Skip to content

Commit

Permalink
fix: update commit to fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajayn84 authored Sep 25, 2024
1 parent 070518c commit 64b6083
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions persistence/sql/persister_oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,23 @@ func (r *OAuth2RequestSQL) toRequest(ctx context.Context, session fosite.Session
return nil, errorsx.WithStack(err)
}

scopes, err := unescapeDelimiter(r.Scopes)
if err != nil {
return nil, errorsx.WithStack(err)
}

grantedScopes, err := unescapeDelimiter(r.GrantedScope)
if err != nil {
return nil, errorsx.WithStack(err)
}

return &fosite.Request{
ID: r.Request,
RequestedAt: r.RequestedAt,
// ExpiresAt does not need to be populated as we get the expiry time from the session.
Client: c,
RequestedScope: unescapeDelimiter(r.Scopes),
GrantedScope: unescapeDelimiter(r.GrantedScope),
RequestedScope: scopes,
GrantedScope: grantedScopes,
RequestedAudience: stringsx.Splitx(r.RequestedAudience, "|"),
GrantedAudience: stringsx.Splitx(r.GrantedAudience, "|"),
Form: val,
Expand Down Expand Up @@ -562,16 +572,16 @@ func escapeDelimiter(scopes []string) []string {
return escapedScopes
}

func unescapeDelimiter(scopes string) []string {
func unescapeDelimiter(scopes string) ([]string, error) {
updatedScopes := stringsx.Splitx(scopes, "|")
if strings.Contains(scopes, "%26") {
for i, scope := range updatedScopes {
unescapedScope, err := url.QueryUnescape(scope)
if err != nil {
errors.Errorf("Error while url unescaping scope: %s", scope)
return nil, errors.Errorf("Error while url unescaping scope: %s", scope)
}
updatedScopes[i] = unescapedScope
}
}
return updatedScopes
return updatedScopes, nil
}

0 comments on commit 64b6083

Please sign in to comment.