# Google Refresh token not returning in user profile's identities section

**URL:** <https://community.auth0.com/t/google-refresh-token-not-returning-in-user-profiles-identities-section/92609>\
**Category:** Get Help\
**Created:** [October 18, 2022, 8:18am UTC](https://community.auth0.com/t/google-refresh-token-not-returning-in-user-profiles-identities-section/92609 "2022-10-18T08:18:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gal2](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gal2/32/40669_2.png) [@gal2](https://community.auth0.com/u/gal2)\
**Post date:** [October 18, 2022, 8:18am UTC](https://community.auth0.com/t/google-refresh-token-not-returning-in-user-profiles-identities-section/92609/1 "2022-10-18T08:18:21Z")

</div>

Hi all

This is my use case:

1. User signs in to my app via social login (google). The app is a **SPA** , using this code:

```javascript
import { Auth0Client, User } from "@auth0/auth0-spa-js";

// init auth0 client
this.auth0 = new Auth0Client({
            domain: domain,
            client_id: clientId,
            audience: `https://${domain}/userinfo`,
            cacheLocation: "localstorage",
            useRefreshTokens: true,
            responseType: "id_token",
            scope: "openid profile email offline_access",
            connection: "google-oauth2",
            redirect_uri: `${window.location.origin}/home`,
            accessType: "offline",
            approvalPrompt: "consent",
            access_type: "offline",
            connection_scope:
                "https://www.googleapis.com/auth/calendar",
        });

...

// login which calls auth0 authorize endpoint
        await this.auth0.loginWithRedirect({
            redirect_uri: `${window.location.origin}/setup`,
            accessType: "offline",
            approvalPrompt: "consent",
            access_type: "offline",
            connection_scope:
                "https://www.googleapis.com/auth/calendar",
        });

```

1. All scopes required for my app are requested (calendar, profile, email)
2. Backend job tries to access google calendar API on behalf of user:  
a. Get user profile from Auth0  
b. Get the user’s google access/refresh token from `user.identities[0]`  
c. Refresh token if expired (using the `user.identities[0].refresh_token` from above  
d. Call Calendar API

However, when I get the user profile from mgmt API: `/api/v2/users`, I do not get the google refresh token, though [documentation says otherwise](https://auth0.com/docs/secure/tokens/access-tokens/identity-provider-access-tokens). **Only the access\_token (which is short lived) is returned**

How can I get Google refresh token returned from Auth0 user profile if my app is an SPA?

---

<div class="post-metadata">

**Author:** ![gal2](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gal2/32/40669_2.png) [@gal2](https://community.auth0.com/u/gal2)\
**Post date:** [October 18, 2022, 5:05pm UTC](https://community.auth0.com/t/google-refresh-token-not-returning-in-user-profiles-identities-section/92609/2 "2022-10-18T17:05:52Z")

</div>

I have since changed the code to use PKCE flow, still does not work:

```javascript
        this.auth0 = new Auth0Client({
            domain: domain,
            client_id: clientId,
            audience: `https://${domain}/userinfo`,
            cacheLocation: "localstorage",
            useRefreshTokens: true,
            responseType: "code",
            code_challenge_method: "S256",
            scope: "openid profile email offline_access",
            connection: "google-oauth2",
            redirect_uri: `${window.location.origin}/home`,
            approvalPrompt: "force",
            access_type: "offline",
            connection_scope: "https://www.googleapis.com/auth/calendar",
        });
// ... 

        const challenge = await this.getAuthChallenge();
        console.log({ challenge });
        await this.auth0.loginWithRedirect({
            redirect_uri: `${window.location.origin}`,
            approvalPrompt: "force",
            access_type: "offline",
            connection_scope: "https://www.googleapis.com/auth/calendar",
            code_challenge: challenge,
        });

```

Though Google does show “offline access” as requested:

![image](https://global.discourse-cdn.com/auth0/original/3X/f/2/f26ebc761b4f04262e62a768d3daef404787f316.png)

---

<div class="post-metadata">

**Author:** ![gal2](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gal2/32/40669_2.png) [@gal2](https://community.auth0.com/u/gal2)\
**Post date:** [October 23, 2022, 7:33am UTC](https://community.auth0.com/t/google-refresh-token-not-returning-in-user-profiles-identities-section/92609/3 "2022-10-23T07:33:15Z")

</div>

Adding reply to bump this to the top

---

<div class="post-metadata">

**Author:** ![thameera](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/thameera/32/13430_2.png) [@thameera](https://community.auth0.com/u/thameera)\
**Post date:** [October 24, 2022, 7:26am UTC](https://community.auth0.com/t/google-refresh-token-not-returning-in-user-profiles-identities-section/92609/4 "2022-10-24T07:26:28Z")

</div>

I just tested with the following snippets and it seemed to work (using auth0-spa-js 1.22):

```auto

auth0 = await createAuth0Client({
  domain: DOMAIN,
  client_id: CLIENT_ID,
  redirect_uri: URL,
  scope: 'openid email profile offline_access',
  audience: 'https://example.com'
})

await auth0.loginWithRedirect({
  access_type: 'offline',
  connection_scope: 'https://www.googleapis.com/auth/calendar',
  connection: 'google-oauth2'
})

```

The user should have both an `access_token` and a`refresh_token` in the identities array.

Also, make sure that the access token you call Management API (`GET /api/v2/users`) with has the `read:user_idp_tokens` scope. If not, it will return the identities array without those two attributes.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 18, 2024, 4:15pm UTC](https://community.auth0.com/t/google-refresh-token-not-returning-in-user-profiles-identities-section/92609/5 "2024-12-18T16:15:40Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
