Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions pkg/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"errors"
"fmt"
"html"
"log"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -176,7 +175,9 @@ func CreateOidcUser(c *gin.Context) {
Timestamp: time.Now().Format(time.RFC3339),
}
c.JSON(http.StatusInternalServerError, er)
log.Print("\033[31mError: OIDC environment variables not configured properly\033[0m")
logger.LogError(
"oidc environment variables not configured properly",
)
return
}

Expand Down Expand Up @@ -213,7 +214,11 @@ func CreateOidcUser(c *gin.Context) {

keyset, err := Jwks.Lookup(context.Background(), os.Getenv("JWKS_URI"))
if err != nil {
log.Print("\033[31mError: Failed jwk.Cache lookup from the oidc provider's URL\033[0m")
logger.LogError(
"failed jwk cache lookup from oidc provider",
zap.Error(err),
)

er := models.LicenseError{
Status: http.StatusInternalServerError,
Message: "Something went wrong",
Expand Down Expand Up @@ -242,7 +247,10 @@ func CreateOidcUser(c *gin.Context) {
}

if keyError {
log.Printf("\033[31mError: Token verification failed due to invalid alg header key field \033[0m")
logger.LogError(
"token verification failed",
zap.String("reason", "invalid alg header key field"),
)
er := models.LicenseError{
Status: http.StatusUnauthorized,
Message: "Please check your credentials and try again",
Expand All @@ -263,12 +271,18 @@ func CreateOidcUser(c *gin.Context) {
Timestamp: time.Now().Format(time.RFC3339),
}
c.JSON(http.StatusUnauthorized, er)
log.Printf("\033[31mError: Token verification failed \033[0m")
logger.LogError(
"token verification failed",
zap.String("stage", "jws_verify"),
)
return
}

parsedToken, err := jwt.Parse([]byte(tokenString), jwt.WithValidate(true), jwt.WithVerify(false))
if err != nil {
logger.LogError(
"token parsing failed",
zap.Error(err),
)
er := models.LicenseError{
Status: http.StatusUnauthorized,
Message: "Please check your credentials and try again",
Expand All @@ -290,7 +304,10 @@ func CreateOidcUser(c *gin.Context) {
Timestamp: time.Now().Format(time.RFC3339),
}
c.JSON(http.StatusUnauthorized, er)
log.Printf("\033[31mError: Issuer '%s' not supported\033[0m", iss)
logger.LogError(
"issuer not supported",
zap.String("issuer", iss),
)
return
}

Expand All @@ -313,7 +330,10 @@ func CreateOidcUser(c *gin.Context) {
Timestamp: time.Now().Format(time.RFC3339),
}
c.JSON(http.StatusUnauthorized, er)
log.Printf("\033[31mError: %s\033[0m", errMessage)
logger.LogError(
"error occurred",
zap.String("message", errMessage),
)
return
}
level := "USER"
Expand Down
Loading