Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
Java Client API
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Genesys PGR
Java Client API
Commits
e7ca859e
Commit
e7ca859e
authored
Jan 09, 2019
by
Maxym Borodenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API for getting access token by client id and secret
FIX: HTTP error 401 if client secret is not provided
parent
58d9733a
Pipeline
#8475
passed with stage
in 34 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
7 deletions
+31
-7
pom.xml
pom.xml
+1
-1
src/main/java/org/genesys2/client/oauth/GenesysClient.java
src/main/java/org/genesys2/client/oauth/GenesysClient.java
+24
-0
src/main/java/org/genesys2/client/oauth/api/GenesysApi.java
src/main/java/org/genesys2/client/oauth/api/GenesysApi.java
+6
-6
No files found.
pom.xml
View file @
e7ca859e
...
...
@@ -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 @
e7ca859e
...
...
@@ -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 @
e7ca859e
...
...
@@ -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
Markdown
is supported
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