From 15cde6ac66bc857ac28df545a37c1f4341977595 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Wed, 5 Feb 2025 18:28:21 +0100 Subject: [PATCH] feat: add JSON support in custom claims --- backend/internal/service/oidc_service.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/internal/service/oidc_service.go b/backend/internal/service/oidc_service.go index 0b1de47..db2b02a 100644 --- a/backend/internal/service/oidc_service.go +++ b/backend/internal/service/oidc_service.go @@ -3,6 +3,7 @@ package service import ( "crypto/sha256" "encoding/base64" + "encoding/json" "errors" "fmt" "mime/multipart" @@ -413,7 +414,16 @@ func (s *OidcService) GetUserClaimsForClient(userID string, clientID string) (ma } for _, customClaim := range customClaims { - claims[customClaim.Key] = customClaim.Value + // 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 + } } } if strings.Contains(scope, "email") {