use of com.nimbusds.oauth2.sdk.AuthorizationResponse in project asgardeo-java-oidc-sdk by asgardeo.
the class OIDCRequestResolverTest method testIsAuthorizationCodeResponse.
@Test
public void testIsAuthorizationCodeResponse() throws IOException, ParseException, URISyntaxException {
MockedStatic<AuthorizationResponse> mockedAuthorizationResponse = mockStatic(AuthorizationResponse.class);
MockedStatic<ServletUtils> mockedServletUtils = mockStatic(ServletUtils.class);
HTTPRequest httpRequest = mock(HTTPRequest.class);
AuthorizationResponse authorizationResponse = mock(AuthorizationResponse.class);
AuthorizationSuccessResponse authorizationSuccessResponse = mock(AuthorizationSuccessResponse.class);
AuthorizationCode authzCode = new AuthorizationCode("auth-code");
when(ServletUtils.createHTTPRequest(request)).thenReturn(httpRequest);
when(AuthorizationResponse.parse(httpRequest)).thenReturn(authorizationResponse);
when(authorizationResponse.indicatesSuccess()).thenReturn(true);
when(authorizationResponse.toSuccessResponse()).thenReturn(authorizationSuccessResponse);
when(authorizationSuccessResponse.getAuthorizationCode()).thenReturn(authzCode);
OIDCRequestResolver resolver = new OIDCRequestResolver(request, oidcAgentConfig);
assertTrue(resolver.isAuthorizationCodeResponse());
mockedAuthorizationResponse.close();
mockedServletUtils.close();
}
use of com.nimbusds.oauth2.sdk.AuthorizationResponse in project asgardeo-java-oidc-sdk by asgardeo.
the class DefaultOIDCManager method handleAuthentication.
private boolean handleAuthentication(final HttpServletRequest request, SessionContext authenticationInfo, Nonce nonce) throws SSOAgentServerException {
AuthorizationResponse authorizationResponse;
AuthorizationCode authorizationCode;
AuthorizationSuccessResponse successResponse;
TokenRequest tokenRequest;
TokenResponse tokenResponse;
try {
authorizationResponse = AuthorizationResponse.parse(ServletUtils.createHTTPRequest(request));
if (!authorizationResponse.indicatesSuccess()) {
handleErrorAuthorizationResponse(authorizationResponse);
return false;
}
successResponse = authorizationResponse.toSuccessResponse();
authorizationCode = successResponse.getAuthorizationCode();
tokenRequest = getTokenRequest(authorizationCode);
tokenResponse = getTokenResponse(tokenRequest);
if (!tokenResponse.indicatesSuccess()) {
handleErrorTokenResponse(tokenRequest, tokenResponse);
return false;
}
handleSuccessTokenResponse(tokenResponse, authenticationInfo, nonce);
return true;
} catch (com.nimbusds.oauth2.sdk.ParseException | SSOAgentServerException | IOException e) {
throw new SSOAgentServerException(e.getMessage(), e);
}
}
use of com.nimbusds.oauth2.sdk.AuthorizationResponse in project asgardeo-java-oidc-sdk by asgardeo.
the class DefaultOIDCManager method handleErrorAuthorizationResponse.
private void handleErrorAuthorizationResponse(AuthorizationResponse authorizationResponse) {
AuthorizationErrorResponse errorResponse = authorizationResponse.toErrorResponse();
JSONObject responseObject = errorResponse.getErrorObject().toJSONObject();
logger.log(Level.INFO, "Error response object: " + responseObject);
}
use of com.nimbusds.oauth2.sdk.AuthorizationResponse in project asgardeo-java-oidc-sdk by asgardeo.
the class OIDCRequestResolver method logErrorAuthorizationResponse.
private void logErrorAuthorizationResponse(AuthorizationResponse authzResponse) {
AuthorizationErrorResponse errorResponse = authzResponse.toErrorResponse();
JSONObject responseObject = errorResponse.getErrorObject().toJSONObject();
logger.log(Level.INFO, "Error response object: ", responseObject);
}
use of com.nimbusds.oauth2.sdk.AuthorizationResponse in project sandbox by backpaper0.
the class OAuth2Filter method handleAuthorization.
private Optional<AuthorizationSuccessResponse> handleAuthorization(HttpServletRequest req) throws Exception {
final Map<String, List<String>> params = req.getParameterMap().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, a -> List.of(a.getValue())));
final URI redirectURI = URI.create(req.getRequestURI());
final AuthorizationResponse response = AuthorizationResponse.parse(redirectURI, params);
if (response.indicatesSuccess() == false) {
return Optional.empty();
}
return Optional.of((AuthorizationSuccessResponse) response);
}
Aggregations