com.nimbusds.oauth2.sdk.TokenErrorResponse Java Examples
The following examples show how to use
com.nimbusds.oauth2.sdk.TokenErrorResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OidcClientTest.java From sonar-auth-oidc with Apache License 2.0 | 6 votes |
private OidcClient newSpyOidcClient() { setSettings(true); OidcClient client = createSpyOidcClient(); try { OIDCTokenResponse tokenResponse = OIDCTokenResponse.parse(JSONObjectUtils.parse( "{\"access_token\":\"eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ3djY4UzUybDZTWVUxNGFfd0N3VElJT01WV1d1RXVXUFNBcERjYXo5Rnd3In0.eyJqdGkiOiIzMWNkOWM3YS05YTM3LTRiOTktOTViMC1jNzJlNGYzNGY4ODEiLCJleHAiOjE1MTQzMDcwNTQsIm5iZiI6MCwiaWF0IjoxNTE0MzA2NzU0LCJpc3MiOiJodHRwOi8vbWFjYm9vay1wcm8uZnJpdHouYm94OjgwODAvYXV0aC9yZWFsbXMvc3NvIiwiYXVkIjoic29uYXJxdWJlIiwic3ViIjoiYWZhYmE1OTItYWM4NS00Y2YxLThlYzYtMDA1OGQxNTdmODgyIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoic29uYXJxdWJlIiwiYXV0aF90aW1lIjoxNTE0MzA2NzU0LCJzZXNzaW9uX3N0YXRlIjoiYWE2N2NjNjktN2EwNi00N2QxLWJhMDAtNjk2NDZlNjBiOGJlIiwiYWNyIjoiMSIsImFsbG93ZWQtb3JpZ2lucyI6WyJodHRwOi8vbWFjYm9vay1wcm8uZnJpdHouYm94OjgwODIvIl0sInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyJ1bWFfYXV0aG9yaXphdGlvbiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7ImFjY291bnQiOnsicm9sZXMiOlsibWFuYWdlLWFjY291bnQiLCJtYW5hZ2UtYWNjb3VudC1saW5rcyIs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2MGI4YmUiLCJhY3IiOiIxIiwibmFtZSI6IkpvaG4gRG9vIiwicHJlZmVycmVkX3VzZXJuYW1lIjoiam9obi5kb28iLCJnaXZlbl9uYW1lIjoiSm9obiIsImZhbWlseV9uYW1lIjoiRG9vIiwiZW1haWwiOiJqb2huLmRvb0BhY21lLmNvbSJ9.UwqM6TGPrpMpK70FKxX9ZQWyUySjx7fxeV5IAT2PtzTH4xZKLJQbQmb4uD9z7o5azK5fgYc9xQfJKQX2y2euz-mtSdjueqkPAY-djQEc2kyvb-4Nd9Qc4Uiy19aAuooNdM-pAiYhfvyQQiGMRe3z68sq45mgfDpKMBcV-5bOJNafQ8tLLEonzT37-1GMfuAMv7ppx4HmdUDQccZ0D4nBqmeFRPcA3BghPZJ6eThR_mRsuYW1yZDg5tMle2cZe80mnIZSTW349cPwJFfmQDNT7XQBHHTCa6pYsBoqs2KYadOnbMSPCXZ-agd0DzffgtujsBvrUWV8tXSZ7axY34xMQQ\"," + "\"token_type\":\"Bearer\",\"expires_in\":300}")); doReturn(tokenResponse).when(client).getTokenResponse(new AuthorizationCode(VALID_CODE), CALLBACK_URL); TokenErrorResponse errorTokenResponse = TokenErrorResponse .parse(JSONObjectUtils.parse("{\"error\":\"invalid_request\"}")); doReturn(errorTokenResponse).when(client).getTokenResponse(new AuthorizationCode(INVALID_CODE), CALLBACK_URL); UserInfo userInfo = new UserInfo(tokenResponse.getOIDCTokens().getIDToken().getJWTClaimsSet()); doReturn(userInfo).when(client).getUserInfo(new AuthorizationCode(VALID_CODE), CALLBACK_URL); } catch (ParseException | java.text.ParseException e) { // ignore } return client; }
Example #2
Source File: OidcClientTest.java From sonar-auth-oidc with Apache License 2.0 | 5 votes |
@Test public void tokenErrorResponseWithoutErrorCode() { OidcClient underTest = newSpyOidcClient(); TokenErrorResponse errorTokenResponse = new TokenErrorResponse(new ErrorObject(null)); doReturn(errorTokenResponse).when(underTest).getTokenResponse(new AuthorizationCode("no_error"), CALLBACK_URL); try { underTest.getUserInfo(new AuthorizationCode("no_error"), CALLBACK_URL); failBecauseExceptionWasNotThrown(IllegalStateException.class); } catch (IllegalStateException e) { assertEquals("Token request failed: No error code returned (identity provider not reachable - " + "check network proxy setting 'http.nonProxyHosts' in 'sonar.properties')", e.getMessage()); } }
Example #3
Source File: OpenIdConnector.java From onedev with MIT License | 4 votes |
@Override public SsoAuthenticated processLoginResponse() { HttpServletRequest request = (HttpServletRequest) RequestCycle.get().getRequest().getContainerRequest(); try { AuthenticationResponse authenticationResponse = AuthenticationResponseParser.parse( new URI(request.getRequestURI() + "?" + request.getQueryString())); if (authenticationResponse instanceof AuthenticationErrorResponse) { throw buildException(((AuthenticationErrorResponse)authenticationResponse).getErrorObject()); } else { AuthenticationSuccessResponse authenticationSuccessResponse = (AuthenticationSuccessResponse)authenticationResponse; String state = (String) Session.get().getAttribute(SESSION_ATTR_STATE); if (state == null || !state.equals(authenticationSuccessResponse.getState().getValue())) throw new AuthenticationException("Unsolicited OIDC authentication response"); AuthorizationGrant codeGrant = new AuthorizationCodeGrant( authenticationSuccessResponse.getAuthorizationCode(), getCallbackUri()); ClientID clientID = new ClientID(getClientId()); Secret clientSecret = new Secret(getClientSecret()); ClientAuthentication clientAuth = new ClientSecretBasic(clientID, clientSecret); TokenRequest tokenRequest = new TokenRequest( new URI(getCachedProviderMetadata().getTokenEndpoint()), clientAuth, codeGrant); HTTPResponse httpResponse = tokenRequest.toHTTPRequest().send(); if (httpResponse.getStatusCode() == HTTPResponse.SC_OK) { JSONObject jsonObject = httpResponse.getContentAsJSONObject(); if (jsonObject.get("error") != null) throw buildException(TokenErrorResponse.parse(jsonObject).getErrorObject()); else return processTokenResponse(OIDCAccessTokenResponse.parse(jsonObject)); } else { ErrorObject error = TokenErrorResponse.parse(httpResponse).getErrorObject(); if (error != null) { throw buildException(error); } else { String message = String.format("Error requesting OIDC token: http status: %d", httpResponse.getStatusCode()); throw new AuthenticationException(message); } } } } catch (ParseException | URISyntaxException|SerializeException|IOException e) { throw new RuntimeException(e); } }