fix: removeUserinfoScopes return new slice (without manipulating passed one) (#110)

This commit is contained in:
Livio Amstutz 2021-07-21 08:27:38 +02:00 committed by GitHub
parent 8a35b89815
commit 1132c9d93d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -155,15 +155,16 @@ func CreateIDToken(ctx context.Context, issuer string, request IDTokenRequest, v
} }
func removeUserinfoScopes(scopes []string) []string { func removeUserinfoScopes(scopes []string) []string {
for i := len(scopes) - 1; i >= 0; i-- { newScopeList := make([]string, 0, len(scopes))
if scopes[i] == oidc.ScopeProfile || for _, scope := range scopes {
scopes[i] == oidc.ScopeEmail || switch scope {
scopes[i] == oidc.ScopeAddress || case oidc.ScopeProfile,
scopes[i] == oidc.ScopePhone { oidc.ScopeEmail,
oidc.ScopeAddress,
scopes[i] = scopes[len(scopes)-1] oidc.ScopePhone:
scopes[len(scopes)-1] = "" continue
scopes = scopes[:len(scopes)-1] default:
newScopeList = append(newScopeList, scope)
} }
} }
return scopes return scopes