Problem statement
A mobile app is being developed for both iOS and Android.
- for iOS, the code is written in Swift
- for Android, the code is written in Kotlin
The iOS SDK was used to configure a native Swift application that uses the Universal Login flow.
The next step will be to implement Universal Login for the Android code. However, it is not clear whether it is necessary to create a separate app for this purpose.
- Is it necessary to create two native Auth0 applications, one for iOS and one for Android?
- Can two native applications share the same database connection?
Solution
Shared Native App Creation
It is not necessary to create two different applications in Auth0 to handle both the Android and iOS mobile apps. However, the Allowed Callbacks in the Application Settings would need to include the callbacks of both applications. For details, refer to Application URIs
The documentation for both Swift and Android quickstarts describes the required configuration that must be performed in the Auth0 dashboard:
Android quickstart: Configure Callback URLs
iOS quickstart: Configure Callback URLs
Although having a single native Auth0 application for both iOS and Android has the advantage of simplicity and less development effort, it does have a number of drawbacks.
Separate Native Apps for iOS and Android
Creating separate Auth0 applications for the iOS and Android mobile apps offers the following advantages:
- Maintenance and debugging will be easier since logs will include the specific application name, which will make it easier to identify and diagnose problems
- Configuring separate Auth0 native applications makes it possible to set the “Application Login Route” configuration per app. This action is recommended for browser-based flows. For further details, refer to the Application Login URI configuration in Application URIs. Auth0 takes the user back to this page when a session cannot be found for some reason. For further information about browser-based login flows using native apps, refer to Browser-based Login
Two Native Apps with a Shared Connection
If required, it is possible for two native apps to share the same Auth0 username-password-authentication connection.
The main advantage of using the same connection for both applications is that if the user has two devices - one Android and one iOS - then it would be possible to use the same user account from either of the applications.
To assign a connection to an application:
- Login to the Auth0 dashboard as a tenant member ( Administrator )
- Navigate Authentication > Database > [database_name]
- On the configuration page for that database, select Applications from the top menu
- From the list of applications, select the native app and toggle this to the On ( green ) position (See example below)
Associate a User with a Native App
It may be desirable to know which type of native application (Android or iOS) a user is associated with. This can be achieved by using an Action to add this information as user_metadata to the user’s profile. For more details, refer to Manage User Data with the Post-Login Action Trigger
For example, on user signup, add a property to the user that tells you if the user initially registered with iOS or Android. However, as previously discussed, the user could be used in either of the applications. In that case, it would be necessary to add some logic to your application code that determines whether a user is associated with just one type of native app ( iOS or Android ) or both types.