Configure OAuth 2.0 in ThingsBoard App
The mobile app supports OAuth 2.0 authentication. When configured, additional sign-in buttons appear on the login screen so users can authenticate with the configured OAuth 2.0 provider. A System or Tenant Administrator configures OAuth 2.0. For general OAuth configuration, see OAuth 2.0 Support.
Add an OAuth 2.0 client to the bundle
Section titled “Add an OAuth 2.0 client to the bundle”The mobile app uses the OAuth 2.0 clients selected in its bundle. Create the client first and then select it in the bundle, or create it directly from the bundle.
Option 1: Create the client, then select it in the bundle
Section titled “Option 1: Create the client, then select it in the bundle”- Go to Security → OAuth 2.0 in the left main menu and open the OAuth 2.0 clients tab.
- Click + Add OAuth 2.0 client, configure the provider, and make sure Android and/or iOS are among its allowed platforms.
- Go to Mobile apps → Bundles and click the target bundle.
- Open the OAuth 2.0 tab, turn on Enable OAuth 2.0, and select the client in the OAuth 2.0 clients field.
- Click Next through the remaining steps and save the bundle.
Option 2: Create the client from the bundle
Section titled “Option 2: Create the client from the bundle”- Go to Mobile apps → Bundles and click the target bundle.
- Open the OAuth 2.0 tab, turn on Enable OAuth 2.0, and click Create new next to the OAuth 2.0 clients field.
- Configure the provider and click Add. The new client is selected in the bundle.
- Click Next through the remaining steps and save the bundle.
Configure the mobile app
Section titled “Configure the mobile app”The app takes its OAuth 2.0 settings from the bundle configuration file. No code changes are needed.
-
Go to Mobile apps → Bundles and click the Configuration app button in the row of the target bundle.
-
Click Download file to get
configs.json. It contains the callback URL scheme (thingsboardOAuth2CallbackUrlScheme) and the application secrets the app uses for OAuth 2.0. -
Put
configs.jsonin the project root, next topubspec.yaml, replacing the existing file if you downloaded one earlier. -
Rebuild the app:
Terminal window flutter run --dart-define-from-file=configs.json
Verify OAuth 2.0 setup
Section titled “Verify OAuth 2.0 setup”Run the mobile app. The login screen should show the OAuth 2.0 sign-in button(s) at the top. Use one to log in as an existing user to confirm the setup works.
Was this helpful?