-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathResourceScopedAccessGrantTokenClient.java
More file actions
55 lines (49 loc) · 2.07 KB
/
ResourceScopedAccessGrantTokenClient.java
File metadata and controls
55 lines (49 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.scalepoint.oauth_token_client;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* OAuth2 Token endpoint client for urn:scalepoint:params:oauth:grant-type:resource-scoped-access grant.
*/
@SuppressWarnings("WeakerAccess")
public class ResourceScopedAccessGrantTokenClient extends CustomGrantTokenClient {
/**
* Constructs a resource-scoped access grant token client.
*
* @param tokenEndpointUri URI of the OAuth2 token endpoint
* @param clientCredentials client credentials for authentication
*/
@SuppressWarnings("SameParameterValue")
public ResourceScopedAccessGrantTokenClient(String tokenEndpointUri, ClientCredentials clientCredentials) {
super(tokenEndpointUri, clientCredentials, new NoCache());
}
/**
* Retrieve access token for the configured "client_id", specified scope and resource
*
* @param parameters Custom grant parameters
* @return Access token
* @throws IOException Exception during token endpoint communication
* @throws InterruptedException if the thread is interrupted during token retrieval
*/
@SuppressWarnings("UnusedReturnValue")
public String getToken(ResourceScopedAccessGrantParameters parameters) throws IOException, InterruptedException {
return getTokenInternal(getPostParams(parameters), parameters.getScope());
}
private List<NameValuePair> getPostParams(ResourceScopedAccessGrantParameters parameters) {
ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new NameValuePair("target", parameters.getTarget()));
String tenantId = parameters.getTenantId();
if (tenantId != null) {
params.add(new NameValuePair("tenantId", tenantId));
}
String amr = parameters.getAmrString();
if (amr != null) {
params.add(new NameValuePair("amr", amr));
}
return params;
}
@Override
protected String getGrantType() {
return "urn:scalepoint:params:oauth:grant-type:resource-scoped-access";
}
}