Class ExternalAccountCredentials

    • Constructor Detail

      • ExternalAccountCredentials

        protected ExternalAccountCredentials​(HttpTransportFactory transportFactory,
                                             String audience,
                                             String subjectTokenType,
                                             String tokenUrl,
                                             com.google.auth.oauth2.ExternalAccountCredentials.CredentialSource credentialSource,
                                             @Nullable
                                             String tokenInfoUrl,
                                             @Nullable
                                             String serviceAccountImpersonationUrl,
                                             @Nullable
                                             String quotaProjectId,
                                             @Nullable
                                             String clientId,
                                             @Nullable
                                             String clientSecret,
                                             @Nullable
                                             Collection<String> scopes)
        Constructor with minimum identifying information and custom HTTP transport. Does not support workforce credentials.
        Parameters:
        transportFactory - HTTP transport factory, creates the transport used to get access tokens
        audience - the Security Token Service audience, which is usually the fully specified resource name of the workload/workforce pool provider
        subjectTokenType - the Security Token Service subject token type based on the OAuth 2.0 token exchange spec. Indicates the type of the security token in the credential file
        tokenUrl - the Security Token Service token exchange endpoint
        tokenInfoUrl - the endpoint used to retrieve account related information. Required for gCloud session account identification.
        credentialSource - the external credential source
        serviceAccountImpersonationUrl - the URL for the service account impersonation request. This URL is required for some APIs. If this URL is not available, the access token from the Security Token Service is used directly. May be null.
        quotaProjectId - the project used for quota and billing purposes. May be null.
        clientId - client ID of the service account from the console. May be null.
        clientSecret - client secret of the service account from the console. May be null.
        scopes - the scopes to request during the authorization grant. May be null.
      • ExternalAccountCredentials

        protected ExternalAccountCredentials​(HttpTransportFactory transportFactory,
                                             String audience,
                                             String subjectTokenType,
                                             String tokenUrl,
                                             com.google.auth.oauth2.ExternalAccountCredentials.CredentialSource credentialSource,
                                             @Nullable
                                             String tokenInfoUrl,
                                             @Nullable
                                             String serviceAccountImpersonationUrl,
                                             @Nullable
                                             String quotaProjectId,
                                             @Nullable
                                             String clientId,
                                             @Nullable
                                             String clientSecret,
                                             @Nullable
                                             Collection<String> scopes,
                                             @Nullable
                                             com.google.auth.oauth2.EnvironmentProvider environmentProvider)
        Constructor with minimum identifying information and custom HTTP transport. Does not support workforce credentials.
        Parameters:
        transportFactory - HTTP transport factory, creates the transport used to get access tokens
        audience - the Security Token Service audience, which is usually the fully specified resource name of the workload/workforce pool provider
        subjectTokenType - the Security Token Service subject token type based on the OAuth 2.0 token exchange spec. Indicates the type of the security token in the credential file
        tokenUrl - the Security Token Service token exchange endpoint
        tokenInfoUrl - the endpoint used to retrieve account related information. Required for gCloud session account identification.
        credentialSource - the external credential source
        serviceAccountImpersonationUrl - the URL for the service account impersonation request. This URL is required for some APIs. If this URL is not available, the access token from the Security Token Service is used directly. May be null.
        quotaProjectId - the project used for quota and billing purposes. May be null.
        clientId - client ID of the service account from the console. May be null.
        clientSecret - client secret of the service account from the console. May be null.
        scopes - the scopes to request during the authorization grant. May be null.
        environmentProvider - the environment provider. May be null. Defaults to SystemEnvironmentProvider.
    • Method Detail

      • getRequestMetadata

        public void getRequestMetadata​(URI uri,
                                       Executor executor,
                                       RequestMetadataCallback callback)
        Description copied from class: Credentials
        Get the current request metadata without blocking.

        This should be called by the transport layer on each request, and the data should be populated in headers or other context. The implementation can either call the callback inline or asynchronously. Either way it should never block in this method. The executor is provided for tasks that may block.

        The default implementation will just call Credentials.getRequestMetadata(URI) then the callback from the given executor.

        The convention for handling binary data is for the key in the returned map to end with "-bin" and for the corresponding values to be base64 encoded.

        Overrides:
        getRequestMetadata in class OAuth2Credentials
        Parameters:
        uri - URI of the entry point for the request.
        executor - Executor to perform the request.
        callback - Callback to execute when the request is finished.
      • getRequestMetadata

        public Map<String,​List<String>> getRequestMetadata​(URI uri)
                                                          throws IOException
        Description copied from class: OAuth2Credentials
        Provide the request metadata by ensuring there is a current access token and providing it as an authorization bearer token.
        Overrides:
        getRequestMetadata in class OAuth2Credentials
        Parameters:
        uri - URI of the entry point for the request.
        Returns:
        The request metadata used for populating headers or other context.
        Throws:
        IOException - if there was an error getting up-to-date access. The exception should implement Retryable and isRetryable() will return true if the operation may be retried.
      • exchangeExternalCredentialForAccessToken

        protected AccessToken exchangeExternalCredentialForAccessToken​(com.google.auth.oauth2.StsTokenExchangeRequest stsTokenExchangeRequest)
                                                                throws IOException
        Exchanges the external credential for a Google Cloud access token.
        Parameters:
        stsTokenExchangeRequest - the Security Token Service token exchange request
        Returns:
        the access token returned by the Security Token Service
        Throws:
        com.google.auth.oauth2.OAuthException - if the call to the Security Token Service fails
        IOException
      • retrieveSubjectToken

        public abstract String retrieveSubjectToken()
                                             throws IOException
        Retrieves the external subject token to be exchanged for a Google Cloud access token.

        Must be implemented by subclasses as the retrieval method is dependent on the credential source.

        Returns:
        the external subject token
        Throws:
        IOException - if the subject token cannot be retrieved
      • getAudience

        public String getAudience()
      • getSubjectTokenType

        public String getSubjectTokenType()
      • getTokenUrl

        public String getTokenUrl()
      • getTokenInfoUrl

        public String getTokenInfoUrl()
      • getCredentialSource

        public com.google.auth.oauth2.ExternalAccountCredentials.CredentialSource getCredentialSource()
      • getServiceAccountImpersonationUrl

        @Nullable
        public String getServiceAccountImpersonationUrl()
      • getServiceAccountEmail

        @Nullable
        public String getServiceAccountEmail()
        Returns:
        The service account email to be impersonated, if available
      • getWorkforcePoolUserProject

        @Nullable
        public String getWorkforcePoolUserProject()
      • getServiceAccountImpersonationOptions

        @Nullable
        public com.google.auth.oauth2.ExternalAccountCredentials.ServiceAccountImpersonationOptions getServiceAccountImpersonationOptions()
      • isWorkforcePoolConfiguration

        public boolean isWorkforcePoolConfiguration()
        Returns:
        whether the current configuration is for Workforce Pools (which enable 3p user identities, rather than workloads)