Skip to content

Commit

Permalink
fix(go): reduce token claims to minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelVallenet committed Apr 25, 2023
1 parent 095aa90 commit 39dd386
Showing 1 changed file with 2 additions and 42 deletions.
44 changes: 2 additions & 42 deletions go/pkg/pwsso/token.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pwsso

import (
"fmt"
time "time"

jwt "github.com/dgrijalva/jwt-go"
Expand Down Expand Up @@ -104,45 +103,10 @@ func ClaimsFromToken(token *jwt.Token) *Claims {
ActionToken: &ActionToken{},
}

// keycloak
if v := mc["typ"]; v != nil {
claims.ActionToken.Typ = v.(string)
}
// Subject & Issue at & Expiration
if v := mc["sub"]; v != nil {
claims.ActionToken.Sub = v.(string)
}
if v := mc["azp"]; v != nil {
claims.ActionToken.Azp = v.(string)
}
if v := mc["iss"]; v != nil {
claims.ActionToken.Iss = v.(string)
}
if v := mc["aud"]; v != nil {
switch typed := v.(type) {
case string:
claims.ActionToken.Aud = typed
default:
claims.ActionToken.Aud = fmt.Sprintf("%v", typed)
}
}
if v := mc["asid"]; v != nil {
claims.ActionToken.Asid = v.(string)
}
if v := mc["nonce"]; v != nil {
claims.ActionToken.Nonce = v.(string)
}
if v := mc["session_state"]; v != nil {
claims.ActionToken.SessionState = v.(string)
}
if v := mc["scope"]; v != nil {
claims.ActionToken.Scope = v.(string)
}
if v := mc["jti"]; v != nil {
claims.ActionToken.Jti = v.(string)
}
if v := mc["nbf"]; v != nil {
claims.ActionToken.Nbf = float32(v.(float64))
}
if v := mc["iat"]; v != nil {
t := time.Unix(int64(v.(float64)), 0)
claims.ActionToken.Iat = &t
Expand All @@ -151,10 +115,6 @@ func ClaimsFromToken(token *jwt.Token) *Claims {
t := time.Unix(int64(v.(float64)), 0)
claims.ActionToken.Exp = &t
}
if v := mc["auth_time"]; v != nil {
t := time.Unix(int64(v.(float64)), 0)
claims.ActionToken.AuthTime = &t
}

// pathwar specific
if v := mc["preferred_username"]; v != nil {
Expand All @@ -173,6 +133,6 @@ func ClaimsFromToken(token *jwt.Token) *Claims {
claims.FamilyName = v.(string)
}

// FIXME: add more infos
//FIXME: add more claims
return claims
}

0 comments on commit 39dd386

Please sign in to comment.