nativescript-auth0 icon indicating copy to clipboard operation
nativescript-auth0 copied to clipboard

Struggling to set access type = 'offline'

Open krthush opened this issue 5 years ago • 0 comments

I am trying to add calendar sync capability to my application, and I'd like to do this by using the Google Social login provided by Auth0.

The main problem I am having is with obtaining the Google refresh token, which should be within the user.identities[0].access_token when looking at a user's profile called from Auth0 User Management API (this is highlighted here: https://auth0.com/docs/connections/calling-an-external-idp-api#step-3-extract-the-idp-access-token).

Now to be able to succesfully to do this, the docs mention you MUST include access type = 'offline' when calling the /authorize endpoint (as mentioned here: https://auth0.com/docs/tokens/overview-idp-access-tokens). I haven't been able to do this properly through the nativescript app, thus not able to get the refresh token from the user profile.

My /authorize section of the code looks like this...

auth0.webAuthentication({  
 scope: 'openid offline_access email profile',  
  parameters: {  
    "prompt": type  
  },  
  scheme: 'com.emit.app',  
  audience: 'https://emitapp.co.uk/api'  
}).then((result) => { ....   

Now I've tried adding parameters in all over the place (one at a time when testing) similar to this...

auth0.webAuthentication({
  scope: 'openid offline_access email profile',
  parameters: {
    "prompt": type,
    'access_type': 'offline',
    'accessType': 'offline',
    'access type': 'offline'
  },
  scheme: 'com.emit.app',
  audience: 'https://emitapp.co.uk/api'
  access_type: 'offline'
}).then((result) => {

The even wierder thing is that even if the user logs in on the webapp (there I am able to flow working to get the refresh token), when they then log onto the phone app the refresh token gets either 'deleted' or 'hidden' and since google doesn't reissue the token, I'm never able to obtain it again. I've resorted forcing my users to log in on my webapp and storing the refresh token on the server side. I'd really appreciate it if I could get the users who login on the Nativescript App showing the Google refresh token in their profile from Auth0 since I'm not a huge fan of storing them on my server vs Auth0's servers.

I've tried looking into people with similar problems as follows (unfortunatly no success, since most I assume are for webapps and not native code): https://community.auth0.com/t/store-and-retrieve-google-refresh-token/28973 https://community.auth0.com/t/need-help-with-fetching-refresh-token-from-google-social-login/11699 https://community.auth0.com/t/cant-get-google-refresh-token-using-auth0-js/11756

krthush avatar Dec 13 '19 21:12 krthush