# How to do user login and get refresh token to invoke gmail apis?

**URL:** <https://community.auth0.com/t/how-to-do-user-login-and-get-refresh-token-to-invoke-gmail-apis/120076>\
**Category:** Get Help\
**Tags:** reusable-refresh-tokens, sessions\
**Created:** [November 2, 2023, 1:12pm UTC](https://community.auth0.com/t/how-to-do-user-login-and-get-refresh-token-to-invoke-gmail-apis/120076 "2023-11-02T13:12:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dean2](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dean2/32/35668_2.png) [@dean2](https://community.auth0.com/u/dean2)\
**Post date:** [November 2, 2023, 1:12pm UTC](https://community.auth0.com/t/how-to-do-user-login-and-get-refresh-token-to-invoke-gmail-apis/120076/1 "2023-11-02T13:12:22Z")

</div>

EDIT to newest flow that still doesn’t work. LAST EDIT → I gave up and went to google oauth and was done in way less time than auth0 so going with straight app → google or app-\>3rd party going forward instead for speed. There is just no responses and no docs on the flow for refresh token.

This has become so complicated, I keep thinking of ditching auth0 ☹ and just using google straight up to prevent the man in the middle confusion.

I read through this post [Having trouble enabling Allow Offline Access](https://community.auth0.com/t/having-trouble-enabling-allow-offline-access/30803) however I still need a refresh token I believe for gmail apis. I was trying to get it through the mgmt api but that only gave me an access token that I could use for 1 hour and then my app stops working.

I had login working doing this but now I have no refresh token so that I can call gmail apis on the user’s behalf once per week (ie. offline)

- redirect to auth0 /authorize

- auth0 redirects back to my /callback

- I decode the jwt and have aud, sid, etc and see the AUTH0 refresh token

- I then call /oauth/token with scopes “openid profile email phone offline\_access” and grant type ‘authorization\_code’ . This seems to give me a valid refresh token

- I then call /api/v2/users/{id} and this gives me google access token but no refresh token still ☹

Where in the flow am I going wrong here so I can get a refresh token for the user so I can fiddle with the stuff he wants once per week in gmail?

This document fetches the management api refresh token NOT the google refresh token (that was not clear but I get it now) → [Get Refresh Tokens](https://auth0.com/docs/secure/tokens/refresh-tokens/get-refresh-tokens)

I read another doc that shows getting google’s access token BUT it does not show how to get the refresh token → [Call an Identity Provider API](https://auth0.com/docs/authenticate/identity-providers/calling-an-external-idp-api?_gl=1*t3ic1v*_gcl_aw*R0NMLjE2OTMxNDQyMjguQ2owS0NRanc2S3VuQmhEeEFSSXNBS0ZVR3M4M1JPWmxOalFhUTczNXJfeXBiUkFIMUdXVU1jdEN4d2hQSnVjUlcwRTBfeWRRUWNDLTc4Z2FBa3NlRUFMd193Y0I.*_gcl_au*ODcxNTY5NDY4LjE2OTMwNDU0MjU.#step-3-extract-the-idp-access-token)

In the end I also tried to see if calling /api/v2/users/{id} would get me a new access token but it did not and using google’s curl endpoint showed that the token expired and auth0 was not refreshing it. I am investigating moving completey to google now as I have exhausted all options from what I can tell and there is no step by step on 3rd party identity provider refresh tokens (probably easier to integrate on my own with each one since they do have refresh token docs where auth0 does not really and you have to piece together many docs and forum posts - I could not piece it together I guess)

I see no document on full steps to get the google refresh token and tried to piece together forum posts but could not.  
thanks,  
Dean

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [November 8, 2023, 10:24pm UTC](https://community.auth0.com/t/how-to-do-user-login-and-get-refresh-token-to-invoke-gmail-apis/120076/2 "2023-11-08T22:24:37Z")

</div>

Hey @dean2 sorry for the delayed response here, but wanted to get back to you regardless.

You should be able to get a Google refresh token by including `access_type=offline` as a param in your initial authorize request as mentioned here:

> **[Identity Provider Access Tokens](https://auth0.com/docs/secure/tokens/access-tokens/identity-provider-access-tokens#renew-third-party-tokens)**
>
> Understand third-party access tokens issued by identity providers after user authentication and how to use them to call the third-party APIs.

---

<div class="post-metadata">

**Author:** ![dean2](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dean2/32/35668_2.png) [@dean2](https://community.auth0.com/u/dean2)\
**Post date:** [November 13, 2023, 12:53pm UTC](https://community.auth0.com/t/how-to-do-user-login-and-get-refresh-token-to-invoke-gmail-apis/120076/4 "2023-11-13T12:53:37Z")

</div>

In my example above, I see the line &access\_type=offline but for some reason, refresh token was the mgmt api refresh token and not google’s when I tried to validate with google. I gave up and I have it 100% working in google now . If I recall, when I read the Identity as well, the refresh token was not there in the identity provideer either. At any rate, now that I have a working thing with google, I do not have time to revisit with auth0 anymore. thanks!!!

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [November 14, 2023, 12:39am UTC](https://community.auth0.com/t/how-to-do-user-login-and-get-refresh-token-to-invoke-gmail-apis/120076/5 "2023-11-14T00:39:18Z")

</div>

Hey @dean2 !

You’re right, I completely missed the `access_type=offline` param in your first request - Things can certainly get a bit complex when working with external IDP tokens, but I am glad to hear you got this working with Google directly and that suits your use case.

Cheers!

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [November 14, 2023, 12:39am UTC](https://community.auth0.com/t/how-to-do-user-login-and-get-refresh-token-to-invoke-gmail-apis/120076/6 "2023-11-14T00:39:28Z")

</div>


