Skip to content

Commit 80bb4f1

Browse files
committed
feat: support for prompt=none
1 parent dbc9b1e commit 80bb4f1

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

internal/controller/oidc_controller.go

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,26 @@ func (controller *OIDCController) authorize(c *gin.Context) {
168168
return
169169
}
170170

171+
userContext, err := new(model.UserContext).NewFromGin(c)
172+
173+
if err != nil {
174+
if !errors.Is(err, model.ErrUserContextNotFound) {
175+
controller.log.App.Warn().Err(err).Msg("Failed to get user context")
176+
}
177+
}
178+
179+
if (err != nil || !userContext.Authenticated) && req.Prompt == "none" {
180+
controller.authorizeError(c, authorizeErrorParams{
181+
err: errors.New("user not logged in"),
182+
reason: "User not logged in",
183+
reasonPublic: "The user is not logged in",
184+
callback: req.RedirectURI,
185+
callbackError: "login_required",
186+
state: req.State,
187+
})
188+
return
189+
}
190+
171191
ticket := controller.oidc.CreateAuthorizeRequestTicket(*req)
172192

173193
values := AuthorizeScreenParams{
@@ -185,9 +205,12 @@ func (controller *OIDCController) authorize(c *gin.Context) {
185205

186206
if err != nil {
187207
controller.authorizeError(c, authorizeErrorParams{
188-
err: err,
189-
reason: "Failed to compile authorize queries",
190-
reasonPublic: "An internal error occured while processing your request",
208+
err: err,
209+
reason: "Failed to compile authorize queries",
210+
reasonPublic: "An internal error occured while processing your request",
211+
callback: req.RedirectURI,
212+
callbackError: "server_error",
213+
state: req.State,
191214
})
192215
return
193216
}
@@ -215,16 +238,12 @@ func (controller *OIDCController) authorizeComplete(c *gin.Context) {
215238
userContext, err := new(model.UserContext).NewFromGin(c)
216239

217240
if err != nil {
218-
controller.authorizeError(c, authorizeErrorParams{
219-
err: err,
220-
reason: "Failed to get user context",
221-
reasonPublic: "User is not logged in or the session is invalid",
222-
json: true,
223-
})
224-
return
241+
if !errors.Is(err, model.ErrUserContextNotFound) {
242+
controller.log.App.Warn().Err(err).Msg("Failed to get user context")
243+
}
225244
}
226245

227-
if !userContext.Authenticated {
246+
if err != nil || !userContext.Authenticated {
228247
controller.authorizeError(c, authorizeErrorParams{
229248
err: errors.New("err user not logged in"),
230249
reason: "User not logged in",

0 commit comments

Comments
 (0)