AccessToken Class
- java.
lang. Object - com.
azure. core. credential. AccessToken
- com.
public class AccessToken
Represents an immutable access token with a token string and an expiration time.
An Access Token is a security token that is issued by an authentication source, such as Azure Active Directory (AAD), and it represents the authorization to access a specific resource or service. It is typically used to authenticate and authorize requests made to Azure services.
Access Tokens are obtained through the authentication process, where the user or application presents valid credentials (such as a client ID, client secret, username/password, or certificate) to the authentication source. The authentication source then verifies the credentials and issues an Access Token, which is a time-limited token that grants access to the requested resource.
Once an Access Token is obtained, it can be included in the Authorization header of HTTP requests to authenticate and authorize requests to Azure services.
Constructor Summary
Constructor | Description |
---|---|
AccessToken(String token, OffsetDateTime expiresAt) |
Creates an access token instance. |
AccessToken(String token, OffsetDateTime expiresAt, OffsetDateTime refreshAt) |
Creates an access token instance. |
AccessToken(String token, OffsetDateTime expiresAt, OffsetDateTime refreshAt, String tokenType) |
Creates an access token instance. |
Method Summary
Modifier and Type | Method and Description |
---|---|
Duration |
getDurationUntilExpiration()
Gets the Duration until the AccessToken expires. |
Offset |
getExpiresAt()
Gets the time when the token expires, in UTC. |
Offset |
getRefreshAt()
Gets the time when the token should refresh next, in UTC. |
String |
getToken()
Gets the token. |
String |
getTokenType()
Gets the token type. |
boolean |
isExpired()
Whether the token has expired. |
Methods inherited from java.lang.Object
Constructor Details
AccessToken
public AccessToken(String token, OffsetDateTime expiresAt)
Creates an access token instance.
Parameters:
AccessToken
public AccessToken(String token, OffsetDateTime expiresAt, OffsetDateTime refreshAt)
Creates an access token instance.
Parameters:
AccessToken
public AccessToken(String token, OffsetDateTime expiresAt, OffsetDateTime refreshAt, String tokenType)
Creates an access token instance.
Parameters:
Method Details
getDurationUntilExpiration
public Duration getDurationUntilExpiration()
Gets the Duration until the AccessToken expires.
The Duration is based on the current time and may return a negative Duration, indicating that the AccessToken has expired.
Returns:
getExpiresAt
public OffsetDateTime getExpiresAt()
Gets the time when the token expires, in UTC.
Returns:
getRefreshAt
public OffsetDateTime getRefreshAt()
Gets the time when the token should refresh next, in UTC.
Note: This value can be null as it is not always provided by the service. When it is provided, it overrides the default refresh offset used by the BearerTokenAuthenticationPolicy to proactively refresh the token.
Returns:
getToken
public String getToken()
Gets the token.
Returns:
getTokenType
public String getTokenType()
Gets the token type.
Returns:
isExpired
public boolean isExpired()
Whether the token has expired.
Returns: