Skip to content

Commit

Permalink
Add new fields in the claim
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmendelope committed Nov 30, 2023
1 parent 2bc9a15 commit 0b2cea6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 1 addition & 3 deletions pkg/interceptors/jwt_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ func GetClaimFromContext(ctx context.Context) (*njwt.ExtendedAuthxClaim, error)
var userAccounts []njwt.UserAccountClaim
accounts, exists := md[helper.AccountsKey]
if exists {
// TODO: review error
userAccounts, _ = njwt.StringToAccounts(accounts[0])

userAccounts = njwt.StringToAccounts(accounts[0])
}

return &njwt.ExtendedAuthxClaim{
Expand Down
6 changes: 2 additions & 4 deletions pkg/njwt/claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,19 @@ func (ac *AuthxClaim) AccountsToString() (string, error) {
return accountStr, nil
}

func StringToAccounts(str string) ([]UserAccountClaim, error) {
func StringToAccounts(str string) []UserAccountClaim {
var accounts []UserAccountClaim
err := json.Unmarshal([]byte(str), &accounts)
if err != nil {
// TODO: return an error
log.Error().Err(err).Msg("error converting string to authx claim")
}
return accounts, err
return accounts
}

// ToMap transforms the claim into a key-value map.
func (ac *AuthxClaim) ToMap() map[string]string {
accounts, err := ac.AccountsToString()
if err != nil {
// TODO: return an error
log.Error().Err(err).Msg("error converting authx claim to a map")
}
return map[string]string{
Expand Down

0 comments on commit 0b2cea6

Please sign in to comment.