Connect an Android Mobile App
Android applications can authenticate using The Identity Hub. This can be done using one of the Authentication Endpoints like OAuth, OpenID Connect... or using the Android SDK.
SDK and Demo App.
A preconfigured SDK can be downloaded from the App Configurations Details page.
Or download the non-configured SDK from here.
A demo app can be found here.
Installing the SDK
- Download the SDK from the App Configurations Details page or download the non-configured SDK from here.
- To integrate the com.theidentityhub with your Android Project in Eclipse extract it into your workspace folder and import it in Eclipse (File | Import | General | Existing Projects into Workspace | Select root directory: [FOLDER WHERE YOU HAVE EXTRACTED] | Finish).
- After you have imported Project Explorer will show imported project under the name TheIdentityHubLibrary. Make sure you keep open TheIdentityHubLibrary.
- To start using TheIdentityHubLibrary in your Android Application project you have to modify properties in your Android Application project.
- Select your Android Application project in Project Explorer. Open the properties (File | Properties).
- On the left tree select Android.
- In the right panel in a Library frame click Add...
- Select TheIdentityHubLibrary project and then click OK.
- Click OK the Properties dialog.
- Your Android Application project is ready to use TheIdentityHubLibrary.
Initialize the Identity Service
Inside the activity in some of your event triggered methods set configuration parameters:
// Your ClientId
String CLIENT_ID = "[ClientId]";
// Your base URL
String BASE_URL = "https://www.theidentityhub.com/{tenant}";
// Initialize
IdentityService is = new IdentityService (CLIENT_ID, BASE_URL);
Authenticate
is.tryAuthenticate(MainActivity.this);
// Use handler to check when authentication is completed
final Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
if (is.isAuthenticated()) {
// If authenticated stop the handler callbacks
h.removeCallbacks(this);
// Continue
}else {
// If not check again in 5 seconds
h.postDelayed(this, 5 * 1000);
}
}
}, 5*1000);
Getting Profile Information
Profile profile = is.getProfile();
Getting information on the current user's accounts
ArrayList<AccountProvider> accountProviders = is.getAccounts();
Getting information on the current user's roles
ArrayList<Role> roles = is.getRoles();