# Needing help with Oauth 2.0 and session based authorisation

**URL:** <https://community.postman.com/t/needing-help-with-oauth-2-0-and-session-based-authorisation/25802>\
**Category:** Help Hub\
**Tags:** authentication\
**Created:** [July 15, 2021, 3:10pm UTC](https://community.postman.com/t/needing-help-with-oauth-2-0-and-session-based-authorisation/25802 "2021-07-15T15:10:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nbsuh](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@nbsuh](https://community.postman.com/u/nbsuh)\
**Post date:** [July 15, 2021, 3:10pm UTC](https://community.postman.com/t/needing-help-with-oauth-2-0-and-session-based-authorisation/25802/1 "2021-07-15T15:10:47Z")

</div>

Hi everyone, I just got started with Postman, and I already managed to make some requests to unprotected endpoints of my app.  
For some endpoints, my app needs to make requests to an external API, in this case, the project management app Asana.

Usually, my auth flow goes like this:

- My app redirects the user to Asana to start the oAuth 2.0 process.
- After authentication, Asana sends the user back to my app to the callback-endpoint, with an authorization code in the URL.
- That callback-endpoint in my backend will be able to retrieve the the authorization code from the request URL.
- The backend will exchange the authorization code for an access code against Asana’s oAuth API.
- On success, the backend will store the access code (and refresh code) in a server session and set a session cookie in the user’s client.
- Having a valid session authorizes the user against my API and the access codes in the session can be used for future requests to my API that involve my backend requesting external data from the Asana API.

Now I would like to replicate this in Postman, authenticating against Asana and receiving the cookie from my backend that authorizes the user both against my API as well as against Asana through the access codes stored in the session associated to the cookie.

I managed to do the standard oAuth 2.0 flow in Postman, which gives me the access token. But I don’t need that token, I need to go through the endpoint on my backend that gives me the cookie.

Which flow do I have to follow and can anyone perhaps suggest me a tutorial that would match the process I have going on here?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [July 16, 2021, 2:15am UTC](https://community.postman.com/t/needing-help-with-oauth-2-0-and-session-based-authorisation/25802/2 "2021-07-16T02:15:16Z")

</div>

Hey @nbsuh 👋 Welcome to the Postman Community 🎉

Checking on [Asana API documentation](https://developers.asana.com/docs/oauth), it says as:

> 1. The application can now use the [Token Exchange Endpoint](https://developers.asana.com/docs/token-exchange-endpoint) to exchange the code, together with the Client Secret, for a Bearer Token (which lasts an hour) and a Refresh Token (which can be used to fetch new Bearer Tokens when the current one expires).
> 2. The application can make requests of the API using this Bearer Token for the next hour.

So I believe that you do need to use Bearer Token to be able to send API request, isn’t it?  
There’s [“Using Postman” page](https://developers.asana.com/docs/using-postman) from which you can import sample collection to your workspace by clicking on “Run in Postman” button, which should help here 😉

Let me know if you have further questions! Happy to help!

---

<div class="post-metadata">

**Author:** ![nbsuh](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@nbsuh](https://community.postman.com/u/nbsuh)\
**Post date:** [July 16, 2021, 6:50am UTC](https://community.postman.com/t/needing-help-with-oauth-2-0-and-session-based-authorisation/25802/3 "2021-07-16T06:50:50Z")

</div>

Hi @taehoshino, thank you for your reply!  
The token exchange with Asana is working fine, it’s all handled by the backend.  
After the user has authenticated against Asana, Asana will redirect the user to my app with said code. The backend then does use that code to get the Bearer/Authentication Token from Asana (as well as the refresh token). But the important part is that those tokens will only be stored server side in a session (in my backend), and of course, that session is associated with a session cookie being sent to the client.  
What I’m struggling with is establishing said session. Usually, after the authentication in Asana, the user would be redirected to my.app/oauth, which is the endpoint which would retrieve the code from the request. But in Postman, the callback URL is [https://oauth.pstmn.io/v1/callback](https://oauth.pstmn.io/v1/callback) in the default oAuth 2.0 Flow. I tried putting my /oauth endpoint there, but then I got errors saying the request uri doesn’t match the one the code was requested with.

The usual flow for a user would be:

**my.app/auth** --(redirection to Asana)–\> **Asana authentication** --(redirection to my app with a code in the url params)–\> **my.app/oauth** --(Backend uses the code from the URL to retrieve bearer token and sets session cookie to client, then it redirects to the home view)–\> **my.app/home**

So I basically need Postman to walk through these steps up to the point where it gets the session cookie. But I’m not sure how to do that. I hope that’s even possible.

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [July 19, 2021, 2:47am UTC](https://community.postman.com/t/needing-help-with-oauth-2-0-and-session-based-authorisation/25802/4 "2021-07-19T02:47:21Z")

</div>

Hey @nbsuh,  
Thanks for sharing the detailed steps. In that case, **Auth Helper should not be used** as it assumes Postman as a client. But in your case, callback URL is your backend endpoint and not Postman.

So what you would need is:

1. Create a request to [authorization endpoint](https://developers.asana.com/docs/user-authorization-endpoint) to receive auth code (you can them save the code as environment variable so that you can use it in the token request)
2. Create another request to [token endpoint](https://developers.asana.com/docs/token-exchange-endpoint) and pass the auth code from the previous request (and specify your backend endpoint as `redirect_url`) and receive token
3. Your backend can handle token and create session etc

I hope this helps! 😉

---

<div class="post-metadata">

**Author:** ![nbsuh](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@nbsuh](https://community.postman.com/u/nbsuh)\
**Post date:** [July 21, 2021, 1:11pm UTC](https://community.postman.com/t/needing-help-with-oauth-2-0-and-session-based-authorisation/25802/5 "2021-07-21T13:11:01Z")

</div>

Hi @taehoshino,  
thanks for your continued effort to help me.  
So I am trying to make request to /auth, which redirects to the authorization endpoint. But before I receive the auth code, I need to authenticate against Asana, which means I would have to log in to Asana. But how do I do this? With the Auth Helper, there was that Popup window where I could enter my login for Asana. But this doesn’t apply when I’m making a normal request. I can look at the response preview and I’m seeing the Asana login for there, but that doesn’t work in the preview/doesn’t allow me to send my login data to Asana.  
I’m still very confused about this…  
I was so happy when I got oAuth to work in my application in general, but I still can’t wrap my head around how I can use it with Postman. I’m not sure if the oAuth implementation in my app is weird or something like that, but as far as I understood, it’s recommended to not give the frontend client the access codes, so I wouldn’t know how else I’d do it.

Thanks again for your support and sorry for being so inept with this 😅

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [July 26, 2021, 1:33am UTC](https://community.postman.com/t/needing-help-with-oauth-2-0-and-session-based-authorisation/25802/6 "2021-07-26T01:33:23Z")

</div>

Sorry for not being clear - for auth request, you would need to _copy and paste into your web browser_ in order for user to be able to log in etc (as Javascript cannot be executed from response body in Postman - the following is an example for PagerDuty)  
 ![Screen Shot 2021-07-26 at 11.27.46 am](https://us1.discourse-cdn.com/getpostman/original/3X/b/0/b06947123344dad878323e160024d1cec61a73e8.png)

This YouTube video walks through the steps to send auth request and get auth code from web browser: [https://www.youtube.com/watch?v=tD9kgb1A6DU](https://www.youtube.com/watch?v=tD9kgb1A6DU)

I hope this helps!

---

<div class="post-metadata">

**Author:** ![hamedABS](https://avatars.discourse-cdn.com/v4/letter/h/82dd89/32.png) [@hamedABS](https://community.postman.com/u/hamedABS)\
**Post date:** [September 18, 2023, 7:34am UTC](https://community.postman.com/t/needing-help-with-oauth-2-0-and-session-based-authorisation/25802/7 "2023-09-18T07:34:14Z")

</div>

Hey man @nbsuh  
hope you doing well  
i’m facing the same problem but not with asan apies, i’ve an apiGateway in my microservice application and i’m applying same flow that you followed with asana  
did you find any solution?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 18, 2023, 8:03am UTC](https://community.postman.com/t/needing-help-with-oauth-2-0-and-session-based-authorisation/25802/8 "2023-09-18T08:03:15Z")

</div>

Hey @hamedABS 👋

Welcome to the Postman community! :postman:

Can I ask that you create a new topic containing all the relevant and contextual information about your issue, please?

This has been open for over 2 years and the platform has changed a lot in that time, sometimes having the “same issue” could be something else instead. 🙏

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 18, 2023, 8:03am UTC](https://community.postman.com/t/needing-help-with-oauth-2-0-and-session-based-authorisation/25802/9 "2023-09-18T08:03:30Z")

</div>

Closed on September 18, 2023, 8:03am UTC


