TokenProvider Class

  • java.lang.Object
    • com.microsoft.azure.servicebus.security.TokenProvider

public class TokenProvider

This abstract class defines the contract of a token provider. All token providers should inherit from this class. An instance of token provider is used to obtain a security token for a given audience.

Method Summary

Modifier and Type Method and Description
TokenProvider createAzureActiveDirectoryTokenProvider(String authorityUrl, String clientId, String clientSecret)

Creates an Azure Active Directory token provider that acquires a token from the given active directory instance using the given clientId and client secret. This is a utility method.

TokenProvider createAzureActiveDirectoryTokenProvider(String authorityUrl, String clientId, String userName, String password)

Creates an Azure Active Directory token provider that acquires a token from the given active directory instance using the given clientId, username and password. This is a utility method.

TokenProvider createManagedServiceIdentityTokenProvider()

Creates a Managed Service Identity token provider. This is a utility method.

TokenProvider createSharedAccessSignatureTokenProvider(String sasToken, Instant sasTokenValidUntil)

Creates a Shared Access Signature token provider that always returns an already created token. This is a utility method.

TokenProvider createSharedAccessSignatureTokenProvider(String sasKeyName, String sasKey)

Creates a Shared Access Signature token provider with the given key name and key value. Returned token provider creates tokens with validity of 20 minutes. This is a utility method.

abstract CompletableFuture<SecurityToken> getSecurityTokenAsync(String audience)

Asynchronously gets a security token for the given audience. Implementations of this method may choose to create a new token for every call or return a cached token. But the token returned must be valid.

Method Details

createAzureActiveDirectoryTokenProvider

public static TokenProvider createAzureActiveDirectoryTokenProvider(String authorityUrl, String clientId, String clientSecret)

Creates an Azure Active Directory token provider that acquires a token from the given active directory instance using the given clientId and client secret. This is a utility method.

Parameters:

authorityUrl - URL of the Azure Active Directory instance
clientId - client id of the application
clientSecret - client secret of the application

Returns:

an instance of Azure Active Directory token provider

Throws:

MalformedURLException - if the authority URL is not well formed

createAzureActiveDirectoryTokenProvider

public static TokenProvider createAzureActiveDirectoryTokenProvider(String authorityUrl, String clientId, String userName, String password)

Creates an Azure Active Directory token provider that acquires a token from the given active directory instance using the given clientId, username and password. This is a utility method.

Parameters:

authorityUrl - URL of the Azure Active Directory instance
clientId - client id of the application
userName - user name
password - password

Returns:

an instance of Azure Active Directory token provider

Throws:

MalformedURLException - if the authority URL is not well formed

createManagedServiceIdentityTokenProvider

public static TokenProvider createManagedServiceIdentityTokenProvider()

Creates a Managed Service Identity token provider. This is a utility method.

Returns:

an instance of Managed Service Identity token provider

createSharedAccessSignatureTokenProvider

public static TokenProvider createSharedAccessSignatureTokenProvider(String sasToken, Instant sasTokenValidUntil)

Creates a Shared Access Signature token provider that always returns an already created token. This is a utility method.

Parameters:

sasToken - Already created Shared Access Signature token to be returned by getSecurityTokenAsync(String audience) method.
sasTokenValidUntil - Instant when the token expires

Returns:

an instance of Shared Access Signature token provider that always returns an already created token.

createSharedAccessSignatureTokenProvider

public static TokenProvider createSharedAccessSignatureTokenProvider(String sasKeyName, String sasKey)

Creates a Shared Access Signature token provider with the given key name and key value. Returned token provider creates tokens with validity of 20 minutes. This is a utility method.

Parameters:

sasKeyName - SAS key name
sasKey - SAS key value

Returns:

an instance of Shared Access Signature token provider with the given key name, key value.

getSecurityTokenAsync

public abstract CompletableFuture getSecurityTokenAsync(String audience)

Asynchronously gets a security token for the given audience. Implementations of this method may choose to create a new token for every call or return a cached token. But the token returned must be valid.

Parameters:

audience - path of the entity for which this security token is to be presented

Returns:

an instance of CompletableFuture which returns a SecurityToken on completion.

Applies to