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
dd1b6fe5
Commit
dd1b6fe5
authored
Oct 28, 2017
by
Matija Obreza
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '8-support-password-grant' into 'master'
Resolve "Support password grant" Closes
#8
See merge request
!8
parents
da23386c
2d6c53c9
Pipeline
#3035
passed with stage
in 27 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
13 deletions
+50
-13
README.md
README.md
+28
-9
src/main/java/org/genesys2/client/oauth/GenesysClient.java
src/main/java/org/genesys2/client/oauth/GenesysClient.java
+22
-4
No files found.
README.md
View file @
dd1b6fe5
...
...
@@ -14,7 +14,9 @@ String scope = "write"; // write scope is required to manage data on Genesys
GenesysClient
genesysClient
=
new
GenesysClient
(
baseUrl
,
clientId
,
clientSecret
,
callbackUrl
,
scope
);
```
### Authentication
### Authentication: Authorization code
For Genesys API clients that support
`authorization_code`
grant (such as websites, unsafe clients).
```
java
// Authenticate the user
...
...
@@ -32,10 +34,27 @@ genesysClient.me();
// genesysClient.getTokens().getRefreshToken();
```
### Authentication: Username and password
For Genesys API clients that support
`password`
grant (safe clients).
```
java
// Obtain username and password
String
username
;
String
password
;
genesysClient
.
authenticate
(
username
,
password
);
// Test it with /me
genesysClient
.
me
();
// Tokens are now accessible. The refreshToken must be **safely** stored for future use.
// genesysClient.getTokens().getAccessToken();
// genesysClient.getTokens().getRefreshToken();
```
### Re-using tokens
If you have existing tokens you can provide the access and refresh tokens when
initializing the client:
If you have existing tokens you can provide the access and refresh tokens when initializing the client:
```
java
GenesysTokens
genesysTokens
=
new
GenesysTokens
();
...
...
@@ -71,9 +90,9 @@ try {
```
xml
<dependency>
<groupId>
org.genesys-pgr
</groupId>
<artifactId>
genesys-client-api
</artifactId>
<version>
1.2
</version>
<groupId>
org.genesys-pgr
</groupId>
<artifactId>
genesys-client-api
</artifactId>
<version>
1.2
</version>
</dependency>
```
...
...
@@ -81,9 +100,9 @@ Or for the development version:
```
xml
<dependency>
<groupId>
org.genesys-pgr
</groupId>
<artifactId>
genesys-client-api
</artifactId>
<version>
1.3-SNAPSHOT
</version>
<groupId>
org.genesys-pgr
</groupId>
<artifactId>
genesys-client-api
</artifactId>
<version>
1.3-SNAPSHOT
</version>
</dependency>
```
...
...
src/main/java/org/genesys2/client/oauth/GenesysClient.java
View file @
dd1b6fe5
...
...
@@ -116,7 +116,7 @@ public class GenesysClient {
public
String
getAuthorizationUrl
()
{
return
service
.
getAuthorizationUrl
();
}
/**
* Sets the tokens.
*
...
...
@@ -231,7 +231,7 @@ public class GenesysClient {
request
.
setPayload
(
postBody
);
}
request
.
setCharset
(
"UTF-8"
);
request
.
setCharset
(
"UTF-8"
);
Response
response
=
null
;
try
{
...
...
@@ -540,16 +540,34 @@ public class GenesysClient {
return
query
(
Verb
.
POST
,
"/acn/"
+
instCode
+
"/delete"
,
null
,
jsonAccessionIdList
);
}
public
void
authenticate
(
String
uname
,
String
password
)
throws
OAuthAuthenticationException
{
try
{
OAuth2AccessToken
accessToken
=
service
.
getAccessTokenPasswordGrant
(
uname
,
password
);
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
(
IOException
|
InterruptedException
|
ExecutionException
e
)
{
LOG
.
error
(
"Auth error"
,
e
);
throw
new
OAuthAuthenticationException
(
e
.
getMessage
());
}
}
/**
* Obtain access and refresh tokens with verifier code.
*
* @param verifierCode the verifier code
* @throws OAuthAuthenticationException
* @throws OAuthAuthenticationException
*/
public
void
authenticate
(
final
String
verifierCode
)
throws
OAuthAuthenticationException
{
try
{
OAuth2AccessToken
accessToken
=
service
.
getAccessToken
(
verifierCode
);
LOG
.
info
(
"ACCESS TOKEN: {} scope={} raw={}"
,
accessToken
.
getAccessToken
(),
accessToken
.
getScope
(),
accessToken
.
getRawResponse
());
final
String
refreshToken
=
accessToken
.
getRefreshToken
();
...
...
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