Skip to content

Commit 19a2f87

Browse files
committed
feat(oidc): support access token in body for user info post
1 parent 0d286d1 commit 19a2f87

1 file changed

Lines changed: 38 additions & 11 deletions

File tree

internal/controller/oidc_controller.go

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/gin-gonic/gin"
1111
"github.com/google/go-querystring/query"
12+
1213
"github.com/steveiliop56/tinyauth/internal/service"
1314
"github.com/steveiliop56/tinyauth/internal/utils"
1415
"github.com/steveiliop56/tinyauth/internal/utils/tlog"
@@ -376,22 +377,48 @@ func (controller *OIDCController) Userinfo(c *gin.Context) {
376377
return
377378
}
378379

380+
var token string
381+
379382
authorization := c.GetHeader("Authorization")
383+
if authorization != "" {
384+
tokenType, bearerToken, ok := strings.Cut(authorization, " ")
385+
if !ok {
386+
tlog.App.Warn().Msg("OIDC userinfo accessed with malformed authorization header")
387+
c.JSON(401, gin.H{
388+
"error": "invalid_request",
389+
})
390+
return
391+
}
380392

381-
tokenType, token, ok := strings.Cut(authorization, " ")
393+
if strings.ToLower(tokenType) != "bearer" {
394+
tlog.App.Warn().Msg("OIDC userinfo accessed with invalid token type")
395+
c.JSON(401, gin.H{
396+
"error": "invalid_request",
397+
})
398+
return
399+
}
382400

383-
if !ok {
401+
token = bearerToken
402+
} else if c.Request.Method == http.MethodPost {
403+
if c.GetHeader("Content-Type") != "application/x-www-form-urlencoded" {
404+
tlog.App.Warn().Msg("OIDC userinfo POST accessed with invalid content type")
405+
c.JSON(400, gin.H{
406+
"error": "invalid_request",
407+
})
408+
return
409+
}
410+
token = c.PostForm("access_token")
411+
if token == "" {
412+
tlog.App.Warn().Msg("OIDC userinfo POST accessed without access_token in body")
413+
c.JSON(401, gin.H{
414+
"error": "invalid_request",
415+
})
416+
return
417+
}
418+
} else {
384419
tlog.App.Warn().Msg("OIDC userinfo accessed without authorization header")
385420
c.JSON(401, gin.H{
386-
"error": "invalid_grant",
387-
})
388-
return
389-
}
390-
391-
if strings.ToLower(tokenType) != "bearer" {
392-
tlog.App.Warn().Msg("OIDC userinfo accessed with invalid token type")
393-
c.JSON(401, gin.H{
394-
"error": "invalid_grant",
421+
"error": "invalid_request",
395422
})
396423
return
397424
}

0 commit comments

Comments
 (0)