Commit a0727767 authored by Maxym Borodenko's avatar Maxym Borodenko

API for getting access token by client id and secret

parent fb9be9de
Pipeline #8390 passed with stage
in 31 seconds
......@@ -91,7 +91,7 @@
<dependency>
<groupId>com.github.scribejava</groupId>
<artifactId>scribejava-core</artifactId>
<version>4.2.0</version>
<version>6.2.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
......
......@@ -42,6 +42,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.scribejava.core.builder.ServiceBuilder;
import com.github.scribejava.core.exceptions.OAuthException;
import com.github.scribejava.core.model.OAuth2AccessToken;
import com.github.scribejava.core.model.OAuthRequest;
import com.github.scribejava.core.model.Response;
......@@ -562,6 +563,29 @@ public class GenesysClient {
}
}
/**
* Obtain access and refresh tokens with client id and secret.
*
* @throws OAuthAuthenticationException
*/
public void authenticate() throws OAuthAuthenticationException {
try {
OAuth2AccessToken accessToken = service.getAccessTokenClientCredentialsGrant();
LOG.info("ACCESS TOKEN: {} scope={} raw={}", accessToken.getAccessToken(), accessToken.getScope(), accessToken.getRawResponse());
final String refreshToken = accessToken.getRefreshToken();
LOG.info("REFRESH TOKEN: {}", refreshToken);
tokens.setAccessToken(accessToken.getAccessToken());
tokens.setRefreshToken(refreshToken);
} catch (OAuthException | IOException | InterruptedException | ExecutionException e) {
LOG.error("Auth error", e);
throw new OAuthAuthenticationException(e.getMessage());
}
}
/**
* Obtain access and refresh tokens with verifier code.
*
......
......@@ -17,7 +17,6 @@
package org.genesys2.client.oauth.api;
import com.github.scribejava.core.builder.api.DefaultApi20;
import com.github.scribejava.core.builder.api.OAuth2SignatureType;
/**
* Genesys API v1.
......@@ -52,11 +51,6 @@ public class GenesysApi extends DefaultApi20 {
return baseUrl + AUTHORIZE_ENDPOINT;
}
@Override
public OAuth2SignatureType getSignatureType() {
return OAuth2SignatureType.BEARER_AUTHORIZATION_REQUEST_HEADER_FIELD;
}
/**
* Gets the base url.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment