Technology

TGIMBA .NET Core – Pre-API work – JWT Embedded Object

To continue my previous post, I was able to place a custom data point inside a claim and retrieve it in the controller.  This is good enough, but it bugged me that I didn’t know how to place a data point in the JSON (JavaScript Object Notation) Web Token (JWT) itself.

At a previous job, this is what we had done.  We placed a customer id inside the token and retrieved it when it was decrypted during authentication (difference was this was a Node JS Type Script API).  But, after poking around a little more, I found my answer in a payload option (reference #4).  More specifically, you can place an object in the payload of the JWT token at creation and retrieve it in the controller.

The steps are:

  • Call the authentication code that generates the JWT token.

p4

  • On your authentication code (TokenController.cs here), add an object to the payload.

p1

  • Inside your controller (ValuesController.cs here), consume the object

p2

I believe I have found the solution I will be using for the TGIMBA API 🙂

Stay tuned!

References

  1. https://stackoverflow.com/questions/39819299/get-json-web-token-payload-data-within-controller-action
  2. https://blog.zaven.co/user-authentication-asp-net-web-api-2-rsa-jwt-tokens-part-3/
  3. https://www.codeproject.com/Tips/1208535/Create-And-Consume-JWT-Tokens-in-csharp
  4. https://stackoverflow.com/questions/41450141/system-identitymodel-tokens-jwtsecuritytoken-custom-properties

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s