Skip to content

Commit efe3730

Browse files
authored
feat: support for oidc max age (#949)
1 parent 7f18b45 commit efe3730

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

internal/controller/oidc_controller.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"fmt"
77
"net/http"
88
"slices"
9+
"strconv"
910
"strings"
11+
"time"
1012

1113
"github.com/gin-gonic/gin"
1214
"github.com/gin-gonic/gin/binding"
@@ -217,6 +219,28 @@ func (controller *OIDCController) authorize(c *gin.Context) {
217219
values.OIDCPrompt = service.OIDCPromptNone
218220
}
219221

222+
if req.MaxAge != "" && userContext != nil {
223+
maxAge, err := strconv.Atoi(req.MaxAge)
224+
if err != nil {
225+
controller.authorizeError(c, authorizeErrorParams{
226+
err: err,
227+
reason: "Invalid max_age",
228+
reasonPublic: "The max_age parameter is invalid",
229+
callback: req.RedirectURI,
230+
callbackError: "invalid_request",
231+
state: req.State,
232+
})
233+
return
234+
}
235+
236+
if userContext.Authenticated {
237+
authTime := time.Unix(userContext.AuthTime, 0)
238+
if authTime.Add(time.Duration(maxAge) * time.Second).Before(time.Now()) {
239+
values.OIDCPrompt = service.OIDCPromptLogin
240+
}
241+
}
242+
}
243+
220244
queries, err := query.Values(values)
221245

222246
if err != nil {

internal/service/oidc_service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ type AuthorizeRequest struct {
128128
CodeChallenge string `form:"code_challenge" json:"code_challenge" url:"code_challenge"`
129129
CodeChallengeMethod string `form:"code_challenge_method" json:"code_challenge_method" url:"code_challenge_method"`
130130
Prompt string `form:"prompt" json:"prompt" url:"prompt"`
131+
MaxAge string `form:"max_age" json:"max_age" url:"max_age"`
131132
}
132133

133134
type AuthorizeCodeEntry struct {

0 commit comments

Comments
 (0)