Package com.nimbusds.oauth2.sdk.http

Examples of com.nimbusds.oauth2.sdk.http.HTTPResponse



  public void testParseEmpty()
    throws Exception {

    HTTPResponse httpResponse = new HTTPResponse(404);

    TokenErrorResponse errorResponse = TokenErrorResponse.parse(httpResponse);

    assertNull(errorResponse.getErrorObject());
  }
View Full Code Here



  public void testParseInvalidClient()
    throws Exception {

    HTTPResponse httpResponse = new HTTPResponse(401);
    httpResponse.setContentType(CommonContentTypes.APPLICATION_JSON);
    httpResponse.setContent("{\"error\":\"invalid_client\", \"error_description\":\"Client authentication failed\"}");

    TokenErrorResponse errorResponse = TokenErrorResponse.parse(httpResponse);

    assertEquals(OAuth2Error.INVALID_CLIENT.getCode(), errorResponse.getErrorObject().getCode());
    assertEquals("Client authentication failed", errorResponse.getErrorObject().getDescription());
View Full Code Here

    TokenErrorResponse errorResponse = new TokenErrorResponse();
    assertNull(errorResponse.getErrorObject());
    assertTrue(errorResponse.toJSONObject().isEmpty());

    HTTPResponse httpResponse = errorResponse.toHTTPResponse();
    assertEquals(400, httpResponse.getStatusCode());
    assertNull(httpResponse.getContentType());
    assertNull(httpResponse.getContent());

    errorResponse = TokenErrorResponse.parse(httpResponse);
    assertNull(errorResponse.getErrorObject());
    assertTrue(errorResponse.toJSONObject().isEmpty());
  }
View Full Code Here

    AuthorizationCode code = new AuthorizationCode("123");
    State state = new State("xyz");

    AuthenticationSuccessResponse successResponse = new AuthenticationSuccessResponse(redirectURI, code, null, null, state);

    HTTPResponse httpResponse = successResponse.toHTTPResponse();

    AuthenticationResponse response = AuthenticationResponseParser.parse(httpResponse);

    assertEquals(redirectURI, response.getRedirectionURI());
    assertEquals(state, response.getState());
View Full Code Here

    ResponseType rt = new ResponseType(ResponseType.Value.CODE);
    State state = new State("xyz");

    AuthenticationErrorResponse errorResponse = new AuthenticationErrorResponse(redirectURI, OAuth2Error.ACCESS_DENIED, rt, state);

    HTTPResponse httpResponse = errorResponse.toHTTPResponse();

    AuthenticationResponse response = AuthenticationResponseParser.parse(httpResponse);

    assertEquals(redirectURI, response.getRedirectionURI());
    assertEquals(state, response.getState());
View Full Code Here

 
  @Override
  public HTTPResponse toHTTPResponse()
    throws SerializeException {
 
    HTTPResponse httpResponse = new HTTPResponse(HTTPResponse.SC_OK);
   
    httpResponse.setContentType(CommonContentTypes.APPLICATION_JSON);
    httpResponse.setCacheControl("no-store");
    httpResponse.setPragma("no-cache");
   
    httpResponse.setContent(toJSONObject().toString());
   
    return httpResponse;
  }
View Full Code Here

  public HTTPResponse toHTTPResponse() {

    int statusCode = (error != null && error.getHTTPStatusCode() > 0) ?
      error.getHTTPStatusCode() : HTTPResponse.SC_BAD_REQUEST;

    HTTPResponse httpResponse = new HTTPResponse(statusCode);

    if (error == null)
      return httpResponse;
   
    httpResponse.setContentType(CommonContentTypes.APPLICATION_JSON);
    httpResponse.setCacheControl("no-store");
    httpResponse.setPragma("no-cache");
   
    httpResponse.setContent(toJSONObject().toString());
   
    return httpResponse;
  }
View Full Code Here

    assertNull(response.getRefreshToken());
    assertNull(response.getIDToken());
    assertNull(response.getIDTokenString());
    assertTrue(response.getCustomParams().isEmpty());

    HTTPResponse httpResponse = response.toHTTPResponse();

    response = OIDCAccessTokenResponse.parse(httpResponse);

    assertEquals("abc123", response.getAccessToken().getValue());
    assertNull(response.getRefreshToken());
View Full Code Here

    assertEquals("def456", response.getRefreshToken().getValue());
    assertEquals(ID_TOKEN_STRING, response.getIDTokenString());
    assertEquals(ID_TOKEN_STRING, response.getIDToken().serialize());
    assertTrue(response.getCustomParams().isEmpty());

    HTTPResponse httpResponse = response.toHTTPResponse();

    response = OIDCAccessTokenResponse.parse(httpResponse);

    assertEquals("abc123", response.getAccessToken().getValue());
    assertEquals("def456", response.getRefreshToken().getValue());
View Full Code Here

    assertEquals(ID_TOKEN_STRING, response.getIDToken().serialize());
    assertEquals("abc", (String)response.getCustomParams().get("sub_sid"));
    assertEquals(10, ((Number)response.getCustomParams().get("priority")).intValue());
    assertEquals(2, response.getCustomParams().size());

    HTTPResponse httpResponse = response.toHTTPResponse();

    response = OIDCAccessTokenResponse.parse(httpResponse);

    assertEquals("abc123", response.getAccessToken().getValue());
    assertEquals("def456", response.getRefreshToken().getValue());
View Full Code Here

TOP

Related Classes of com.nimbusds.oauth2.sdk.http.HTTPResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.