-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for multiple Auth0 tenants #421
Comments
Yeah +1 mate, this caveat of the Our situation is similar, except instead of using multiple tenants to isolate staging and production - we use them to region specific logins so that we comply with GDPR for customers in the EU. For instance, if a project is in the UK, we sign in users with our EU tenant - whereas a project in Australia would sign in using a global tenant. At one point we contemplated having region specific builds to handle this, except users can sometimes switch between global regions and alas the dynamic approach made much more sense for us. As @ptrowan indicates above, the approach prior to <!-- android/app/src/main/AndroidManifest.xml -->
<activity
android:name=".MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- You could list all necessary Auth0 URL's below, eg -->
<!-- Australia Region URL -->
<data
android:host="example.au.auth0.com"
android:pathPrefix="/android/${applicationId}/callback"
android:scheme="${applicationId}" />
<!-- EU Region URL -->
<data
android:host="example.eu.auth0.com"
android:pathPrefix="/android/${applicationId}/callback"
android:scheme="${applicationId}" />
</intent-filter>
</activity> We were then able to manage tenant switching ourselves on the JavaScript side by simply reinitializing the Auth0 class with a new Base URL as required. But since
...there unfortunately seems to be no option for us to "safelist" multiple URL's anymore? 😟 |
This is completely blocking our team from upgrading as well. |
This new flow is very inconvenient at dev env, nobody want to mess up in the production env, so we have to change continuesly the config. |
Same problem here. We have in production an App with open Domain and now we are blocked with the v2.9.0. Before we could set the
In the actual version of the library I try to remove the Could be possible to set an empty |
Hi @ptrowan, thanks for raising this. Please let me know if that helps. |
@Widcket adding an activity with
(which is identical to the |
@ptrowan thanks for sharing the solution, so android:launchMode="singleTask" from the main activity should be removed right? And no need to add manifestPlaceholders? |
I am also facing this exact issue in Android where after signing in, the application is restarting, how did you end up resolving it? |
Deleting |
Now, auth0 documentation says you have to write this in your build.gradle : manifestPlaceholders = [auth0Domain: "domain", auth0Scheme: "${applicationId}.auth0"] But, this is totally dumb as you can't pass multiple domains??? Any solution? |
For anyone else coming across this. Usage: const withAuth0MultiTenancy = require("./withAuth0MultiTenancy");
module.exports = {
expo: {
name: "YourAppName",
slug: "your-app-slug",
android: {
package: "com.example.app", // Replace with your app's package name
},
plugins: [
[
withAuth0MultiTenancy,
{
flters: [
{
host: "host1.com",
pathPrefix: "/android/${applicationId}/callback",
scheme: "mysheme",
},
{
host: "host2.com",
pathPrefix: "/android/${applicationId}/callback",
scheme: "myscheme",
},
]
},
],
],
},
};
const { withAndroidManifest } = require("@expo/config-plugins");
/**
* Adds a custom activity with intent filters to the AndroidManifest.xml.
* @param {object} androidManifest - The parsed AndroidManifest.xml object.
* @param {Array} filters - Array of objects containing host, pathPrefix, and scheme.
* @returns {object} - The modified AndroidManifest.xml object.
*/
const addCustomActivity = (androidManifest, filters) => {
const appNode = androidManifest.manifest.application[0];
// Define the new activity with the provided filters
const newActivity = {
$: {
"android:name": "com.auth0.react.RedirectActivity",
"android:exported": "true",
"tools:node": "replace",
},
"intent-filter": [
{
action: [
{
$: {
"android:name": "android.intent.action.VIEW",
},
},
],
category: [
{
$: {
"android:name": "android.intent.category.DEFAULT",
},
},
{
$: {
"android:name": "android.intent.category.BROWSABLE",
},
},
],
data: filters.map((filter) => ({
$: {
"android:host": filter.host,
"android:pathPrefix": filter.pathPrefix,
"android:scheme": filter.scheme,
},
})),
},
],
};
// Initialize activities array if it doesn't exist
if (!appNode["activity"]) {
appNode["activity"] = [];
}
// Find index of existing Auth0 redirect activity
const existingActivityIndex = appNode["activity"].findIndex(
(activity) => activity.$?.["android:name"] === "com.auth0.react.RedirectActivity"
);
// Replace if exists, otherwise add
if (existingActivityIndex !== -1) {
appNode["activity"][existingActivityIndex] = newActivity;
} else {
appNode["activity"].push(newActivity);
}
return androidManifest;
};
/**
* Custom Expo Config Plugin to add an Auth0 Multi-Tenant Redirect Activity.
* @param {object} config - The Expo configuration object.
* @param {Array} filters - Array of objects containing host, pathPrefix, and scheme.
* @returns {object} - The modified Expo configuration object.
*/
const withAuth0MultiTenancy = (config, { filters = [] }) => {
return withAndroidManifest(config, (config) => {
config.modResults = addCustomActivity(config.modResults, filters);
return config;
});
};
module.exports = withAuth0MultiTenancy; |
How can I use your approach in bare RN project |
@caolong0204 @jnjdev42 Supporting multiple tenants has been made possible again (in a barebones RN project) if you are able to upgrade your Auth0 SDK to Version 4. iOS requires no changes after following the setup instructions (since you no longer need to add your domain config in XCode), and you can refer to my answer here to get Android working: #747 (comment) |
Before version 2.9, we were able to add support for multiple tenants (for example, we have a dev tenant and a prod tenant) by simply adding multiple
<data/>
tags to the intent filter, one for each auth0 domain we use.With the updates in version 2.9, we can only specify one Auth0 domain. We can swap between Auth0 domains between doing production builds and dev builds, but in our use case, our team needs to be able to swap between dev & prod servers at runtime (which worked with multiple data tags).
Don't know enough about Android/Gradle to know the limitations of manifestPlaceholders, but it doesn't seem like having list-type placeholders that generate tags would be possible.
Another solution would be to have option to specify the intent filter in the user's AndroidManifest, like how it was done pre-v2.9 (not sure if there's already a way to override the react-native-auth0's AndroidManifest)
Was able to get around this by adding multiple
<data>
tags to the intent filter inside of node_modules/react-native-auth0, and add corresponding manifestPlaceholders (e.g. auth0Domain_prod and auth0Domain_dev) but obviously this is not a real solution.The text was updated successfully, but these errors were encountered: