function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Daniel González J.Daniel González J. 

React Native: Cannot get Refresh Token - OAuth 2.0 User-Agent Flow

We are developing a React Native App with Expo using Auth2 User Agent Flow (https://help.salesforce.com/articleView?id=remoteaccess_oauth_user_agent_flow.htm&type=0)

I have checked all different post about this topic but I still cannot receive it.

  1. Managed App > Scope > Perform requests on your behalf at any time (refresh_token, offline_access) enabled
  2. Managed App > Scope > Full Access (full) enabled

This is what we send 

https://login.salesforce.com/services/oauth2/authorize
?response_type=token
&client_id=OurCustomerKeyFromTheOrg
&redirect_uri=https%3A%2F%2Fauth.expo.io%2F%40robertovg_pve%2FprecursiveMobile

We receive all data (access_token, instance_url,..) but no refresh_token.

Reading official doc, we have added scope=refresh_token / scope=full%20refresh_token  but the response we have is that "refresh_token" is not a valid scope.

Also, we changed redirectUrl as https://login.salesforce.com/services/oauth2/success but then, how can we redirect back to the app? Putting this url, it gets stuck on the browser after putting credentials

What we missed? What else we can try? Thanks in advance.

Best Answer chosen by Daniel González J.
Santosh Reddy MaddhuriSantosh Reddy Maddhuri
Hi Daniel.

Please  follow the comments made by "Ken Koellner 7"  with code snippets in the below link and you should be able to achieve what you are looking for.

https://developer.salesforce.com/forums/?id=906F0000000AgInIAK


Hope this helps.Mark this as best answer if it works, so others can benefit too.

Regards,
Santosh.

All Answers

Santosh Reddy MaddhuriSantosh Reddy Maddhuri
Hi Daniel.

Please  follow the comments made by "Ken Koellner 7"  with code snippets in the below link and you should be able to achieve what you are looking for.

https://developer.salesforce.com/forums/?id=906F0000000AgInIAK


Hope this helps.Mark this as best answer if it works, so others can benefit too.

Regards,
Santosh.
This was selected as the best answer
Daniel González J.Daniel González J.

Thank you Santosh, definitely I have replaced this authentication method by OAuth2 Web Server https://help.salesforce.com/articleView?id=remoteaccess_oauth_web_server_flow.htm&type=0

Finally, we received now this refresh_token using this method.

Something good to know is that scope=refresh_token in the first auth request (code) will give you an access_token which you cannot use for make request to REST API (you will see this error: https://developer.salesforce.com/forums/?id=9060G0000005XRQQA2). Anyway, this param is not required and can be removed from request.

Thanks.