public class AuthenticationContext
extends java.lang.Object
Constructor and Description |
---|
AuthenticationContext(android.content.Context appContext,
java.lang.String authority,
boolean validateAuthority)
Constructs context to use with known authority to get the token.
|
AuthenticationContext(android.content.Context appContext,
java.lang.String authority,
boolean validateAuthority,
ITokenCacheStore tokenCacheStore)
Constructs context to use with known authority to get the token.
|
AuthenticationContext(android.content.Context appContext,
java.lang.String authority,
ITokenCacheStore tokenCacheStore)
It will verify the authority and use the given cache.
|
Modifier and Type | Method and Description |
---|---|
void |
acquireToken(android.app.Activity activity,
java.lang.String resource,
java.lang.String clientId,
java.lang.String redirectUri,
PromptBehavior prompt,
AuthenticationCallback<AuthenticationResult> callback)
acquireToken will start interactive flow if needed.
|
void |
acquireToken(android.app.Activity activity,
java.lang.String resource,
java.lang.String clientId,
java.lang.String redirectUri,
PromptBehavior prompt,
java.lang.String extraQueryParameters,
AuthenticationCallback<AuthenticationResult> callback)
acquireToken will start interactive flow if needed.
|
void |
acquireToken(android.app.Activity activity,
java.lang.String resource,
java.lang.String clientId,
java.lang.String redirectUri,
java.lang.String loginHint,
AuthenticationCallback<AuthenticationResult> callback)
acquireToken will start interactive flow if needed.
|
void |
acquireToken(android.app.Activity activity,
java.lang.String resource,
java.lang.String clientId,
java.lang.String redirectUri,
java.lang.String loginHint,
PromptBehavior prompt,
java.lang.String extraQueryParameters,
AuthenticationCallback<AuthenticationResult> callback)
acquireToken will start interactive flow if needed.
|
void |
acquireToken(android.app.Activity activity,
java.lang.String resource,
java.lang.String clientId,
java.lang.String redirectUri,
java.lang.String loginHint,
PromptBehavior prompt,
java.lang.String extraQueryParameters,
java.lang.String claims,
AuthenticationCallback<AuthenticationResult> callback)
acquireToken will start an interactive auth flow to acquire new tokens
with the requested claims.
|
void |
acquireToken(android.app.Activity activity,
java.lang.String resource,
java.lang.String clientId,
java.lang.String redirectUri,
java.lang.String loginHint,
java.lang.String extraQueryParameters,
AuthenticationCallback<AuthenticationResult> callback)
acquireToken will start interactive flow if needed.
|
void |
acquireToken(IWindowComponent fragment,
java.lang.String resource,
java.lang.String clientId,
java.lang.String redirectUri,
java.lang.String loginHint,
PromptBehavior prompt,
java.lang.String extraQueryParameters,
AuthenticationCallback<AuthenticationResult> callback)
It will start interactive flow if needed.
|
void |
acquireToken(IWindowComponent fragment,
java.lang.String resource,
java.lang.String clientId,
java.lang.String redirectUri,
java.lang.String loginHint,
PromptBehavior prompt,
java.lang.String extraQueryParameters,
java.lang.String claims,
AuthenticationCallback<AuthenticationResult> callback)
acquireToken will start an interactive auth flow to acquire new tokens
with the requested claims.
|
void |
acquireToken(java.lang.String resource,
java.lang.String clientId,
java.lang.String redirectUri,
java.lang.String loginHint,
PromptBehavior prompt,
java.lang.String extraQueryParameters,
AuthenticationCallback<AuthenticationResult> callback)
acquireToken will authorize an end user to call the specified resource.
|
void |
acquireToken(java.lang.String resource,
java.lang.String clientId,
java.lang.String redirectUri,
java.lang.String loginHint,
PromptBehavior prompt,
java.lang.String extraQueryParameters,
java.lang.String claims,
AuthenticationCallback<AuthenticationResult> callback)
acquireToken will authorize an end user to call the specified resource.
|
void |
acquireTokenByRefreshToken(java.lang.String refreshToken,
java.lang.String clientId,
AuthenticationCallback<AuthenticationResult> callback)
Deprecated.
acquireTokenByRefreshToken(String, String, AuthenticationCallback)
will be removed from the next major release. We don't recommend developers taking dependency on refresh token,
ADAL will handle the cache lookup, and refresh the RT if necessary. |
void |
acquireTokenByRefreshToken(java.lang.String refreshToken,
java.lang.String clientId,
java.lang.String resource,
AuthenticationCallback<AuthenticationResult> callback)
Deprecated.
acquireTokenByRefreshToken(String, String, AuthenticationCallback)
will be removed from the next major release. We don't recommend developers taking dependency on refresh token,
ADAL will handle the cache lookup, and refresh the RT if necessary. |
java.util.concurrent.Future<AuthenticationResult> |
acquireTokenSilent(java.lang.String resource,
java.lang.String clientId,
java.lang.String userId,
AuthenticationCallback<AuthenticationResult> callback)
|
void |
acquireTokenSilentAsync(java.lang.String resource,
java.lang.String clientId,
java.lang.String userId,
AuthenticationCallback<AuthenticationResult> callback)
The function will first look at the cache and automatically checks for
the token expiration.
|
void |
acquireTokenSilentAsync(java.lang.String resource,
java.lang.String clientId,
java.lang.String userId,
boolean forceRefresh,
AuthenticationCallback<AuthenticationResult> callback)
The function will first look at the cache and automatically checks for
the token expiration.
|
void |
acquireTokenSilentAsync(java.lang.String resource,
java.lang.String clientId,
java.lang.String userId,
java.lang.String claims,
AuthenticationCallback<AuthenticationResult> callback)
The function will first look at the cache and automatically checks for
the token expiration.
|
AuthenticationResult |
acquireTokenSilentSync(java.lang.String resource,
java.lang.String clientId,
java.lang.String userId)
This is sync function.
|
AuthenticationResult |
acquireTokenSilentSync(java.lang.String resource,
java.lang.String clientId,
java.lang.String userId,
boolean forceRefresh)
This is sync function.
|
AuthenticationResult |
acquireTokenSilentSync(java.lang.String resource,
java.lang.String clientId,
java.lang.String userId,
java.lang.String claims)
This is sync function.
|
boolean |
cancelAuthenticationActivity(int requestId)
Active authentication activity can be cancelled if it exists.
|
java.lang.String |
getAuthority()
Gets authority that is used for this object of AuthenticationContext.
|
java.lang.String |
getBrokerUser()
Gets username for current broker user.
|
UserInfo[] |
getBrokerUsers()
Gets user info from broker.
|
ITokenCacheStore |
getCache()
Returns referenced cache.
|
java.util.List<java.lang.String> |
getClientCapabilites() |
boolean |
getExtendedLifetimeEnabled()
Gets if the ExtendedLifetime mode is enabled.
|
java.lang.String |
getRedirectUriForBroker()
Get expected redirect Uri for your app to use in broker.
|
java.util.UUID |
getRequestCorrelationId()
Get the CorrelationId set by user.
|
boolean |
getValidateAuthority() |
static java.lang.String |
getVersionName()
Version name for ADAL not for the app itself.
|
static java.lang.String |
mergeClaimsWithClientCapabilities(java.lang.String claims,
java.util.List<java.lang.String> clientCapabilities)
Util method to merge
|
void |
onActivityResult(int requestCode,
int resultCode,
android.content.Intent data)
This method wraps the implementation for onActivityResult at the related
Activity class.
|
void |
setClientCapabilites(java.util.List<java.lang.String> clientCapabilites) |
void |
setExtendedLifetimeEnabled(boolean extendedLifetimeEnabled)
The client need to set the flag to true explicitly to enable the ExtendedLifetime mode
The default value of flag is false.
|
void |
setRequestCorrelationId(java.util.UUID requestCorrelationId)
Set CorrelationId to requests.
|
public AuthenticationContext(android.content.Context appContext, java.lang.String authority, boolean validateAuthority)
appContext
- It needs to have handle to the Context
to use
the SharedPreferencesFileManager as a Default cache storage. It does not
need to be activity.authority
- Authority url to send code and token requestsvalidateAuthority
- validate authority before sending token requestpublic AuthenticationContext(android.content.Context appContext, java.lang.String authority, boolean validateAuthority, ITokenCacheStore tokenCacheStore)
appContext
- Context
authority
- Authority UrlvalidateAuthority
- true/false for validationtokenCacheStore
- Set to null if you don't want cache.public AuthenticationContext(android.content.Context appContext, java.lang.String authority, ITokenCacheStore tokenCacheStore)
appContext
- Context
authority
- Authority UrltokenCacheStore
- Cache ITokenCacheStore
used to store
tokens. Set to null if you don't want cache.public ITokenCacheStore getCache()
public boolean getExtendedLifetimeEnabled()
public void setExtendedLifetimeEnabled(boolean extendedLifetimeEnabled)
extendedLifetimeEnabled
- true if the ExtendedLifetime mode is on, false otherwisepublic java.lang.String getAuthority()
public boolean getValidateAuthority()
public java.lang.String getBrokerUser()
public UserInfo[] getBrokerUsers() throws android.accounts.OperationCanceledException, android.accounts.AuthenticatorException, java.io.IOException
UserInfo
that haven been authenticated via broker(can be null).java.io.IOException
- if the broker returned an error response that indicates that it encountered an IOException
while communicating with the authentication server.android.accounts.AuthenticatorException
- if there was an error communicating with the authenticator or if the
authenticator returned an invalid response.android.accounts.OperationCanceledException
- if the request was canceled for any reason.public java.lang.String getRedirectUriForBroker()
public void acquireToken(android.app.Activity activity, java.lang.String resource, java.lang.String clientId, @Nullable java.lang.String redirectUri, @Nullable java.lang.String loginHint, AuthenticationCallback<AuthenticationResult> callback)
activity
- required to launch authentication activity.resource
- required resource identifier.clientId
- required client identifierredirectUri
- Optional. It will use package name info if not
provided.loginHint
- login hint (optional if validateAuthority == false)callback
- requiredpublic void acquireToken(android.app.Activity activity, java.lang.String resource, java.lang.String clientId, @Nullable java.lang.String redirectUri, @Nullable java.lang.String loginHint, @Nullable java.lang.String extraQueryParameters, AuthenticationCallback<AuthenticationResult> callback)
activity
- Calling activityresource
- required resource identifier.clientId
- required client identifierredirectUri
- Optional. It will use packagename and provided suffix
for this.loginHint
- Optional if validateAuthority == null. 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.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.public void acquireToken(android.app.Activity activity, java.lang.String resource, java.lang.String clientId, @Nullable java.lang.String redirectUri, @Nullable PromptBehavior prompt, AuthenticationCallback<AuthenticationResult> callback)
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.activity
- Calling activityresource
- 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 urlcallback
- required AuthenticationCallback
object for async
call.public void acquireToken(android.app.Activity activity, java.lang.String resource, java.lang.String clientId, @Nullable java.lang.String redirectUri, @Nullable PromptBehavior prompt, @Nullable java.lang.String extraQueryParameters, AuthenticationCallback<AuthenticationResult> callback)
activity
- Calling activityresource
- 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 urlextraQueryParameters
- Optional. added to authorization urlcallback
- required AuthenticationCallback
object for async
call.public void acquireToken(android.app.Activity activity, java.lang.String resource, java.lang.String clientId, @Nullable java.lang.String redirectUri, @Nullable java.lang.String loginHint, @Nullable PromptBehavior prompt, @Nullable java.lang.String extraQueryParameters, AuthenticationCallback<AuthenticationResult> callback)
activity
- Calling activityresource
- required resource identifier.clientId
- required client identifier.redirectUri
- Optional. It will use packagename and provided suffix
for this.loginHint
- Optional if validateAuthority == null. It is used for cache and as a loginhint at
authentication.prompt
- Optional. added as query parameter to authorization urlextraQueryParameters
- Optional. added to authorization urlcallback
- required AuthenticationCallback
object for async
call.public void acquireToken(android.app.Activity activity, java.lang.String resource, java.lang.String clientId, @Nullable java.lang.String redirectUri, @Nullable java.lang.String loginHint, @Nullable PromptBehavior prompt, @Nullable java.lang.String extraQueryParameters, @Nullable java.lang.String claims, AuthenticationCallback<AuthenticationResult> callback)
activity
- Calling activityresource
- required resource identifier.clientId
- required client identifier.redirectUri
- Optional. It will use packagename and provided suffix
for this.loginHint
- Optional if validateAuthority == null. It is used for cache and as a loginhint at
authentication.prompt
- Optional. added as query parameter to authorization urlextraQueryParameters
- Optional. added to authorization urlclaims
- Optional. The claims challenge returned from middle tier service, will be added as query string
to authorize endpoint.callback
- required AuthenticationCallback
object for async
call.public void acquireToken(IWindowComponent fragment, java.lang.String resource, java.lang.String clientId, @Nullable java.lang.String redirectUri, @Nullable java.lang.String loginHint, @Nullable PromptBehavior prompt, @Nullable java.lang.String extraQueryParameters, AuthenticationCallback<AuthenticationResult> callback)
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 if validateAuthority == null. It is used for cache and as a loginhint at
authentication.prompt
- Optional. added as query parameter to authorization urlextraQueryParameters
- Optional. added to authorization urlcallback
- required AuthenticationCallback
object for async
call.public void acquireToken(IWindowComponent fragment, java.lang.String resource, java.lang.String clientId, @Nullable java.lang.String redirectUri, @Nullable java.lang.String loginHint, @Nullable PromptBehavior prompt, @Nullable java.lang.String extraQueryParameters, @Nullable java.lang.String claims, AuthenticationCallback<AuthenticationResult> callback)
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 if validateAuthority == null. It is used for cache and as a loginhint at
authentication.prompt
- Optional. added as query parameter to authorization urlextraQueryParameters
- Optional. added to authorization urlclaims
- Optional. The claims challenge returned from middle tier service, will be added as query string
to authorize endpoint.callback
- required AuthenticationCallback
object for async
call.public void acquireToken(java.lang.String resource, java.lang.String clientId, @Nullable java.lang.String redirectUri, @Nullable java.lang.String loginHint, @Nullable PromptBehavior prompt, @Nullable java.lang.String extraQueryParameters, AuthenticationCallback<AuthenticationResult> callback)
AuthenticationCallback
and can be used to call the specified protected resource.
By default, acquireToken will attempt to fulfill the request silently, and
perform an interactive login if needed or explicitly specified in
the request. This overload uses an
[AlertDialog](https://developer.android.com/guide/topics/ui/dialogs)
when user interaction is required. This overload does not support any flow
requiring a
[token broker](https://github.com/AzureAD/azure-activedirectory-library-for-android/wiki/Broker).resource
- required resource identifier.clientId
- required client identifier.redirectUri
- Optional. It will use packagename and provided suffix
for this.loginHint
- Optional if validateAuthority == null. It is used for cache and as a loginhint at
authentication.prompt
- Optional. added as query parameter to authorization urlextraQueryParameters
- Optional. added to authorization urlcallback
- required AuthenticationCallback
object for async
call.public void acquireToken(java.lang.String resource, java.lang.String clientId, @Nullable java.lang.String redirectUri, @Nullable java.lang.String loginHint, @Nullable PromptBehavior prompt, @Nullable java.lang.String extraQueryParameters, @Nullable java.lang.String claims, AuthenticationCallback<AuthenticationResult> callback)
AuthenticationCallback
and can be used to call the specified protected resource.
Bypasses token cache if @param prompt is not AUTO or claims are passed.
This overload uses an
[AlertDialog](https://developer.android.com/guide/topics/ui/dialogs)
when user interaction is required. This overload does not support any flow
requiring a
[token broker](https://github.com/AzureAD/azure-activedirectory-library-for-android/wiki/Broker).resource
- required resource identifier.clientId
- required client identifier.redirectUri
- Optional. It will use packagename and provided suffix
for this.loginHint
- Optional if validateAuthority == null. It is used for cache and as a loginhint at
authentication.prompt
- Optional. added as query parameter to authorization urlextraQueryParameters
- Optional. added to authorization urlclaims
- Optional. The claims challenge returned from middle tier service, will be added as query string
to authorize endpoint.callback
- required AuthenticationCallback
object for async
call.public AuthenticationResult acquireTokenSilentSync(java.lang.String resource, java.lang.String clientId, java.lang.String userId) throws AuthenticationException, java.lang.InterruptedException
resource
- required resource identifier.clientId
- required client identifier.userId
- UserID obtained from
#getUserInfo()
Future
object representing the
AuthenticationResult
of the call. It contains Access
Token,the Access Token's expiration time, Refresh token, and
UserInfo
.AuthenticationException
- If silent request fails to get the token back.java.lang.InterruptedException
- If the main thread is interrupted before or during the activity.public AuthenticationResult acquireTokenSilentSync(java.lang.String resource, java.lang.String clientId, java.lang.String userId, @Nullable java.lang.String claims) throws AuthenticationException, java.lang.InterruptedException
resource
- required resource identifier.clientId
- required client identifier.userId
- UserID obtained from
#getUserInfo()
claims
- Optional. The claims challenge returned from middle tier service, will be added as query string
to authorize endpoint.Future
object representing the
AuthenticationResult
of the call. It contains Access
Token,the Access Token's expiration time, Refresh token, and
UserInfo
.AuthenticationException
- If silent request fails to get the token back.java.lang.InterruptedException
- If the main thread is interrupted before or during the activity.public AuthenticationResult acquireTokenSilentSync(java.lang.String resource, java.lang.String clientId, java.lang.String userId, boolean forceRefresh) throws AuthenticationException, java.lang.InterruptedException
resource
- required resource identifier.clientId
- required client identifier.userId
- UserID obtained from
#getUserInfo()
forceRefresh
- when true, access token is renewed using broker if available; otherwise, uses local refresh tokenFuture
object representing the
AuthenticationResult
of the call. It contains Access
Token,the Access Token's expiration time, Refresh token, and
UserInfo
.AuthenticationException
- If silent request fails to get the token back.java.lang.InterruptedException
- If the main thread is interrupted before or during the activity.@Deprecated public java.util.concurrent.Future<AuthenticationResult> acquireTokenSilent(java.lang.String resource, java.lang.String clientId, java.lang.String userId, AuthenticationCallback<AuthenticationResult> callback)
acquireTokenSilentAsync(java.lang.String, java.lang.String, java.lang.String, com.microsoft.aad.adal.AuthenticationCallback<com.microsoft.aad.adal.AuthenticationResult>)
method.resource
- required resource identifier.clientId
- required client identifier.userId
- UserId obtained from UserInfo
inside
AuthenticationResult
callback
- required AuthenticationCallback
object for async
call.Future
object representing the
AuthenticationResult
of the call. It contains Access
Token,the Access Token's expiration time, Refresh token, and
UserInfo
.public void acquireTokenSilentAsync(java.lang.String resource, java.lang.String clientId, java.lang.String userId, AuthenticationCallback<AuthenticationResult> callback)
resource
- required resource identifier.clientId
- required client identifier.userId
- UserId obtained from UserInfo
inside
AuthenticationResult
callback
- required AuthenticationCallback
object for async
call.public void acquireTokenSilentAsync(java.lang.String resource, java.lang.String clientId, java.lang.String userId, boolean forceRefresh, AuthenticationCallback<AuthenticationResult> callback)
resource
- required resource identifier.clientId
- required client identifier.userId
- UserId obtained from UserInfo
inside
AuthenticationResult
forceRefresh
- when true, access token is renewed using broker if available; otherwise, uses local refresh tokencallback
- required AuthenticationCallback
object for async
call.public void acquireTokenSilentAsync(java.lang.String resource, java.lang.String clientId, java.lang.String userId, @Nullable java.lang.String claims, AuthenticationCallback<AuthenticationResult> callback)
resource
- required resource identifier.clientId
- required client identifier.userId
- UserId obtained from UserInfo
inside
AuthenticationResult
claims
- Optional. The claims challenge returned from middle tier service, will be added as query string
to authorize endpoint.callback
- required AuthenticationCallback
object for async
call.@Deprecated public void acquireTokenByRefreshToken(java.lang.String refreshToken, java.lang.String clientId, AuthenticationCallback<AuthenticationResult> callback)
acquireTokenByRefreshToken(String, String, AuthenticationCallback)
will be removed from the next major release. We don't recommend developers taking dependency on refresh token,
ADAL will handle the cache lookup, and refresh the RT if necessary.refreshToken
- Required.clientId
- Required.callback
- Required@Deprecated public void acquireTokenByRefreshToken(java.lang.String refreshToken, java.lang.String clientId, java.lang.String resource, AuthenticationCallback<AuthenticationResult> callback)
acquireTokenByRefreshToken(String, String, AuthenticationCallback)
will be removed from the next major release. We don't recommend developers taking dependency on refresh token,
ADAL will handle the cache lookup, and refresh the RT if necessary.refreshToken
- Required.clientId
- Required.resource
- Required resource identifier.callback
- Requiredpublic void onActivityResult(int requestCode, int resultCode, android.content.Intent data)
requestCode
- Request code provided at the start of the activity.resultCode
- Result code set from the activity.data
- Intent
public boolean cancelAuthenticationActivity(int requestId) throws AuthenticationException
requestId
- Hash code value of your callback to cancel activity
launchAuthenticationException
- if failed to get the waiting requestpublic java.util.UUID getRequestCorrelationId()
public void setRequestCorrelationId(java.util.UUID requestCorrelationId)
requestCorrelationId
- The correlation id UUID
to be set in the request.public static java.lang.String mergeClaimsWithClientCapabilities(java.lang.String claims, java.util.List<java.lang.String> clientCapabilities)
claims
- input claims passed on acquireToken callorg.json.JSONException
- if input claims is an invalid JSON
Sample input claim :
{
"userinfo":
{
"given_name": {"essential": true},
"email": {"essential": true},
},
"id_token":
{
"auth_time": {"essential": true},
}
}
Sample capabilities list : [CP1, CP2 CP3]
Output merged claims :
{
"userinfo": {
"given_name": {
"essential": true
},
"email": {
"essential": true
}
},
"id_token": {
"auth_time": {
"essential": true
}
},
"access_token": {
"xms_cc": {
"values": ["CP1", "CP2"]
}
}
}public static java.lang.String getVersionName()
public java.util.List<java.lang.String> getClientCapabilites()
public void setClientCapabilites(java.util.List<java.lang.String> clientCapabilites)