Class TokenProvider

java.lang.Object
com.microsoft.azure.relay.TokenProvider
Direct Known Subclasses:
SharedAccessSignatureTokenProvider

public abstract class TokenProvider extends Object
  • Constructor Details

    • TokenProvider

      protected TokenProvider()
      Initializes a new instance of the TokenProvider class.
  • Method Details

    • createSharedAccessSignatureTokenProvider

      public static TokenProvider createSharedAccessSignatureTokenProvider(String sharedAccessSignature)
      Construct a TokenProvider based on the provided Key Name and Shared Access Key.
      Parameters:
      sharedAccessSignature - The signature associated with the SharedAccessKeyAuthorizationRule
      Returns:
      A TokenProvider initialized with the provided RuleId and Password
    • createSharedAccessSignatureTokenProvider

      public static TokenProvider createSharedAccessSignatureTokenProvider(String keyName, String sharedAccessKey)
      Construct a TokenProvider based on the provided Key Name and Shared Access Key.
      Parameters:
      keyName - The key name of the corresponding SharedAccessKeyAuthorizationRule.
      sharedAccessKey - The key associated with the SharedAccessKeyAuthorizationRule
      Returns:
      A TokenProvider instance used for authentication
    • createAzureIdentityTokenProvider

      public static TokenProvider createAzureIdentityTokenProvider(com.azure.core.credential.TokenCredential tokenCredential)
      Construct a TokenProvider with a provided TokenCredential. For options or examples, please see here.
      Parameters:
      tokenCredential - The token credential which will be used to obtain a token.
      Returns:
      A TokenProvider instance used for authentication
    • getTokenAsync

      public CompletableFuture<SecurityToken> getTokenAsync(String urlString, Duration validFor)
      Gets a SecurityToken for the given audience and duration
      Parameters:
      urlString - The target audience for the security token
      validFor - How long the generated token should be valid for
      Returns:
      Returns a CompletableFuture of the SecutiryToken that completes once generated
    • onGetTokenAsync

      protected abstract CompletableFuture<SecurityToken> onGetTokenAsync(String urlString, Duration validFor)
      Implemented by derived TokenProvider types to generate their SecurityTokens.
      Parameters:
      urlString - The target audience for the security token
      validFor - How long the generated token should be valid for
      Returns:
      Returns a CompletableFuture of the SecutiryToken that completes once generated