-
Notifications
You must be signed in to change notification settings - Fork 108
ADAL Basics
Shane Oatman edited this page Jul 13, 2018
·
18 revisions
In the build.gradle,
repositories {
mavenCentral()
}
dependencies {
// your dependencies here...
implementation('com.microsoft.aad:adal:1.14.+') {
// if your app includes android support libraries or Gson in its dependencies
// exclude that groupId from ADAL's compile task by un-commenting the appropriate line below
// exclude group: 'com.android.support'
// exclude group: 'com.google.code.gson'
}
}
In AndroidManifest.XML,
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
....
<activity
android:name="com.microsoft.aad.adal.AuthenticationActivity"
android:label="@string/title_login_hello_app" >
</activity>
....
<application/>
mAuthContext = new AuthenticationContext(getApplicationContext(), AUTHORITY_URL,false);
More information about the usage can be found at AuthenticationContext Wiki
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mAuthContext.onActivityResult(requestCode, resultCode, data);
}
ADAL will manage all the token refresh and caching. To get the token you can call either of the methods below
-
acquireToken
- Attempts to invoke an UI prompt with the user if needed to acquire tokens.The method can accessed like below:mAuthContext.acquireToken(MainActivity.this, RESOURCE_ID, CLIENT_ID, REDIRECT_URI, PromptBehavior.Auto, getAuthCallback());
More information about the usage can be found at acquireToken Wiki
-
acquireTokenSilentSync
- Acquires token from the cache without an UI prompt synchronously.The method can accessed like below:mAuthContext.acquireTokenSilentSync(RESOURCE_ID, CLIENT_ID, userId);
-
acquireTokenSilentASync
- Acquires token from the cache without an UI prompt asynchronously.The method can accessed like below:mAuthContext.acquireTokenSilentAsync(RESOURCE_ID, CLIENT_ID, userId, getAuthCallback());
More information about the usage can be found at acquireTokenSilent(...) Wiki
- Error Handling
- Auth Telemetry
- Logging
- Doze and App Standby
- ProGuard
- Session Cookies in WebView
- Resource Overrides