Skip to content

Commit

Permalink
fix: wrong usement in getUsername
Browse files Browse the repository at this point in the history
Signed-off-by: Kininaru <[email protected]>
  • Loading branch information
keainye committed Jun 6, 2021
1 parent 741d1fe commit b65ae4e
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions routers/authz_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,25 @@ type Object struct {
Name string `json:"name"`
}

func getUsernameByClientIdSecret(ctx *context.Context) string {
requestUri := ctx.Request.RequestURI
clientId := parseQuery(requestUri, "clientId")
clientSecret := parseQuery(requestUri, "clientSecret")
if len(clientId) == 0 || len(clientSecret) == 0 {
return ""
}

app := object.GetApplicationByClientId(clientId)
if app == nil || app.ClientSecret != clientSecret {
return ""
}
return "built-in/service"
}

func getUsername(ctx *context.Context) (username string) {
defer func() {
if r := recover(); r != nil {
username = ""
username = getUsernameByClientIdSecret(ctx)
}
}()

Expand All @@ -44,18 +59,7 @@ func getUsername(ctx *context.Context) (username string) {
username = ctx.Input.Session("username").(string)

if len(username) == 0 {
query := ctx.Request.URL.RawQuery
clientId := parseQuery(query, "clientId")
clientSecret := parseQuery(query, "clientSecret")
if len(clientId) == 0 || len(clientSecret) == 0 {
return
}

app := object.GetApplicationByClientId(clientId)
if app == nil || app.ClientSecret != clientSecret {
return
}
return "built-in/service"
username = getUsernameByClientIdSecret(ctx)
}

return
Expand Down

0 comments on commit b65ae4e

Please sign in to comment.