com.microsoft.aad.adal
Class AuthenticationContext

java.lang.Object
  extended by com.microsoft.aad.adal.AuthenticationContext

public class AuthenticationContext
extends Object

ADAL context to get access token, refresh token, and lookup from cache.


Constructor Summary
AuthenticationContext(android.content.Context appContext, String authority, boolean validateAuthority)
          Constructs context to use with known authority to get the token.
AuthenticationContext(android.content.Context appContext, String authority, boolean validateAuthority, ITokenCacheStore tokenCacheStore)
          Constructs context to use with known authority to get the token.
AuthenticationContext(android.content.Context appContext, String authority, ITokenCacheStore tokenCacheStore)
          It will verify the authority and use the given cache.
 
Method Summary
 void acquireToken(android.app.Activity activity, String resource, String clientId, String redirectUri, PromptBehavior prompt, AuthenticationCallback<AuthenticationResult> callback)
          acquire Token will start interactive flow if needed.
 void acquireToken(android.app.Activity activity, String resource, String clientId, String redirectUri, PromptBehavior prompt, String extraQueryParameters, AuthenticationCallback<AuthenticationResult> callback)
          acquire Token will start interactive flow if needed.
 void acquireToken(android.app.Activity activity, String resource, String clientId, String redirectUri, String loginHint, AuthenticationCallback<AuthenticationResult> callback)
          acquire Token will start interactive flow if needed.
 void acquireToken(android.app.Activity activity, String resource, String clientId, String redirectUri, String loginHint, PromptBehavior prompt, String extraQueryParameters, AuthenticationCallback<AuthenticationResult> callback)
          acquire Token will start interactive flow if needed.
 void acquireToken(android.app.Activity activity, String resource, String clientId, String redirectUri, String loginHint, String extraQueryParameters, AuthenticationCallback<AuthenticationResult> callback)
          acquire Token will start interactive flow if needed.
 void acquireToken(IWindowComponent fragment, String resource, String clientId, String redirectUri, String loginHint, PromptBehavior prompt, String extraQueryParameters, AuthenticationCallback<AuthenticationResult> callback)
          It will start interactive flow if needed.
 void acquireToken(String resource, String clientId, String redirectUri, String loginHint, PromptBehavior prompt, String extraQueryParameters, AuthenticationCallback<AuthenticationResult> callback)
          This uses new dialog based prompt.
 void acquireTokenByRefreshToken(String refreshToken, String clientId, AuthenticationCallback<AuthenticationResult> callback)
          acquire token using refresh token if cache is not used.
 void acquireTokenByRefreshToken(String refreshToken, String clientId, String resource, AuthenticationCallback<AuthenticationResult> callback)
          acquire token using refresh token if cache is not used.
 Future<AuthenticationResult> acquireTokenSilent(String resource, String clientId, String userId, AuthenticationCallback<AuthenticationResult> callback)
          The function will first look at the cache and automatically checks for the token expiration.
 AuthenticationResult acquireTokenSilentSync(String resource, String clientId, String userId)
          This is sync function.
 boolean cancelAuthenticationActivity(int requestId)
          Active authentication activity can be cancelled if it exists.
 String getAuthority()
          Gets authority that is used for this object of AuthenticationContext.
 String getBrokerUser()
          Gets username for current broker user.
 UserInfo[] getBrokerUsers()
           
 ITokenCacheStore getCache()
          Returns referenced cache.
 String getRedirectUriForBroker()
          Get expected redirect Uri for your app to use in broker.
 UUID getRequestCorrelationId()
          Get the CorrelationId set by user.
 boolean getValidateAuthority()
           
static String getVersionName()
          Version name for ADAL not for the app itself.
protected  boolean isRefreshable(AuthenticationResult cachedItem)
           
 void onActivityResult(int requestCode, int resultCode, android.content.Intent data)
          This method wraps the implementation for onActivityResult at the related Activity class.
 void setRequestCorrelationId(UUID requestCorrelationId)
          set CorrelationId to requests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AuthenticationContext

public AuthenticationContext(android.content.Context appContext,
                             String authority,
                             boolean validateAuthority)
                      throws NoSuchAlgorithmException,
                             NoSuchPaddingException
Constructs context to use with known authority to get the token. It uses default cache that stores encrypted tokens.

Parameters:
appContext - It needs to have handle to the Context to use the SharedPreferences as a Default cache storage. It does not need to be activity.
authority - Authority url to send code and token requests
validateAuthority - validate authority before sending token request
Throws:
NoSuchPaddingException - Algorithm padding does not exist in the device
NoSuchAlgorithmException - Encryption Algorithm does not exist in the device. Please see the log record for details.

AuthenticationContext

public AuthenticationContext(android.content.Context appContext,
                             String authority,
                             boolean validateAuthority,
                             ITokenCacheStore tokenCacheStore)
Constructs context to use with known authority to get the token. It uses provided cache.

Parameters:
appContext - Context
authority - Authority Url
validateAuthority - true/false for validation
tokenCacheStore - Set to null if you don't want cache.

AuthenticationContext

public AuthenticationContext(android.content.Context appContext,
                             String authority,
                             ITokenCacheStore tokenCacheStore)
It will verify the authority and use the given cache. If cache is null, it will not use cache.

Parameters:
appContext - Context
authority - Authority Url
tokenCacheStore - Cache ITokenCacheStore used to store tokens. Set to null if you don't want cache.
Method Detail

getCache

public ITokenCacheStore getCache()
Returns referenced cache. You can use default cache, which uses SharedPreferences and handles synchronization by itself.

Returns:
ITokenCacheStore Current cache used

getAuthority

public String getAuthority()
Gets authority that is used for this object of AuthenticationContext.

Returns:
Authority

getValidateAuthority

public boolean getValidateAuthority()
Returns:
True when authority is valid

getBrokerUser

public String getBrokerUser()
Gets username for current broker user.

Returns:
Username

getBrokerUsers

public UserInfo[] getBrokerUsers()
                          throws android.accounts.OperationCanceledException,
                                 android.accounts.AuthenticatorException,
                                 IOException
Throws:
android.accounts.OperationCanceledException
android.accounts.AuthenticatorException
IOException

getRedirectUriForBroker

public String getRedirectUriForBroker()
Get expected redirect Uri for your app to use in broker. You need to register this redirectUri in order to get token from Broker.

Returns:
RedirectUri string to use for broker requests.

acquireToken

public void acquireToken(android.app.Activity activity,
                         String resource,
                         String clientId,
                         String redirectUri,
                         String loginHint,
                         AuthenticationCallback<AuthenticationResult> callback)
acquire Token will start interactive flow if needed. It checks the cache to return existing result if not expired. It tries to use refresh token if available. If it fails to get token with refresh token, it will remove this refresh token from cache and start authentication.

Parameters:
activity - required to launch authentication activity.
resource - required resource identifier.
clientId - required client identifier
redirectUri - Optional. It will use package name info if not provided.
loginHint - Optional login hint
callback - required

acquireToken

public void acquireToken(android.app.Activity activity,
                         String resource,
                         String clientId,
                         String redirectUri,
                         String loginHint,
                         String extraQueryParameters,
                         AuthenticationCallback<AuthenticationResult> callback)
acquire Token will start interactive flow if needed. It checks the cache to return existing result if not expired. It tries to use the refresh token if available. If it fails to get token with refresh token, it will remove this refresh token from cache and fall back on the UI.

Parameters:
activity - Calling activity
resource - required resource identifier.
clientId - required client identifier
redirectUri - Optional. It will use packagename and provided suffix for this.
loginHint - Optional. This parameter will be used to pre-populate the username field in the authentication form. Please note that the end user can still edit the username field and authenticate as a different user. This parameter can be null.
extraQueryParameters - Optional. This parameter will be appended as is to the query string in the HTTP authentication request to the authority. The parameter can be null.
callback - required AuthenticationCallback object for async call.

acquireToken

public void acquireToken(android.app.Activity activity,
                         String resource,
                         String clientId,
                         String redirectUri,
                         PromptBehavior prompt,
                         AuthenticationCallback<AuthenticationResult> callback)
acquire Token will start interactive flow if needed. It checks the cache to return existing result if not expired. It tries to use refresh token if available. If it fails to get token with refresh token, behavior will depend on options. If PromptBehavior is AUTO, it will remove this refresh token from cache and fall back on the UI. Default is AUTO. if PromptBehavior is Always, it will display prompt screen.

Parameters:
activity - Calling activity
resource - required resource identifier.
clientId - required client identifier.
redirectUri - Optional. It will use packagename and provided suffix for this.
prompt - Optional. PromptBehavior added as query parameter to authorization url
callback - required AuthenticationCallback object for async call.

acquireToken

public void acquireToken(android.app.Activity activity,
                         String resource,
                         String clientId,
                         String redirectUri,
                         PromptBehavior prompt,
                         String extraQueryParameters,
                         AuthenticationCallback<AuthenticationResult> callback)
acquire Token will start interactive flow if needed. It checks the cache to return existing result if not expired. It tries to use refresh token if available. If it fails to get token with refresh token, behavior will depend on options. If promptbehavior is AUTO, it will remove this refresh token from cache and fall back on the UI if activitycontext is not null. Default is AUTO.

Parameters:
activity - Calling activity
resource - required resource identifier.
clientId - required client identifier.
redirectUri - Optional. It will use packagename and provided suffix for this.
prompt - Optional. added as query parameter to authorization url
extraQueryParameters - Optional. added to authorization url
callback - required AuthenticationCallback object for async call.

acquireToken

public void acquireToken(android.app.Activity activity,
                         String resource,
                         String clientId,
                         String redirectUri,
                         String loginHint,
                         PromptBehavior prompt,
                         String extraQueryParameters,
                         AuthenticationCallback<AuthenticationResult> callback)
acquire Token will start interactive flow if needed. It checks the cache to return existing result if not expired. It tries to use refresh token if available. If it fails to get token with refresh token, behavior will depend on options. If promptbehavior is AUTO, it will remove this refresh token from cache and fall back on the UI if activitycontext is not null. Default is AUTO.

Parameters:
activity - Calling activity
resource - required resource identifier.
clientId - required client identifier.
redirectUri - Optional. It will use packagename and provided suffix for this.
loginHint - Optional. It is used for cache and as a loginhint at authentication.
prompt - Optional. added as query parameter to authorization url
extraQueryParameters - Optional. added to authorization url
callback - required AuthenticationCallback object for async call.

acquireToken

public void acquireToken(IWindowComponent fragment,
                         String resource,
                         String clientId,
                         String redirectUri,
                         String loginHint,
                         PromptBehavior prompt,
                         String extraQueryParameters,
                         AuthenticationCallback<AuthenticationResult> callback)
It will start interactive flow if needed. It checks the cache to return existing result if not expired. It tries to use refresh token if available. If it fails to get token with refresh token, behavior will depend on options. If promptbehavior is AUTO, it will remove this refresh token from cache and fall back on the UI. Default is AUTO.

Parameters:
fragment - It accepts both type of fragments.
resource - required resource identifier.
clientId - required client identifier.
redirectUri - Optional. It will use packagename and provided suffix for this.
loginHint - Optional. It is used for cache and as a loginhint at authentication.
prompt - Optional. added as query parameter to authorization url
extraQueryParameters - Optional. added to authorization url
callback - required AuthenticationCallback object for async call.

acquireToken

public void acquireToken(String resource,
                         String clientId,
                         String redirectUri,
                         String loginHint,
                         PromptBehavior prompt,
                         String extraQueryParameters,
                         AuthenticationCallback<AuthenticationResult> callback)
This uses new dialog based prompt. It will create a handler to run the dialog related code. It will start interactive flow if needed. It checks the cache to return existing result if not expired. It tries to use refresh token if available. If it fails to get token with refresh token, behavior will depend on options. If promptbehavior is AUTO, it will remove this refresh token from cache and fall back on the UI. Default is AUTO.

Parameters:
resource - required resource identifier.
clientId - required client identifier.
redirectUri - Optional. It will use packagename and provided suffix for this.
loginHint - Optional. It is used for cache and as a loginhint at authentication.
prompt - Optional. added as query parameter to authorization url
extraQueryParameters - Optional. added to authorization url
callback - required AuthenticationCallback object for async call.

acquireTokenSilentSync

public AuthenticationResult acquireTokenSilentSync(String resource,
                                                   String clientId,
                                                   String userId)
This is sync function. It will first look at the cache and automatically checks for the token expiration. Additionally, if no suitable access token is found in the cache, but refresh token is available, the function will use the refresh token automatically. This method will not show UI for the user. If prompt is needed, the method will return an exception

Parameters:
resource - required resource identifier.
clientId - required client identifier.
userId - UserID obtained from #getUserInfo()
Returns:
A Future object representing the AuthenticationResult of the call. It contains Access Token,the Access Token's expiration time, Refresh token, and UserInfo.

acquireTokenSilent

public Future<AuthenticationResult> acquireTokenSilent(String resource,
                                                       String clientId,
                                                       String userId,
                                                       AuthenticationCallback<AuthenticationResult> callback)
The function will first look at the cache and automatically checks for the token expiration. Additionally, if no suitable access token is found in the cache, but refresh token is available, the function will use the refresh token automatically. This method will not show UI for the user. If prompt is needed, the method will return an exception

Parameters:
resource - required resource identifier.
clientId - required client identifier.
userId - UserId obtained from UserInfo inside AuthenticationResult
callback - required AuthenticationCallback object for async call.
Returns:
A Future object representing the AuthenticationResult of the call. It contains Access Token,the Access Token's expiration time, Refresh token, and UserInfo.

acquireTokenByRefreshToken

public void acquireTokenByRefreshToken(String refreshToken,
                                       String clientId,
                                       AuthenticationCallback<AuthenticationResult> callback)
acquire token using refresh token if cache is not used. Otherwise, use acquireToken to let the ADAL handle the cache lookup and refresh token request.

Parameters:
refreshToken - Required.
clientId - Required.
callback - Required

acquireTokenByRefreshToken

public void acquireTokenByRefreshToken(String refreshToken,
                                       String clientId,
                                       String resource,
                                       AuthenticationCallback<AuthenticationResult> callback)
acquire token using refresh token if cache is not used. Otherwise, use acquireToken to let the ADAL handle the cache lookup and refresh token request.

Parameters:
refreshToken - Required.
clientId - Required.
resource - Required resource identifier.
callback - Required

onActivityResult

public void onActivityResult(int requestCode,
                             int resultCode,
                             android.content.Intent data)
This method wraps the implementation for onActivityResult at the related Activity class. This method is called at UI thread.

Parameters:
requestCode - Request code provided at the start of the activity.
resultCode - Result code set from the activity.
data - Intent

cancelAuthenticationActivity

public boolean cancelAuthenticationActivity(int requestId)
Active authentication activity can be cancelled if it exists. It may not be cancelled if activity is not launched yet. RequestId is the hashcode of your AuthenticationCallback.

Parameters:
requestId - Hash code value of your callback to cancel activity launch
Returns:
true: if there is a valid waiting request and cancel message send successfully. false: Request does not exist or cancel message not send

isRefreshable

protected boolean isRefreshable(AuthenticationResult cachedItem)

getRequestCorrelationId

public UUID getRequestCorrelationId()
Get the CorrelationId set by user.

Returns:
UUID

setRequestCorrelationId

public void setRequestCorrelationId(UUID requestCorrelationId)
set CorrelationId to requests.

Parameters:
mRequestCorrelationId -

getVersionName

public static String getVersionName()
Version name for ADAL not for the app itself.

Returns:
Version


Copyright © 2003–2015. All rights reserved.