|
9 | 9 |
|
10 | 10 | "github.com/gin-gonic/gin" |
11 | 11 | "github.com/google/go-querystring/query" |
| 12 | + |
12 | 13 | "github.com/steveiliop56/tinyauth/internal/service" |
13 | 14 | "github.com/steveiliop56/tinyauth/internal/utils" |
14 | 15 | "github.com/steveiliop56/tinyauth/internal/utils/tlog" |
@@ -376,22 +377,48 @@ func (controller *OIDCController) Userinfo(c *gin.Context) { |
376 | 377 | return |
377 | 378 | } |
378 | 379 |
|
| 380 | + var token string |
| 381 | + |
379 | 382 | 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 | + } |
380 | 392 |
|
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 | + } |
382 | 400 |
|
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 { |
384 | 419 | tlog.App.Warn().Msg("OIDC userinfo accessed without authorization header") |
385 | 420 | 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", |
395 | 422 | }) |
396 | 423 | return |
397 | 424 | } |
|
0 commit comments