82
Views
11
Comments
[JWT] Complex Object as Custom Claim
Question
jwt
Service icon
Forge asset by João Almeida

How do I pass complex JSON objects to the custom claims? Could you share some sample?

2022-02-18 15-32-27
João Almeida
Champion

Laxman Venkatesan wrote:

How do I pass complex JSON objects to the custom claims? Could you share some sample?

 Hi Laxman, you can't. The custom claims need to be in name/value pair format. One workaround could be serializing the complex object into JSON or base64, and add it as a custom claim.

 

UserImage.jpg
Radoslaw Grabowski

Will the component be updated to support nested object in custom claim? Firebase accepts custom claims only as keys/values in 'claims' object claim.

https://firebase.google.com/docs/auth/admin/create-custom-tokens?hl=en#create_custom_tokens_using_a_third-party_jwt_library
2022-02-18 15-32-27
João Almeida
Champion

Radoslaw Grabowski wrote:

Will the component be updated to support nested object in custom claim? Firebase accepts custom claims only as keys/values in 'claims' object claim.

https://firebase.google.com/docs/auth/admin/create-custom-tokens?hl=en#create_custom_tokens_using_a_third-party_jwt_library

Not in the roadmap for now, but if needed the workaround I mentioned above can be used. 

 

UserImage.jpg
Radoslaw Grabowski

João Almeida wrote:

Radoslaw Grabowski wrote:

Will the component be updated to support nested object in custom claim? Firebase accepts custom claims only as keys/values in 'claims' object claim.

https://firebase.google.com/docs/auth/admin/create-custom-tokens?hl=en#create_custom_tokens_using_a_third-party_jwt_library

Not in the roadmap for now, but if needed the workaround I mentioned above can be used. 

 

I tried. How is it supposed to work if firebase requires nested object in the 'claims' claim and not the JSON string I can provide? I don't think it could work with some form of trying to escape the string but maybe I could have missed something.

I tried to provide custom claim without nesting in 'claims' claim but Firebase just ignores it. 

I tried to provide JSON with my custom claims(as you suggested to do) as the value for 'claims' claim but then Firebase rejects the request.

 

2022-02-18 15-32-27
João Almeida
Champion

Radoslaw Grabowski wrote:

João Almeida wrote:

Radoslaw Grabowski wrote:

Will the component be updated to support nested object in custom claim? Firebase accepts custom claims only as keys/values in 'claims' object claim.

https://firebase.google.com/docs/auth/admin/create-custom-tokens?hl=en#create_custom_tokens_using_a_third-party_jwt_library

Not in the roadmap for now, but if needed the workaround I mentioned above can be used. 

 

I tried. How is it supposed to work if firebase requires nested object in the 'claims' claim and not the JSON string I can provide? I don't think it could work with some form of trying to escape the string but maybe I could have missed something.

I tried to provide custom claim without nesting in 'claims' claim but Firebase just ignores it. 

I tried to provide JSON with my custom claims(as you suggested to do) as the value for 'claims' claim but then Firebase rejects the request.

 

In that case I'm afraid there's no workaround, right now the component only supports the claims as a list of name value pairs.

 

 

UserImage.jpg
Laxman Venkatesan

Hi,

I have created a component which can be used to generate JWT from a complex object types instead of key value pair. Hope this helps!

ComplexJWT

2022-03-03 22-15-30
Borislav Shumarov PhD
Champion

I could not get your solution to work

2022-03-03 22-15-30
Borislav Shumarov PhD
Champion

I modified the JWT component to be able to perform this. I am still waiting for approval to the merge request, until then, you can ping me for the modified version of JWT component ;)

2022-02-18 15-32-27
João Almeida
Champion

Hi all. Regarding Laxman Venkatesan's problem, the best and fastest might be to work with Borislav Shumarov for his modified version. This is because we weren't any new features for version 4.0 (the last release was just and update of external libraries), the custom claims would go along with major features for 5.0, but that won't likely happen in the very near future.

 

UserImage.jpg
Chanyut Luesiripanit

Could you please to sharing the workaround solution, I have same issue. Thank you.

2022-03-03 22-15-30
Borislav Shumarov PhD
Champion

Hi Chanyut,

I have uploaded a Fork of the project on the Forge:

https://www.outsystems.com/forge/component-overview/16132/jwt-advanced

Let me know, if you have any problems

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.