mirror of
https://github.com/nikdoof/pocket-id.git
synced 2025-12-14 15:22:18 +00:00
feat: add JSON support in custom claims
This commit is contained in:
@@ -3,6 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
@@ -413,9 +414,18 @@ func (s *OidcService) GetUserClaimsForClient(userID string, clientID string) (ma
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, customClaim := range customClaims {
|
for _, customClaim := range customClaims {
|
||||||
|
// The value of the custom claim can be a JSON object or a string
|
||||||
|
var jsonValue interface{}
|
||||||
|
json.Unmarshal([]byte(customClaim.Value), &jsonValue)
|
||||||
|
if jsonValue != nil {
|
||||||
|
// It's JSON so we store it as an object
|
||||||
|
claims[customClaim.Key] = jsonValue
|
||||||
|
} else {
|
||||||
|
// Marshalling failed, so we store it as a string
|
||||||
claims[customClaim.Key] = customClaim.Value
|
claims[customClaim.Key] = customClaim.Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if strings.Contains(scope, "email") {
|
if strings.Contains(scope, "email") {
|
||||||
claims["email"] = user.Email
|
claims["email"] = user.Email
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user