
Series Intro
This series will cover the full implementation of OAuth2.0 Authentication in NestJS for the following types of APIs:
Exp...
For further actions, you may consider blocking this person and/or reporting abuse
Hi, excellent article, it helped me a lot!
I have a question...
Is this flow still recommended or is it better for the backend to just redirect with the code, then the front end in another call to the API with the code asks for the access token so that the token does not travel in the URL?
So this is outdated, and for the upcoming OAuth 2.1 standard you shouldn't use the implicit flow.
I may have to revisit these articles and fix a lot of the recommendations.
In hingsight I should've followed standards more, but I cut some corners since it was purely educational
Thank you very much for the quick response!
Just to confirm, the flow should be:
Personally since the call to google is made by the server, I keep them separate. I normally do something like this in production:
code_verifier
,code_challenge
andstate
, caches thecode_verifier
andstate
in localstorage (web) or secure storage (native);client_id
query parameters instead of the url params, this will allow you to add Dynamic Registration in the future, which is used in the new Model Context Protocol server apps (if AI is something important in your company);state
,code_verifier
andcode_challenge
, make sure to use S256 if you want extra security. Cache both the user state and the server state, with all the usercode_challenge
and the IDPcode_verifier
. I normally use the IDP state as the Key;state
andcode_challenge
call google;state
, and call token endpoint with the servercode_verifier
;code
and thecode_verifier
.Thank you so much again!
Just noticed this morning there was a major bug on the tutorial, just fixed it after one year, sorry for the inconvenience.
I left the state static, but it actually should be cached and new on every request
thanks a ton, this have been super helpful, I've been looking to work on a POC with fastify + external authentication and this has done the job for me.
Also the code quality is super!
much love <3
The way it is set up, if the user does not exists it will just create a new account with the external provider. You could add a third and forth endpoints for registration if you deem that as necessary.
You are hero bro. Thanks a lot