React-native-auth0: How can I get 'refresh token' in React Native?

Created on 18 Oct 2019  路  5Comments  路  Source: auth0/react-native-auth0

Hi,

Now I am trying to get 'refresh token' in React Native.
I've checked this document.
https://auth0.com/docs/tokens/refresh-token/current
It seems I can get 'refresh token' via only browser, not SDK. Is it right?
Please let me know.

Thank you.

Most helpful comment

@joshcanhelp I have the same problem. I can open a new issue if necessary.

It seems that auth0 is not returning the refresh token when using webauth. I followed the instructions in this repo's readme to the letter.

I call the sdk like so:

        const auth0 = new Auth0({
            domain: 'mydomain',
            clientId: 'myclientid,
        });
        auth0.webAuth
            .authorize({
                scope: 'openid email offline_access',
                audience: 'myaudience',
            })
            .then(c => {
                console.log(c);
            })
            .catch(e => console.log(e));

and I get this logged as the response:

{
  "accessToken": "...",
  "expiresIn": 86400,
  "idToken": "...",
  "scope": "openid email",
  "tokenType": "Bearer"
}

There's no refresh token there, and the offline_access scope disappeared.

All 5 comments

@a-jumping425 - I'm not sure I'm totally clear on your question here but I'll take a stab at it.

Refresh tokens need to be obtained and stored securely so they should never be obtained through the browser or stored in the browser. Native applications (like a React Native application) can obtain and store them securely. Requesting a refresh token is done by adding offline_access to the scope parameter used when logging in. Once you have it stored, it can be used like so.

@a-jumping425 there? This is knox. Can we discuss about auth token in React Native?
I am very interested in your post.

@joshcanhelp I have the same problem. I can open a new issue if necessary.

It seems that auth0 is not returning the refresh token when using webauth. I followed the instructions in this repo's readme to the letter.

I call the sdk like so:

        const auth0 = new Auth0({
            domain: 'mydomain',
            clientId: 'myclientid,
        });
        auth0.webAuth
            .authorize({
                scope: 'openid email offline_access',
                audience: 'myaudience',
            })
            .then(c => {
                console.log(c);
            })
            .catch(e => console.log(e));

and I get this logged as the response:

{
  "accessToken": "...",
  "expiresIn": 86400,
  "idToken": "...",
  "scope": "openid email",
  "tokenType": "Bearer"
}

There's no refresh token there, and the offline_access scope disappeared.

@bunea I was having the same issue, enabling this setting in the API on the Auth0 Dashboard fixed it.

https://github.com/auth0/react-native-auth0/issues/279#issuecomment-586506570

As well as setting the Rotating Token Behavior under the Application Tokens in my Application Settings

Just adding to @DarioVaccaro's response with a supplemental screenshot for anyone that runs into this issue.

Under Application Settings, the following toggle fixed it so refreshToken(...) returns a refreshToken in the response object.

Screen Shot 2021-04-20 at 9 17 26 PM

Was this page helpful?
0 / 5 - 0 ratings