Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Java Client API
Commits
964f5327
Commit
964f5327
authored
Jan 25, 2019
by
Matija Obreza
Browse files
Merge branch 'new-api-for-anno' into 'master'
API for getting access token by client id and secret See merge request
!10
parents
58d9733a
e7ca859e
Changes
3
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
964f5327
...
...
@@ -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>
...
...
src/main/java/org/genesys2/client/oauth/GenesysClient.java
View file @
964f5327
...
...
@@ -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
;
...
...
@@ -581,6 +582,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.
*
...
...
src/main/java/org/genesys2/client/oauth/api/GenesysApi.java
View file @
964f5327
...
...
@@ -17,7 +17,8 @@
package
org.genesys2.client.oauth.api
;
import
com.github.scribejava.core.builder.api.DefaultApi20
;
import
com.github.scribejava.core.builder.api.OAuth2SignatureType
;
import
com.github.scribejava.core.oauth2.clientauthentication.ClientAuthentication
;
import
com.github.scribejava.core.oauth2.clientauthentication.RequestBodyAuthenticationScheme
;
/**
* Genesys API v1.
...
...
@@ -52,11 +53,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.
*
...
...
@@ -66,4 +62,8 @@ public class GenesysApi extends DefaultApi20 {
return
baseUrl
;
}
@Override
public
ClientAuthentication
getClientAuthentication
()
{
return
RequestBodyAuthenticationScheme
.
instance
();
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment