Class GoogleServiceAccountTokenProvider

java.lang.Object
fr.becpg.repo.multilingual.translation.GoogleServiceAccountTokenProvider
All Implemented Interfaces:
GoogleAccessTokenProvider

public class GoogleServiceAccountTokenProvider extends Object implements GoogleAccessTokenProvider
Access token of a service account key file, for servers outside Google Cloud that have no metadata server. The signed JWT assertion is exchanged at the token URI of the key (RFC 7523).
Author:
matthieu
  • Field Details

  • Constructor Details

    • GoogleServiceAccountTokenProvider

      public GoogleServiceAccountTokenProvider(String credentialsFile)

      Constructor for GoogleServiceAccountTokenProvider.

      Parameters:
      credentialsFile - path of the JSON key of the service account
    • GoogleServiceAccountTokenProvider

      GoogleServiceAccountTokenProvider(org.json.JSONObject key, org.springframework.web.client.RestTemplate restTemplate, Clock clock)
  • Method Details

    • getAccessToken

      public String getAccessToken()

      getAccessToken.

      Specified by:
      getAccessToken in interface GoogleAccessTokenProvider
      Returns:
      a valid bearer access token
    • fetchAccessToken

      private void fetchAccessToken()
    • buildAssertion

      String buildAssertion()
    • readKey

      private static org.json.JSONObject readKey(Path credentialsFile)
    • parsePrivateKey

      static PrivateKey parsePrivateKey(String pem)
    • base64Url

      private static String base64Url(byte[] bytes)