Package com.nimbusds.oauth2.sdk.http

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


    AccessToken accessToken = new BearerAccessToken("abc123");
    RefreshToken refreshToken = new RefreshToken("def456");

    OIDCAccessTokenResponse response = new OIDCAccessTokenResponse(accessToken, refreshToken, ID_TOKEN);

    HTTPResponse httpResponse = response.toHTTPResponse();

    TokenResponse tokenResponse = OIDCTokenResponseParser.parse(httpResponse);

    assertTrue(tokenResponse instanceof OIDCAccessTokenResponse);
View Full Code Here


  public void testParseError()
    throws Exception {

    TokenErrorResponse response = new TokenErrorResponse(OAuth2Error.INVALID_GRANT);

    HTTPResponse httpResponse = response.toHTTPResponse();

    TokenResponse tokenResponse = OIDCTokenResponseParser.parse(httpResponse);

    assertTrue(tokenResponse instanceof TokenErrorResponse);
View Full Code Here

 
  @Override
  public HTTPResponse toHTTPResponse()
    throws SerializeException {
 
    HTTPResponse httpResponse = new HTTPResponse(HTTPResponse.SC_OK);
   
    httpResponse.setContentType(getContentType());
   
    String content;
   
    if (claimsSet != null) {
   
      content = claimsSet.toJSONObject().toString();

    } else {
     
      try {
        content = jwt.serialize();
       
      } catch (IllegalStateException e) {
     
        throw new SerializeException("Couldn't serialize UserInfo claims JWT: " +
                               e.getMessage(), e);
      }
    }
   
    httpResponse.setContent(content);
 
    return httpResponse;
  }
View Full Code Here

   * @return The HTTP response matching this UserInfo error response.
   */
  @Override
  public HTTPResponse toHTTPResponse() {

    HTTPResponse httpResponse;

    if (error != null && error.getHTTPStatusCode() > 0)
      httpResponse = new HTTPResponse(error.getHTTPStatusCode());
    else
      httpResponse = new HTTPResponse(HTTPResponse.SC_BAD_REQUEST);

    // Add the WWW-Authenticate header
    if (error != null)
      httpResponse.setWWWAuthenticate(error.toWWWAuthenticateHeader());

    return httpResponse;
  }
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

      throw new ParseException(e.getMessage(), e);
    }

    // Check that the top level client_id matches the assertion subject + issuer

    ClientID clientID = JWTAuthentication.parseClientID(params);

    if (clientID != null) {

      if (! clientID.equals(privateKeyJWT.getClientID()))
        throw new ParseException("The client identifier doesn't match the client assertion subject / issuer");
    }

    return privateKeyJWT;
  }
View Full Code Here

    if (clientAuth == null && grant.getType().requiresClientAuthentication()) {
      throw new ParseException("Missing client authentication", OAuth2Error.INVALID_CLIENT);
    }

    // Parse client id
    ClientID clientID = null;

    if (clientAuth == null) {

      // Parse optional client ID
      String clientIDString = params.get("client_id");

      if (clientIDString != null && clientIDString.trim().length() > 0)
        clientID = new ClientID(clientIDString);

      if (clientID == null && grant.getType().requiresClientID()) {
        throw new ParseException("Missing required \"client_id\" parameter", OAuth2Error.INVALID_REQUEST);
      }
    }
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.