JHipster React Native uses Expo's AuthSession library for integrating with Keycloak and Okta.
Configure the redirect URIs for your app in your Identity Provider's authorized redirect URI list.
https://auth.expo.io/@your-expo-username/reactNativeAppName
- Use the value for
reactNativeAppName
in your.yo-rc.json
- Use your Expo username in place of
@your-expo-username
(runexpo whoami
) - Used for Expo's Auth Proxy
- Use the value for
- Some identity providers may require you to configure this value as a logout URL too
http://localhost:19006/
- For local development with
react-native-web
- For local development with
https://your-app-domain.com/
- For production deployment with
react-native-web
- For production deployment with
Edit src/main/docker/realm-config/jhipster-realm.json
and add the redirect URIs above to all instances of the redirectUris
array. Make sure to restart the Keycloak Docker container after making any changes.
Note: When running the backend locally for Android, you will need to run the following commands so the app can communicate with both Keycloak and your backend on localhost:
adb reverse tcp:8080 tcp:8080 && adb reverse tcp:9080 tcp:9080
Note: You can do the following steps the Okta Dashboard if preferred.
Using the Okta CLI, run okta apps create
- For "Type of Application" choose
Native
- For "Redirect URI" and "Post Logout Redirect URI" provide
http://localhost:19006/,https://auth.expo.io/@your-expo-username/reactNativeAppName
- Change
@your-expo-username
to match your Expo username (runexpo whoami
) - Change
reactNativeAppName
to the value provided during generation (look in your.yo-rc.json
)
- Change
Copy the provided clientId
to app/config/app-config.js
, and set nativeClientId
to the copied value. This is loaded in login.sagas.js
during authentication.
If you're using Auth0, you'll also need to change the
audience
inapp/modules/login/login.utils.ts
. For example:audience: 'https://dev-06bzs1cu.us.auth0.com/api/v2/',
You can now log in to Okta through React Native clients on iOS, Android, and Web.
Note: These steps are only necessary if you are using JHipster v6, or JHipster v7 with a Reactive JHipster backend.
Follow the instructions under "Add Claims to Access Token" in the JHipster Ionic ReadMe.
Expo's auth proxy does not currently work with logging out from the identity provider (supported and enabled on Web). If you want to completely sign out on native apps:
- Change
useExpoAuthProxy
tofalse
inapp-config.js
- Configure your redirect URLs for logout in your identity provider
- Usually something like
exp://127.0.0.1:19000
andexp://10.0.0.114:19000
, where10.0.0.114
is your local IP
- Usually something like
- A popup will appear on browser open, but will say "Expo wants to use identity-provider.com to sign in", but it will really be signing out.