Package com.nimbusds.oauth2.sdk.auth

Examples of com.nimbusds.oauth2.sdk.auth.JWTAuthentication


    TokenRevocationRequest request = new TokenRevocationRequest(endpointURI, null, token);
    assertEquals(endpointURI, request.getEndpointURI());
    assertNull(request.getClientAuthentication());
    assertEquals(token, request.getToken());

    HTTPRequest httpRequest = request.toHTTPRequest();
    assertEquals(HTTPRequest.Method.POST, httpRequest.getMethod());
    assertEquals(endpointURI.toURL().toString(), httpRequest.getURL().toString());
    assertEquals(CommonContentTypes.APPLICATION_URLENCODED, httpRequest.getContentType());
    assertNull(httpRequest.getAuthorization());

    assertEquals(token.getValue(), httpRequest.getQueryParameters().get("token"));
    assertEquals("refresh_token", httpRequest.getQueryParameters().get("token_type_hint"));
    assertEquals(2, httpRequest.getQueryParameters().size());
  }
View Full Code Here


    TokenRevocationRequest request = new TokenRevocationRequest(endpointURI, clientAuth, token);
    assertEquals(endpointURI, request.getEndpointURI());
    assertEquals(clientAuth, request.getClientAuthentication());
    assertEquals(token, request.getToken());

    HTTPRequest httpRequest = request.toHTTPRequest();
    assertEquals(HTTPRequest.Method.POST, httpRequest.getMethod());
    assertEquals(endpointURI.toURL().toString(), httpRequest.getURL().toString());
    assertEquals(CommonContentTypes.APPLICATION_URLENCODED, httpRequest.getContentType());

    assertEquals(token.getValue(), httpRequest.getQueryParameters().get("token"));
    assertEquals("refresh_token", httpRequest.getQueryParameters().get("token_type_hint"));
    assertEquals(2, httpRequest.getQueryParameters().size());

    ClientSecretBasic basicAuth = ClientSecretBasic.parse(httpRequest.getAuthorization());
    assertEquals("123", basicAuth.getClientID().getValue());
    assertEquals("secret", basicAuth.getClientSecret().getValue());
  }
View Full Code Here


  public void testWithUnknownToken()
    throws Exception {

    HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.POST, new URL("https://c2id.com/token/revoke"));
    httpRequest.setContentType(CommonContentTypes.APPLICATION_URLENCODED);

    Map<String,String> queryParams = new HashMap<>();
    queryParams.put("token", "abc");
    httpRequest.setQuery(URLUtils.serializeParameters(queryParams));

    TokenRevocationRequest request = TokenRevocationRequest.parse(httpRequest);
    assertEquals("abc", request.getToken().getValue());
    assertFalse(request.getToken() instanceof AccessToken);
    assertFalse(request.getToken() instanceof RefreshToken);
View Full Code Here

    URI uri = resp.toURI();

    System.out.println("Location: " + uri);

    HTTPResponse httpResponse = resp.toHTTPResponse();
    assertEquals(302, httpResponse.getStatusCode());
    assertEquals(uri, httpResponse.getLocation());

    resp = AuthorizationSuccessResponse.parse(httpResponse);

    assertEquals(ABS_REDIRECT_URI, resp.getRedirectionURI());
    assertEquals(TOKEN, resp.getAccessToken());
View Full Code Here

    TokenErrorResponse r = new TokenErrorResponse(err);
   
    assertEquals(OAuth2Error.INVALID_REQUEST, r.getErrorObject());
   

    HTTPResponse httpResponse = r.toHTTPResponse();
   
    assertEquals(HTTPResponse.SC_BAD_REQUEST, httpResponse.getStatusCode());
    assertEquals(CommonContentTypes.APPLICATION_JSON, httpResponse.getContentType());
    assertEquals("no-store", httpResponse.getCacheControl());
    assertEquals("no-cache", httpResponse.getPragma());
   
   
    JSONObject jsonObject = JSONObjectUtils.parseJSONObject(httpResponse.getContent())

    assertEquals(OAuth2Error.INVALID_REQUEST.getCode(), (String)jsonObject.get("error"));
    assertEquals(OAuth2Error.INVALID_REQUEST.getDescription(), (String)jsonObject.get("error_description"));
    assertEquals(ERROR_PAGE_URI.toString(), (String)jsonObject.get("error_uri"));
    assertEquals(3, jsonObject.size());
View Full Code Here


  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

TOP

Related Classes of com.nimbusds.oauth2.sdk.auth.JWTAuthentication

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.