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 {
for i := len(scopes) - 1; i >= 0; i-- {
if scopes[i] == oidc.ScopeProfile ||
scopes[i] == oidc.ScopeEmail ||
scopes[i] == oidc.ScopeAddress ||
scopes[i] == oidc.ScopePhone {
scopes[i] = scopes[len(scopes)-1]
scopes[len(scopes)-1] = ""
scopes = scopes[:len(scopes)-1]
newScopeList := make([]string, 0, len(scopes))
for _, scope := range scopes {
switch scope {
case oidc.ScopeProfile,
oidc.ScopeEmail,
oidc.ScopeAddress,
oidc.ScopePhone:
continue
default:
newScopeList = append(newScopeList, scope)
}
}
return scopes