This sample demonstrates using an iTwin service app so that an iTwin Mobile app can make use of a 3rd party authentication provider. It uses auth0 for user authentication. The sample uses Jetpack Compose UI to authenticate against an auth0 account and obtain an ID token. It then uses that ID token as the authentication when communicating with a demo iTwin token provider server running on the developer's computer. The token provider server validates that the token is from the proper auth0 domain, and then uses a client secret that was created during the registration of the iTwin service app to generate an iTwin access token.
If you want to run the sample, you will need to set up an auth0 account and configure it to work with this sample. However, while this sample uses auth0, the 3rd party authentication workflow should work the same with any authentication provider. Specifically:
- Have the user sign in and get a token.
- Automatically refresh this token as needed.
- Use this token in the
Authentication
header sent to a custom iTwin access token provider. - Create a web service app that runs on a server somewhere.
- Have this app validate the incoming token to decide whether the user is authorized, and if so to what extent.
- Return an iTwin service access token based on your authentication of the user.
-
Follow the instructions in the Android Readme.
-
Follow the instructions to setup auth0 in the Auth0 Readme
-
Add the following environment variables to your ITMSamples.properties file and configure them to match the auth0 client:
itmsample.auth0_client_id itmsample.auth0_domain itmsample.auth0_audience
-
Add
itmsample.token_server_url
to the ITMSamples.properties file so the sample app knows where to find the token server. The initital valuehttp://10.0.2.2:3001
should work from an emulator, but will need to be adjusted if running from a device.Note: The
itmsample.*
variables in the above steps will be accessible as resources via R.string in the native Android code. -
Follow the instructions in the Token Server Readme.
-
Open the ThirdPartyAuth folder (where this README.md file resides) in Android Studio.
-
Sync project with gradle files, build, and run.
-
Hit Log in.
-
Select "Sign up" and create an account.