Class TokenCredential


  • public class TokenCredential
    extends Object
    A public credential representing an access token. Example is a Google access token you get when authenticating against Google's Open ID Connect.
    • Method Detail

      • create

        public static TokenCredential create​(String token,
                                             String issuer,
                                             Instant issueTime,
                                             Instant expTime)
        Creates a new token credential for the specified token.
        Parameters:
        token - Token value (as received from external client)
        issuer - Issuer of the token (such as accounts.google.com) - optional
        issueTime - Time instant the token was issued - optional
        expTime - Time instant the token will expire - optional
        Returns:
        new instance of credential
      • builder

        public static TokenCredential.Builder builder()
        Get a builder for this class.
        Returns:
        a new builder to build an instance
      • token

        public String token()
        The full token string as it was received from token service.
        Returns:
        token data as a string
      • getIssueTime

        public Optional<Instant> getIssueTime()
        Issue time of the token.
        Returns:
        issue time or empty if not available
      • getExpTime

        public Optional<Instant> getExpTime()
        Expiration time of the token.
        Returns:
        expiration time or empty if not available
      • getIssuer

        public Optional<String> getIssuer()
        Issuer of the token.
        Returns:
        issuer or empty if not available
      • getTokenInstance

        public <U> Optional<U> getTokenInstance​(Class<U> tokenClass)
        Get a token of a specific class. By default the String.class is supported - and returns the token content. Other instances may be available from authentication provider (e.g. Jwt).
        Type Parameters:
        U - type of the class
        Parameters:
        tokenClass - class we want to get
        Returns:
        instance of the token if present