JWT authentication with microservices case #2506
Replies: 4 comments 13 replies
-
I have shared a few times why there are no JWT is AdonisJS #2166 (comment) and #1365 (reply in thread) Regarding the micro services use cases. I am not sure about your architecture and neither the right person to suggest an architecture for it. However, this is how I have done it using the opaque tokens for a client.
Infact, specs like Open ID connect also suggest JWT's for Id tokens. Finally, if you want to stick your existing approach. You can generate JWT tokens like you would do in any other Node.js app not using AdonisJS |
Beta Was this translation helpful? Give feedback.
-
I needed to use JWT in a project and so I ended up implementing a JWTGuard for Adonis. I made it completely based on OATGuard so that it was completely integrated with the Adonis proposal, including being able to choose Database or Redis as TokenProvider. I did this implementation yesterday and maybe it still needs more testing, I will share it with you anyway. Install jwt package.
Edit your ".env"
You can generate new keys like this:
Edit your "providers/AppProvider.ts"
Edit your "contracts/auth.ts"
Edit your "config/auth.ts"
Create your "providers/JWTGuard/index.ts"
It's a lot of code to read/understand, but what really matters is the methods: "JWTGuard.authenticate" and "JWTGuard.login" Good luck! |
Beta Was this translation helpful? Give feedback.
-
@alex-oliveira I need your help, I couldn't implement your example. Typescript has errors: Cannot find name 'AuthManager' and Event is not assignable to parameter of type 'EmitterContract'.
|
Beta Was this translation helpful? Give feedback.
-
Here's a package to add JWT auth to adonis v5: https://github.com/maxgalbu/adonis5-jwt Let me know if it works for you! |
Beta Was this translation helpful? Give feedback.
-
I am implementing an app with microservices and some services rely on adonis.js v5 so JWT is important in that case to avoid duplicating authentication data across the services to keep the services self-dependent or avoid making every service rely on the authentication service. any advice? @thetutlage
Beta Was this translation helpful? Give feedback.
All reactions