use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken in project ORCID-Source by ORCID.
the class OrcidClientCredentialEndPointDelegatorTest method generateRefreshTokenThatExpireAfterParentTokenTest.
@Test
public void generateRefreshTokenThatExpireAfterParentTokenTest() {
//Generate the access token
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", false, "/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()));
//Generate the refresh token that expires after parent token
MultivaluedMap<String, String> refreshTokenformParams = new MultivaluedMapImpl();
refreshTokenformParams.add("client_id", CLIENT_ID_1);
refreshTokenformParams.add("client_secret", "DhkFj5EI0qp6GsUKi55Vja+h+bsaKpBx");
refreshTokenformParams.add("grant_type", "refresh_token");
refreshTokenformParams.add("redirect_uri", "http://www.APP-5555555555555555.com/redirect/oauth");
refreshTokenformParams.add("refresh_token", token.getRefreshToken().getValue());
refreshTokenformParams.add("expires_in", String.valueOf(2 * 60 * 60));
String authorization = "bearer " + token.getValue();
try {
orcidClientCredentialEndPointDelegator.obtainOauth2Token(authorization, refreshTokenformParams);
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("Token expiration can't be after"));
}
//Try again with a valid expiration value
refreshTokenformParams = new MultivaluedMapImpl();
refreshTokenformParams.add("client_id", CLIENT_ID_1);
refreshTokenformParams.add("client_secret", "DhkFj5EI0qp6GsUKi55Vja+h+bsaKpBx");
refreshTokenformParams.add("grant_type", "refresh_token");
refreshTokenformParams.add("redirect_uri", "http://www.APP-5555555555555555.com/redirect/oauth");
refreshTokenformParams.add("refresh_token", token.getRefreshToken().getValue());
refreshTokenformParams.add("expires_in", String.valueOf(60 * 30));
response = orcidClientCredentialEndPointDelegator.obtainOauth2Token(authorization, refreshTokenformParams);
assertNotNull(response);
assertNotNull(response.getEntity());
DefaultOAuth2AccessToken refreshToken = (DefaultOAuth2AccessToken) response.getEntity();
assertNotNull(refreshToken);
assertTrue(!PojoUtil.isEmpty(refreshToken.getValue()));
assertNotNull(refreshToken.getRefreshToken());
assertTrue(!PojoUtil.isEmpty(refreshToken.getRefreshToken().getValue()));
assertTrue(token.getExpiration().getTime() > refreshToken.getExpiration().getTime());
}
use of org.springframework.security.oauth2.common.DefaultOAuth2AccessToken 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()));
}
Aggregations