mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 05:10:19 +08:00
feat: fix bug for access key and secret login (#3022)
* fix: get username for keys * chore: move user nil check
This commit is contained in:
@ -35,20 +35,13 @@ type Object struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getUsername(ctx *context.Context) (username string) {
|
func getUsername(ctx *context.Context) (username string) {
|
||||||
defer func() {
|
username, ok := ctx.Input.Session("username").(string)
|
||||||
if r := recover(); r != nil {
|
if !ok || username == "" {
|
||||||
username, _ = getUsernameByClientIdSecret(ctx)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
username = ctx.Input.Session("username").(string)
|
|
||||||
|
|
||||||
if username == "" {
|
|
||||||
username, _ = getUsernameByClientIdSecret(ctx)
|
username, _ = getUsernameByClientIdSecret(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
if username == "" {
|
if username == "" {
|
||||||
username = getUsernameByKeys(ctx)
|
username, _ = getUsernameByKeys(ctx)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -91,17 +91,22 @@ func getUsernameByClientIdSecret(ctx *context.Context) (string, error) {
|
|||||||
return fmt.Sprintf("app/%s", application.Name), nil
|
return fmt.Sprintf("app/%s", application.Name), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUsernameByKeys(ctx *context.Context) string {
|
func getUsernameByKeys(ctx *context.Context) (string, error) {
|
||||||
accessKey, accessSecret := getKeys(ctx)
|
accessKey, accessSecret := getKeys(ctx)
|
||||||
user, err := object.GetUserByAccessKey(accessKey)
|
user, err := object.GetUserByAccessKey(accessKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if user != nil && accessSecret == user.AccessSecret {
|
if user == nil {
|
||||||
return user.GetId()
|
return "", fmt.Errorf("user not found for access key: %s", accessKey)
|
||||||
}
|
}
|
||||||
return ""
|
|
||||||
|
if accessSecret != user.AccessSecret {
|
||||||
|
return "", fmt.Errorf("incorrect access secret for user: %s", user.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
return user.GetId(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSessionUser(ctx *context.Context) string {
|
func getSessionUser(ctx *context.Context) string {
|
||||||
|
Reference in New Issue
Block a user