Hello,
I am exposing a REST API and would like to create authentication logic with JWT. I installed this Forge component but there are a few things I don't understand regarding the use of Asymmetric Signature with JSON Web Key. Some of my doubts are:
Thanks in advance!
In short:
a) keep pub/priv keys unique per environment. Private key should be kept very secret and public one exposed via JWKS. Change ~once a year or if compromised.
b) session stuff doesn't work on Outsystems API endpoints, no session vars. If you need to bound it with UI sessions, then you need to create custom authorization on API endpoint, but you have to rely on JWT tokens, thus include UserID, TenantID in JWT cliams and then in custom auth extract them and do TenantSwitch -> UserLogin, to have user context in API stuff. Of course always check if JWT token is valid. Btw you can store JWT in session cookie too.
I have the same doubts.
Thanks for your feedback Ivan!
Could you clarify what "exposed via JWKS" means? Is it something that goes in the payload of the token?
https://auth0.com/docs/tokens/json-web-tokens/json-web-key-sets
Basically @Ivan Nudzik wrapped it up pretty well, but just want to add something. Are you exposing or consuming an API with JWT? Because you start by saying you're exposing the service, but is questions are related with consuming one.
Thanks for your feedback João.
Actually I am both exposing and consuming the API, since I am trying to understand how the authentication flow works. It's the first time I implement this king of logic. Right now I have:
So let me see if I got it right.
That's not it. Trying to understand generating and validating token at the same time may be a bit too much at the same time, I'd advise to take a look at consuming a REST service with JWT by looking at an existing service first.
Modules shouldn't expose private keys in endpoints at all! Public keys may be exposed publicly, to easily share them, but the flow doesn't them to be exposed. In theory when it begins the corresponding key should already be configured in the producer and consumer.
The short version of the flow goes like this:
Another question: are you implementing exposing and consuming because those are parts of the same implementation? If so, consider using symmetric signature instead, which is much more suited in scenarios where there's a higher trust between the producer and consumer.
You are right, it's a bit confusing doing both at the same time!
It's getting clearer for me now with your explanation of the flow. I am going to seach for some free API on the web to consume and get a better grip of all this concepts.
Concerning your question: Yes those are parts of an implementation based on services. I am going to consider using the symmetric key. I was testing the asymetric key just to understand it.
I may be replying to the Older post,
But I have tried symmetric approach as João Almeida's suggestion,
It is working like a charm. Thank you.