I have a react-native project that uses an embedded login and react-native-auth0 (using expo AuthSession). I allow users to login with email/password, or social (facebook, google). I need the ability to store a refresh token on the device but I have only been successful in doing so with the email/password login with offline_access scope.
The auth0 sdk provides an utility class in both IOS or Android SDK to store token security. You can take advantage of the interface. That following article explains that in details
I should mention that I am using Expo for this project and the app has not been ejected. I was hoping to find a solution that would not require me to do so.
Here is the project that I was using for guidance:
In my social login method I’m trying to use the /authorize endpoint and expo AuthSession
At https://auth0.com/docs/api/authentication#social it shows that I can include ADDITIONAL_PARAMETERS such as access_type=offline to retrieve a refresh token from the social provider. My attempts at doing so have been unsuccessful (using scope and appending ?access_type=offline to the request).
Please let me know if there are any other possible solutions you could direct me to.
Are you seeing any specific error when you are working with access_type=offline? We don’t have samples written up for this specific use case with expo. I would like help, i just need more information. Thanks!
The react-native-auth0 library implements the code authorization grant with PKCE , which is the appropriate flow for native applications. Your direct usage of the /authorize endpoint with response_type=token is triggering an “implicit flow” like @James.Morrison said, which is the flow used in SPA. The implicit flow, by definition, does not return refresh tokens because SPAs are not suited to keep a refresh token securely.
You can leverage react-native-auth0’s authorize method, which uses the code grant with PKCE. The recommended usage would display Auth0’s hosted login page (to let the user choose the desired login method) but if you are putting that option in your application, you can put the connection name directly in the authorize request like this:
I’ve tried react-native-auth0’s authorize method exactly how you have it there. The error displayed is: Missing NativeModule. Please make sure you run react-native link react-native-auth0
I am using Expo for this project and I’m looking for a solution that does not require me to eject the app to link libraries.
Not sure how Expo works and didn’t understand the “eject” bit, sorry about that.
Our libraries do indeed open the device’s native browser as per recommendations of the OAuth 2.0 Threat Model and Security Considerations. An embedded WebView is rejected by some identity providers (like Google) because it could potentially enable an application to steal the user credentials or do other malicious activities on behalf of the user (like automatically giving consent without the user intervention).
If you want to implement the flow in the app’s embedded browser (which, again, is not recommended because of security concerns and might be rejected by some identity providers) you will have to implement the Code Authorization grant with PKCE to obtain refresh tokens.