TokenRequestContext Class

  • java.lang.Object
    • com.azure.core.credential.TokenRequestContext

public class TokenRequestContext

The TokenRequestContext is a class used to provide additional information and context when requesting an access token from an authentication source. It allows you to customize the token request and specify additional parameters, such as scopes, claims, or authentication options.

The TokenRequestContext is typically used with authentication mechanisms that require more advanced configurations or options, such as Azure Active Directory (Azure AD) authentication.

Here's a high-level overview of how you can use the TokenRequestContext:

  1. Create an instance of the TokenRequestContext class and configure the required properties. The TokenRequestContext class allows you to specify the scopes or resources for which you want to request an access token, as well as any additional claims or options.
  2. Pass the TokenRequestContext instance to the appropriate authentication client or mechanism when requesting an access token. The specific method or API to do this will depend on the authentication mechanism you are using. For example, if you are using Azure Identity for AAD authentication, you would pass the TokenRequestContext instance to the getToken method of the TokenCredential implementation.
  3. The authentication client or mechanism will handle the token request and return an access token that can be used to authenticate and authorize requests to Azure services.

Constructor Summary

Constructor Description
TokenRequestContext()

Creates a token request instance.

Method Summary

Modifier and Type Method and Description
TokenRequestContext addScopes(String[] scopes)

Adds one or more scopes to the request scopes.

String getClaims()

Get the additional claims to be included in the token.

ProofOfPossessionOptions getProofOfPossessionOptions()

Gets the proof of possession options.

List<String> getScopes()

Gets the scopes required for the token.

String getTenantId()

Get the tenant id to be used for the authentication request.

boolean isCaeEnabled()

Get the status indicating whether Continuous Access Evaluation (CAE) is enabled for the requested token.

TokenRequestContext setCaeEnabled(boolean enableCae)

Indicates whether to enable Continuous Access Evaluation (CAE) for the requested token.

TokenRequestContext setClaims(String claims)

Set the additional claims to be included in the token.

TokenRequestContext setProofOfPossessionOptions(ProofOfPossessionOptions proofOfPossessionOptions)

Sets the proof of possession options.

TokenRequestContext setScopes(List<String> scopes)

Sets the scopes required for the token.

TokenRequestContext setTenantId(String tenantId)

Set the tenant id to be used for the authentication request.

Methods inherited from java.lang.Object

Constructor Details

TokenRequestContext

public TokenRequestContext()

Creates a token request instance.

Method Details

addScopes

public TokenRequestContext addScopes(String[] scopes)

Adds one or more scopes to the request scopes.

Parameters:

scopes - one or more scopes to add

Returns:

the TokenRequestContext itself

getClaims

public String getClaims()

Get the additional claims to be included in the token.

Returns:

the additional claims to be included in the token.

getProofOfPossessionOptions

public ProofOfPossessionOptions getProofOfPossessionOptions()

Gets the proof of possession options.

Returns:

The current instance of ProofOfPossessionOptions.

getScopes

public List getScopes()

Gets the scopes required for the token.

Returns:

the scopes required for the token

getTenantId

public String getTenantId()

Get the tenant id to be used for the authentication request.

Returns:

the configured tenant id.

isCaeEnabled

public boolean isCaeEnabled()

Get the status indicating whether Continuous Access Evaluation (CAE) is enabled for the requested token.

Returns:

the flag indicating whether CAE authentication should be used or not.

setCaeEnabled

public TokenRequestContext setCaeEnabled(boolean enableCae)

Indicates whether to enable Continuous Access Evaluation (CAE) for the requested token.

If a resource API implements CAE and your application declares it can handle CAE, your app receives CAE tokens for that resource. For this reason, if you declare your app CAE ready, your application must handle the CAE claim challenge for all resource APIs that accept Microsoft Identity access tokens. If you don't handle CAE responses in these API calls, your app could end up in a loop retrying an API call with a token that is still in the returned lifespan of the token but has been revoked due to CAE.

Parameters:

enableCae - the flag indicating whether to enable Continuous Access Evaluation (CAE) for the requested token.

Returns:

the updated TokenRequestContext.

setClaims

public TokenRequestContext setClaims(String claims)

Set the additional claims to be included in the token.

Parameters:

claims - the additional claims to be included in the token.

Returns:

the updated TokenRequestContext itself

setProofOfPossessionOptions

public TokenRequestContext setProofOfPossessionOptions(ProofOfPossessionOptions proofOfPossessionOptions)

Sets the proof of possession options.

Parameters:

proofOfPossessionOptions - An instance of ProofOfPossessionOptions to be set.

Returns:

The updated instance of TokenRequestContext.

setScopes

public TokenRequestContext setScopes(List scopes)

Sets the scopes required for the token.

Parameters:

scopes - the scopes required for the token

Returns:

the TokenRequestContext itself

setTenantId

public TokenRequestContext setTenantId(String tenantId)

Set the tenant id to be used for the authentication request.

Parameters:

tenantId - the tenant to be used when requesting the token.

Returns:

the updated TokenRequestContext itself

Applies to