mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-06-20 18:30:14 +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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt := controller.oidc.GetPrompt(req.Prompt)
|
prompts := controller.oidc.GetPrompt(req.Prompt)
|
||||||
|
|
||||||
userContext, err := new(model.UserContext).NewFromGin(c)
|
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{
|
controller.authorizeError(c, authorizeErrorParams{
|
||||||
err: errors.New("user not logged in"),
|
err: errors.New("user not logged in"),
|
||||||
reason: "User not logged in",
|
reason: "User not logged in",
|
||||||
@@ -197,7 +197,12 @@ func (controller *OIDCController) authorize(c *gin.Context) {
|
|||||||
OIDCTicket: ticket,
|
OIDCTicket: ticket,
|
||||||
OIDCScope: req.Scope,
|
OIDCScope: req.Scope,
|
||||||
OIDCName: client.Name,
|
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)
|
queries, err := query.Values(values)
|
||||||
|
|||||||
@@ -947,19 +947,20 @@ func (service *OIDCService) DecodeAuthorizeJWT(tokenString string) (*AuthorizeRe
|
|||||||
}, nil
|
}, 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 == "" {
|
if prompt == "" {
|
||||||
return ""
|
return []OIDCPrompt{}
|
||||||
}
|
}
|
||||||
|
|
||||||
prompts := strings.Split(prompt, " ")
|
parsedPromps := make([]OIDCPrompt, 0)
|
||||||
|
prompts := strings.SplitSeq(prompt, " ")
|
||||||
|
|
||||||
for _, p := range prompts {
|
for p := range prompts {
|
||||||
if slices.Contains(SupportedPrompts, p) {
|
if !slices.Contains(SupportedPrompts, p) {
|
||||||
return OIDCPrompt(p)
|
continue
|
||||||
}
|
}
|
||||||
|
parsedPromps = append(parsedPromps, OIDCPrompt(p))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return parsedPromps
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user