use of org.springframework.security.oauth2.provider.TokenRequest in project ORCID-Source by ORCID.
the class OrcidClientCredentialsCheckerTest method testValidCredentialsScopes.
@Test
public void testValidCredentialsScopes() throws Exception {
String memberId = "2875-8158-1475-6194";
String clientId = "APP-1";
setupMocks(clientId, memberId);
Set<String> requestedScopes = new HashSet<String>(Arrays.asList(ScopePathType.READ_PUBLIC.value()));
Map<String, String> requestParams = new HashMap<String, String>();
requestParams.put(OrcidOauth2Constants.SCOPE_PARAM, ScopePathType.READ_PUBLIC.value());
checker.validateCredentials("client_credentials", new TokenRequest(requestParams, clientId, requestedScopes, "client_credentials"));
}
use of org.springframework.security.oauth2.provider.TokenRequest in project ORCID-Source by ORCID.
the class OrcidClientCredentialsCheckerTest method testValidCredentialsScopesForClientOnly.
@Test
public void testValidCredentialsScopesForClientOnly() throws Exception {
String memberId = "2875-8158-1475-6194";
String clientId = "APP-1";
setupMocks(clientId, memberId);
Set<String> requestedScopes = new HashSet<String>(Arrays.asList(ScopePathType.READ_PUBLIC.value()));
Map<String, String> requestParams = new HashMap<String, String>();
requestParams.put(OrcidOauth2Constants.SCOPE_PARAM, ScopePathType.READ_PUBLIC.value());
checker.validateCredentials("client_credentials", new TokenRequest(requestParams, clientId, requestedScopes, "client_credentials"));
}
use of org.springframework.security.oauth2.provider.TokenRequest in project ORCID-Source by ORCID.
the class OrcidRefreshTokenTokenGranterTest method generateRefreshToken.
private OAuth2AccessToken generateRefreshToken(OrcidOauth2TokenDetail tokenDetails, String customClientId, Boolean revokeOld, Long expiresIn, String... scopesParam) {
Set<String> scopes = null;
if (scopesParam != null) {
scopes = new HashSet<String>(Arrays.asList(scopesParam));
}
Map<String, String> authorizationParameters = new HashMap<String, String>();
String scopesString = scopes == null ? null : StringUtils.join(scopes, ' ');
String clientId = PojoUtil.isEmpty(customClientId) ? tokenDetails.getClientDetailsId() : customClientId;
String refreshTokenValue = tokenDetails.getRefreshTokenValue();
authorizationParameters.put(OAuth2Utils.CLIENT_ID, clientId);
authorizationParameters.put(OrcidOauth2Constants.IS_PERSISTENT, "true");
authorizationParameters.put(OrcidOauth2Constants.AUTHORIZATION, tokenDetails.getTokenValue());
authorizationParameters.put(OrcidOauth2Constants.REFRESH_TOKEN, refreshTokenValue);
authorizationParameters.put(OAuth2Utils.REDIRECT_URI, tokenDetails.getRedirectUri());
if (!PojoUtil.isEmpty(scopesString)) {
authorizationParameters.put(OAuth2Utils.SCOPE, scopesString);
}
if (revokeOld != null) {
authorizationParameters.put(OrcidOauth2Constants.REVOKE_OLD, String.valueOf(revokeOld));
}
if (expiresIn != null) {
authorizationParameters.put(OrcidOauth2Constants.EXPIRES_IN, String.valueOf(expiresIn));
}
TokenRequest tokenRequest = new TokenRequest(authorizationParameters, clientId, scopes, OrcidOauth2Constants.REFRESH_TOKEN);
return refreshTokenTokenGranter.grant(OrcidOauth2Constants.REFRESH_TOKEN, tokenRequest);
}
Aggregations