Package com.nimbusds.oauth2.sdk

Examples of com.nimbusds.oauth2.sdk.ParseException


    throws SerializeException {
   
    if (getEndpointURI() == null)
      throw new SerializeException("The endpoint URI is not specified");
   
    HTTPRequest httpRequest;

    URL endpointURL;

    try {
      endpointURL = getEndpointURI().toURL();

    } catch (MalformedURLException e) {

      throw new SerializeException(e.getMessage(), e);
    }
   
    if (method.equals(HTTPRequest.Method.GET)) {

      httpRequest = new HTTPRequest(HTTPRequest.Method.GET, endpointURL);

    } else if (method.equals(HTTPRequest.Method.POST)) {

      httpRequest = new HTTPRequest(HTTPRequest.Method.POST, endpointURL);

    } else {

      throw new IllegalArgumentException("The HTTP request method must be GET or POST");
    }
   
    httpRequest.setQuery(toQueryString());
   
    return httpRequest;
  }
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

   
    // Parse required claims
    Issuer iss = new Issuer(JSONObjectUtils.getString(jsonObject, "iss"));
    Subject sub = new Subject(JSONObjectUtils.getString(jsonObject, "sub"));

    Audience aud;

    if (jsonObject.get("aud") instanceof String) {

      aud = new Audience(JSONObjectUtils.getString(jsonObject, "aud"));

    } else {
      String[] audList = JSONObjectUtils.getStringArray(jsonObject, "aud");

      if (audList.length > 1)
        throw new ParseException("Multiple audiences (aud) not supported");

      aud = new Audience(audList[0]);
    }

    Date exp = DateUtils.fromSecondsSinceEpoch(JSONObjectUtils.getLong(jsonObject, "exp"));

View Full Code Here

   *
   * @return The client identifier.
   */
  public ClientID getClientID() {

    return new ClientID(iss.getValue());
  }
View Full Code Here

    // Check client ID

    if (! iss.getValue().equals(sub.getValue()))
      throw new ParseException("JWT issuer and subject must have the same client ID");

    ClientID clientID = new ClientID(iss.getValue());

    return new JWTAuthenticationClaimsSet(clientID, aud, exp, nbf, iat, jti);
  }
View Full Code Here

    String secretValue = params.get("client_secret");
   
    if (secretValue == null)
      throw new ParseException("Missing \"client_secret\" parameter");
   
    return new ClientSecretPost(new ClientID(clientIDString), new Secret(secretValue));
  }
View Full Code Here

TOP

Related Classes of com.nimbusds.oauth2.sdk.ParseException

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.