mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-06-19 18:00:22 +00:00
fix: use slice for oidc prompt parsing and checking
This commit is contained in:
@@ -168,7 +168,7 @@ func (controller *OIDCController) authorize(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
prompt := controller.oidc.GetPrompt(req.Prompt)
|
||||
prompts := controller.oidc.GetPrompt(req.Prompt)
|
||||
|
||||
userContext, err := new(model.UserContext).NewFromGin(c)
|
||||
|
||||
@@ -178,7 +178,7 @@ func (controller *OIDCController) authorize(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
if (err != nil || !userContext.Authenticated) && prompt == service.OIDCPromptNone {
|
||||
if (err != nil || !userContext.Authenticated) && slices.Contains(prompts, service.OIDCPromptNone) {
|
||||
controller.authorizeError(c, authorizeErrorParams{
|
||||
err: errors.New("user not logged in"),
|
||||
reason: "User not logged in",
|
||||
@@ -197,7 +197,12 @@ func (controller *OIDCController) authorize(c *gin.Context) {
|
||||
OIDCTicket: ticket,
|
||||
OIDCScope: req.Scope,
|
||||
OIDCName: client.Name,
|
||||
OIDCPrompt: prompt,
|
||||
}
|
||||
|
||||
if slices.Contains(prompts, service.OIDCPromptLogin) {
|
||||
values.OIDCPrompt = service.OIDCPromptLogin
|
||||
} else if slices.Contains(prompts, service.OIDCPromptNone) {
|
||||
values.OIDCPrompt = service.OIDCPromptNone
|
||||
}
|
||||
|
||||
queries, err := query.Values(values)
|
||||
|
||||
@@ -947,19 +947,20 @@ func (service *OIDCService) DecodeAuthorizeJWT(tokenString string) (*AuthorizeRe
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Return the first prompt in the list of prompts, or an empty string if no prompt is specified
|
||||
func (service *OIDCService) GetPrompt(prompt string) OIDCPrompt {
|
||||
func (service *OIDCService) GetPrompt(prompt string) []OIDCPrompt {
|
||||
if prompt == "" {
|
||||
return ""
|
||||
return []OIDCPrompt{}
|
||||
}
|
||||
|
||||
prompts := strings.Split(prompt, " ")
|
||||
parsedPromps := make([]OIDCPrompt, 0)
|
||||
prompts := strings.SplitSeq(prompt, " ")
|
||||
|
||||
for _, p := range prompts {
|
||||
if slices.Contains(SupportedPrompts, p) {
|
||||
return OIDCPrompt(p)
|
||||
for p := range prompts {
|
||||
if !slices.Contains(SupportedPrompts, p) {
|
||||
continue
|
||||
}
|
||||
parsedPromps = append(parsedPromps, OIDCPrompt(p))
|
||||
}
|
||||
|
||||
return ""
|
||||
return parsedPromps
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user