use of com.google.api.client.auth.oauth2.ClientCredentialsTokenRequest in project SORMAS-Project by hzi-braunschweig.
the class Oidc method requestAccessToken.
public static String requestAccessToken(String tokenEndpoint, String clientId, String clientSecret, List<String> scopes) throws Exception {
ClientParametersAuthentication clientAuth = new ClientParametersAuthentication(clientId, clientSecret);
try {
LOGGER.info(String.format("Requesting access token for client %s at %s with scope: %s", clientId, tokenEndpoint, scopes));
TokenResponse response = new ClientCredentialsTokenRequest(new NetHttpTransport(), new GsonFactory(), new GenericUrl(tokenEndpoint)).setClientAuthentication(clientAuth).setScopes(scopes).execute();
String token = response.getAccessToken();
if (token == null || token.isEmpty()) {
LOGGER.error("Could not retrieve access token.");
throw new Exception("Could not retrieve access token.");
}
return token;
} catch (IOException e) {
LOGGER.error("Unable to connect to Keycloak.", e);
throw e;
}
}
Aggregations