mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-10-20 08:39:04 +02:00
fix: /authorize endpoint crashes when list of scopes is empty (#1575)
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"maps"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -451,15 +452,18 @@ func (r interactionRequirements) any() bool {
|
||||
|
||||
func (s *authorizationService) createInteractionSession(ctx context.Context, requester fosite.AuthorizeRequester, requestParams map[string]string, userID string, requirements interactionRequirements) (InteractionSession, error) {
|
||||
parameters := make(map[string]string, len(requestParams))
|
||||
for key, value := range requestParams {
|
||||
parameters[key] = value
|
||||
maps.Copy(parameters, requestParams)
|
||||
|
||||
scopes := requester.GetRequestedScopes()
|
||||
if scopes == nil {
|
||||
scopes = []string{}
|
||||
}
|
||||
|
||||
return s.interactionSessionService.create(ctx, InteractionSession{
|
||||
Base: model.Base{
|
||||
ID: requester.GetID(),
|
||||
},
|
||||
Scopes: datatype.StringList(requester.GetRequestedScopes()),
|
||||
Scopes: datatype.StringList(scopes),
|
||||
ClientID: requester.GetClient().GetID(),
|
||||
UserID: utils.PtrOrNil(userID),
|
||||
ConsentRequired: requirements.ConsentRequired,
|
||||
|
||||
@@ -187,8 +187,13 @@ func (s *deviceService) getDeviceCodeInfo(ctx context.Context, userCode, userID
|
||||
authorizationRequired = consentRequired(hasAuthorizedClient, client.SkipConsent, nil)
|
||||
}
|
||||
|
||||
scope := request.GetRequestedScopes()
|
||||
if scope == nil {
|
||||
scope = []string{}
|
||||
}
|
||||
|
||||
// Resolve friendly names for the requested custom-API permissions so the device consent screen matches the browser flow
|
||||
scopeInfo, err := s.authorizationService.resolveScopeInfoForRequest(ctx, resource, request.GetRequestedScopes())
|
||||
scopeInfo, err := s.authorizationService.resolveScopeInfoForRequest(ctx, resource, scope)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -206,7 +211,7 @@ func (s *deviceService) getDeviceCodeInfo(ctx context.Context, userCode, userID
|
||||
LaunchURL: client.LaunchURL,
|
||||
RequiresReauthentication: client.RequiresReauthentication,
|
||||
},
|
||||
Scope: request.GetRequestedScopes(),
|
||||
Scope: scope,
|
||||
ScopeInfo: scopeInfo,
|
||||
AuthorizationRequired: authorizationRequired,
|
||||
ReauthenticationRequired: client.RequiresReauthentication,
|
||||
|
||||
@@ -43,9 +43,17 @@ func newInteractionSessionForUser(interactionSession InteractionSession) (intera
|
||||
currentStep = requiredSteps[0]
|
||||
}
|
||||
|
||||
scopes := interactionSession.Scopes
|
||||
if scopes == nil {
|
||||
scopes = []string{}
|
||||
}
|
||||
if requiredSteps == nil {
|
||||
requiredSteps = []interactionStep{}
|
||||
}
|
||||
|
||||
return interactionSessionForUser{
|
||||
ID: interactionSession.ID,
|
||||
Scopes: interactionSession.Scopes,
|
||||
Scopes: scopes,
|
||||
Client: client,
|
||||
CurrentStep: currentStep,
|
||||
RequiredSteps: requiredSteps,
|
||||
|
||||
Reference in New Issue
Block a user