# NodeJS - Execute an authorization grant

**URL:** <https://community.auth0.com/t/nodejs-execute-an-authorization-grant/11978>\
**Category:** Get Help\
**Tags:** nodejs\
**Created:** [May 30, 2018, 7:40pm UTC](https://community.auth0.com/t/nodejs-execute-an-authorization-grant/11978 "2018-05-30T19:40:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![to.charlie.nash](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@to.charlie.nash](https://community.auth0.com/u/to.charlie.nash)\
**Post date:** [May 30, 2018, 7:40pm UTC](https://community.auth0.com/t/nodejs-execute-an-authorization-grant/11978/1 "2018-05-30T19:40:41Z")

</div>

Question:  
I the doc, section titled “Execute an authorization grant flow”, the first step is to get the User’s Authorization.  
The doc, states “To begin an Authorization Code flow, your web application should first send the user to the authorization URL: etc”.  
My appologies if this question is a basic nodejs development related one, but how do you do that in nodejs? Are we talking to make a http POST request to the URL?

Thanks!  
Charlie

---

<div class="post-metadata">

**Author:** ![luis.rudge](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/luis.rudge/32/7073_2.png) [@luis.rudge](https://community.auth0.com/u/luis.rudge)\
**Post date:** [May 30, 2018, 8:07pm UTC](https://community.auth0.com/t/nodejs-execute-an-authorization-grant/11978/2 "2018-05-30T20:07:32Z")

</div>

DId you try our nodejs quick starts? [Auth0 Express SDK Quickstarts: Login](https://auth0.com/docs/quickstart/webapp/nodejs/01-login)

---

<div class="post-metadata">

**Author:** ![to.charlie.nash](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@to.charlie.nash](https://community.auth0.com/u/to.charlie.nash)\
**Post date:** [May 30, 2018, 8:40pm UTC](https://community.auth0.com/t/nodejs-execute-an-authorization-grant/11978/3 "2018-05-30T20:40:20Z")

</div>

Yes, I reviewed and tested the code you referenced. But this code doesn’t execute an authorization grant flow, as per my initial question.  
C-

---

<div class="post-metadata">

**Author:** ![sgmeyer](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgmeyer/32/3387_2.png) [@sgmeyer](https://community.auth0.com/u/sgmeyer)\
**Post date:** [May 30, 2018, 8:55pm UTC](https://community.auth0.com/t/nodejs-execute-an-authorization-grant/11978/4 "2018-05-30T20:55:17Z")

</div>

This quick start uses express + passport.js to initiate this flow. That code is well encapsulated. This is the exact line that does this with middleware:

> <https://github.com/auth0-samples/auth0-nodejs-webapp-sample/blob/master/01-Login/routes/index.js#L17-L23>

This is how it works. When the server is spun up it configures passport.js with the passport-auth0 strategy. When calling the login endpoint it checks the session for a valid/authenticated user. If one doesn’t exist that endpoint will redirect the user to the /authorize endpoint to trigger Authorization Code Flow.

Then after the user successfully logs in Auth0 will redirect the user back to here:

> <https://github.com/auth0-samples/auth0-nodejs-webapp-sample/blob/master/01-Login/routes/index.js#L33-L40>

This also uses passport.js middle ware to do the code exchange. It is actually using the auth0 strategy as well to do the state validation and code exchange. You can see how passport and the auth0 strategy are configured here:

> <https://github.com/auth0-samples/auth0-nodejs-webapp-sample/blob/master/01-Login/app.js#L19-L44>

---

<div class="post-metadata">

**Author:** ![luis.rudge](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/luis.rudge/32/7073_2.png) [@luis.rudge](https://community.auth0.com/u/luis.rudge)\
**Post date:** [May 30, 2018, 8:56pm UTC](https://community.auth0.com/t/nodejs-execute-an-authorization-grant/11978/5 "2018-05-30T20:56:32Z")

</div>

> [@to.charlie.nash](#):
>
> To begin an Authorization Code flow, your web application should first sen

Yes, it does.  
[This part](https://auth0.com/docs/api-auth/tutorials/authorization-code-grant#1-get-the-user-s-authorization), actually says that you should redirect your user to the /authorization endpoint, which is what our quick start does [here](https://auth0.com/docs/quickstart/webapp/nodejs/01-login#trigger-authentication).

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 25, 2019, 1:38pm UTC](https://community.auth0.com/t/nodejs-execute-an-authorization-grant/11978/6 "2019-07-25T13:38:04Z")

</div>


