use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.
the class OrcidClientCredentialEndPointDelegatorTest method generateClientCredentialsAccessTokenTest.
@Test
public void generateClientCredentialsAccessTokenTest() {
SecurityContextTestUtils.setUpSecurityContextForClientOnly(CLIENT_ID_1, ScopePathType.ACTIVITIES_UPDATE, ScopePathType.READ_LIMITED);
MultivaluedMap<String, String> formParams = new MultivaluedMapImpl();
formParams.add("client_id", CLIENT_ID_1);
formParams.add("client_secret", "DhkFj5EI0qp6GsUKi55Vja+h+bsaKpBx");
formParams.add("grant_type", "client_credentials");
formParams.add("redirect_uri", "http://www.APP-5555555555555555.com/redirect/oauth");
formParams.add("scope", "/orcid-profile/create");
Response response = orcidClientCredentialEndPointDelegator.obtainOauth2Token(null, formParams);
assertNotNull(response);
assertNotNull(response.getEntity());
DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) response.getEntity();
assertNotNull(token);
assertTrue(!PojoUtil.isEmpty(token.getValue()));
assertNotNull(token.getRefreshToken());
assertTrue(!PojoUtil.isEmpty(token.getRefreshToken().getValue()));
}
use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.
the class OrcidClientCredentialEndPointDelegatorTest method generateAccessTokenTest.
@Test
public void generateAccessTokenTest() {
SecurityContextTestUtils.setUpSecurityContextForClientOnly(CLIENT_ID_1, ScopePathType.ACTIVITIES_UPDATE, ScopePathType.READ_LIMITED);
OrcidOauth2AuthoriziationCodeDetail authCode = createAuthorizationCode("code-1", CLIENT_ID_1, "http://www.APP-5555555555555555.com/redirect/oauth", true, "/activities/update");
MultivaluedMap<String, String> formParams = new MultivaluedMapImpl();
formParams.add("client_id", CLIENT_ID_1);
formParams.add("client_secret", "DhkFj5EI0qp6GsUKi55Vja+h+bsaKpBx");
formParams.add("grant_type", "authorization_code");
formParams.add("redirect_uri", "http://www.APP-5555555555555555.com/redirect/oauth");
formParams.add("code", authCode.getId());
Response response = orcidClientCredentialEndPointDelegator.obtainOauth2Token(null, formParams);
assertNotNull(response);
assertNotNull(response.getEntity());
DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) response.getEntity();
assertNotNull(token);
assertTrue(!PojoUtil.isEmpty(token.getValue()));
assertNotNull(token.getRefreshToken());
assertTrue(!PojoUtil.isEmpty(token.getRefreshToken().getValue()));
}
use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.
the class PublicClientTest method testAuthenticateOnPublicAPI.
@Test
public void testAuthenticateOnPublicAPI() throws JSONException, InterruptedException {
String clientId = getPublicClientId();
String clientRedirectUri = getPublicClientRedirectUri();
String clientSecret = getPublicClientSecret();
String userId = getUser1OrcidId();
String password = getUser1Password();
String authorizationCode = getAuthorizationCode(clientId, clientRedirectUri, "/authenticate", userId, password, true);
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("client_id", clientId);
params.add("client_secret", clientSecret);
params.add("grant_type", "authorization_code");
params.add("scope", "/authenticate");
params.add("redirect_uri", clientRedirectUri);
params.add("code", authorizationCode);
ClientResponse response = t1OAuthClient.obtainOauth2TokenPost("client_credentials", params);
assertEquals(200, response.getStatus());
String body = response.getEntity(String.class);
JSONObject jsonObject = new JSONObject(body);
assertNotNull(jsonObject);
assertNotNull(jsonObject.get("access_token"));
assertEquals(userId, jsonObject.get("orcid"));
}
use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.
the class PublicClientTest method testAuthenticateOnMembersAPI.
@Test
public void testAuthenticateOnMembersAPI() throws JSONException, InterruptedException {
String clientId = getPublicClientId();
String clientRedirectUri = getPublicClientRedirectUri();
String clientSecret = getPublicClientSecret();
String userId = getUser1OrcidId();
String password = getUser1Password();
String authorizationCode = getAuthorizationCode(clientId, clientRedirectUri, "/authenticate", userId, password, true);
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("client_id", clientId);
params.add("client_secret", clientSecret);
params.add("grant_type", "authorization_code");
params.add("scope", "/authenticate");
params.add("redirect_uri", clientRedirectUri);
params.add("code", authorizationCode);
ClientResponse response = t2OAuthClient.obtainOauth2TokenPost("client_credentials", params);
assertEquals(200, response.getStatus());
String body = response.getEntity(String.class);
JSONObject jsonObject = new JSONObject(body);
assertNotNull(jsonObject);
assertNotNull(jsonObject.get("access_token"));
assertEquals(userId, jsonObject.get("orcid"));
}
use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.
the class InternalAPITest method testGetTokenForInternalScopes.
@Test
public void testGetTokenForInternalScopes() throws JSONException {
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("client_id", client1ClientId);
params.add("client_secret", client1ClientSecret);
params.add("grant_type", "client_credentials");
params.add("scope", ScopePathType.INTERNAL_PERSON_LAST_MODIFIED.value());
ClientResponse clientResponse = oauthHelper.getResponse(params, APIRequestType.INTERNAL);
assertNotNull(clientResponse);
assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatus());
String body = clientResponse.getEntity(String.class);
JSONObject jsonObject = new JSONObject(body);
String accessToken = (String) jsonObject.get("access_token");
assertNotNull(accessToken);
assertFalse(PojoUtil.isEmpty(accessToken));
}
Aggregations