Name: react-native-auth0
Owner: Auth0
Description: React Native toolkit for Auth0 API
Created: 2016-06-14 23:10:12.0
Updated: 2018-05-18 21:22:37.0
Pushed: 2018-04-25 18:16:38.0
Homepage: https://auth0.com
Size: 974
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
React Native toolkit for Auth0 API
React Native 0.26+
Install react-native-auth0
using npm
install react-native-auth0 --save
Or via yarn
add react-native-auth0
then you need to link the native module in react-native-auth0
t-native link react-native-auth0
This section is for those that want to use WebAuth, if you dont need it just ignore this section.
In the file android/app/src/main/AndroidManifest.xml
you must make sure the MainActivity of the app has a launchMode value of singleTask
and that it has the following intent filter:
ent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="YOUR_AUTH0_DOMAIN"
android:pathPrefix="/android/${applicationId}/callback"
android:scheme="${applicationId}" />
tent-filter>
So if you have samples.auth0.com
as your Auth0 domain you would have the following MainActivity configuration:
ivity
oid:name=".MainActivity"
oid:label="@string/app_name"
oid:launchMode="singleTask"
oid:configChanges="keyboard|keyboardHidden|orientation|screenSize"
oid:windowSoftInputMode="adjustResize">
ent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
tent-filter>
ent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="samples.auth0.com"
android:pathPrefix="/android/${applicationId}/callback"
android:scheme="${applicationId}" />
tent-filter>
tivity>
For more info please read react native docs
In order to reduce the potential for conflict which may be caused by the presence of differing versions of the Android support libraries, you may wish to configure project-wide properties. Setting the Compile and Target SDK versions, Build Tools version, and Support Library version in your root project's build.gradle
file will make react-native-auth0
and many other React Native modules use them.
Inside the ios
folder find the file AppDelegate.[swift|m]
add the following to it
ort <React/RCTLinkingManager.h>
OOL)application:(UIApplication *)application openURL:(NSURL *)url
urceApplication:(NSString *)sourceApplication annotation:(id)annotation
turn [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
Inside the ios
folder open the Info.plist
and locate the value for CFBundleIdentifier
, e.g.
>CFBundleIdentifier</key>
ing>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
and then register a URL type entry using the value of CFBundleIdentifier
as the value of CFBundleURLSchemes
>CFBundleURLTypes</key>
ay>
<dict>
<key>CFBundleTypeRole</key>
<string>None</string>
<key>CFBundleURLName</key>
<string>auth0</string>
<key>CFBundleURLSchemes</key>
<array>
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
</array>
</dict>
ray>
The value
org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)
is the default for apps created with React Native CLI, you may have a different value.For more info please read react native docs
Callback URLs are the URLs that Auth0 invokes after the authentication process. Auth0 routes your application back to this URL and appends additional parameters to it, including a token. Since callback URLs can be manipulated, you will need to add this URL to your Application's Allowed Callback URLs for security. This will enable Auth0 to recognize these URLs as valid. If omitted, authentication will not be successful.
Go to the Auth0 Dashboard, select your application and make sure that Allowed Callback URLs contains the following:
sq
R_BUNDLE_IDENTIFIER}://${YOUR_AUTH0_DOMAIN}/ios/{YOUR_BUNDLE_IDENTIFIER}/callback
R_APP_PACKAGE_NAME}://{YOUR_AUTH0_DOMAIN}/android/{YOUR_APP_PACKAGE_NAME}/callback
rt Auth0 from 'react-native-auth0';
t auth0 = new Auth0({ domain: '{YOUR_AUTH0_DOMAIN}', clientId: '{YOUR_CLIENT_ID}' });
0
.webAuth
.authorize({scope: 'openid email', audience: 'https://{YOUR_AUTH0_DOMAIN}/userinfo'})
.then(credentials => console.log(credentials))
.catch(error => console.log(error));
This snippet sets the
audience
to ensure OIDC compliant responses, this can also be achieved by enabling the OIDC Conformant switch in your Auth0 dashboard underApplication / Settings / Advanced OAuth
. For more information please check this documentation.
0
.auth
.passwordRealm({username: "info@auth0.com", password: "password", realm: "myconnection"})
.then(console.log)
.catch(console.error);
0
.auth
.userInfo({token: 'user access_token'})
.then(console.log)
.catch(console.error);
0
.auth
.refreshToken({refreshToken: 'user refresh_token'})
.then(console.log)
.catch(console.error);
0
.auth
.createUser({email: 'info@auth0.com', username: 'username', pasword: 'password', connection: 'myconnection'})
.then(console.log)
.catch(console.error);
0
.users('user token')
.patchUser({id: 'user_id', metadata: {'first_name': 'John', 'last_name': 'Doe'}})
.then(console.log)
.catch(console.error);
0
.users('user token')
.getUser({id: "user_id"})
.then(console.log)
.catch(console.error);
For more info please check our generated documentation
Auth0 helps you to:
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
This project is licensed under the MIT license. See the LICENSE file for more info.