Package com.nimbusds.oauth2.sdk.id

Examples of com.nimbusds.oauth2.sdk.id.Audience


    throws Exception {

    IDTokenClaimsSet claimsSet = new IDTokenClaimsSet(
      new Issuer("iss"),
      new Subject("sub"),
      new Audience("aud").toSingleAudienceList(),
      new Date(),
      new Date());

    assertNull(claimsSet.getSubjectJWK());
View Full Code Here


    throws Exception {

    IDTokenClaimsSet claimsSet = new IDTokenClaimsSet(
      new Issuer("iss"),
      new Subject("sub"),
      new Audience("aud").toSingleAudienceList(),
      new Date(),
      new Date());

    assertNull(claimsSet.getSubjectJWK());
View Full Code Here

  public void testStringClaim() {

    IDTokenClaimsSet claimsSet = new IDTokenClaimsSet(
      new Issuer("iss"),
      new Subject("sub"),
      new Audience("aud").toSingleAudienceList(),
      new Date(),
      new Date());

    claimsSet.setClaim("xString", "apples");
View Full Code Here

  public void testNumberClaim() {

    IDTokenClaimsSet claimsSet = new IDTokenClaimsSet(
      new Issuer("iss"),
      new Subject("sub"),
      new Audience("aud").toSingleAudienceList(),
      new Date(),
      new Date());

    claimsSet.setClaim("xInteger", 10);
View Full Code Here

    throws Exception {

    IDTokenClaimsSet claimsSet = new IDTokenClaimsSet(
      new Issuer("iss"),
      new Subject("sub"),
      new Audience("aud").toSingleAudienceList(),
      new Date(),
      new Date());

    claimsSet.setURLClaim("xURL", new URL("http://example.com"));
View Full Code Here

  public void testRun()
    throws Exception {

    ClientID clientID = new ClientID("http://client.com");
    Audience audience = new Audience("http://idp.com");
    Date exp = DateUtils.fromSecondsSinceEpoch(new Date().getTime() / 1000 + 3600);
    Date nbf = DateUtils.fromSecondsSinceEpoch(new Date().getTime() / 1000);
    Date iat = DateUtils.fromSecondsSinceEpoch(new Date().getTime() / 1000);
    JWTID jti = new JWTID();

    JWTAuthenticationClaimsSet assertion = new JWTAuthenticationClaimsSet(clientID, audience, exp, nbf, iat, jti);

    System.out.println("Client secret JWT claims set: " + assertion.toJSONObject());


    JWSHeader jwsHeader = new JWSHeader(JWSAlgorithm.HS256);

    SignedJWT jwt = new SignedJWT(jwsHeader, assertion.toJWTClaimsSet());

    Secret secret = new Secret();

    MACSigner signer = new MACSigner(secret.getValueBytes());

    jwt.sign(signer);

    ClientSecretJWT clientSecretJWT = new ClientSecretJWT(jwt);

    Map<String,String> params = clientSecretJWT.toParameters();
    params.put("client_id", clientID.getValue()); // add optional client_id to test parser

    System.out.println("Client secret JWT: " + params);

    clientSecretJWT = ClientSecretJWT.parse(params);

    assertEquals("http://client.com", clientSecretJWT.getClientID().getValue());

    jwt = clientSecretJWT.getClientAssertion();

    assertTrue(jwt.getState().equals(JWSObject.State.SIGNED));

    MACVerifier verifier = new MACVerifier(secret.getValueBytes());

    boolean verified = jwt.verify(verifier);

    assertTrue(verified);

    assertion = clientSecretJWT.getJWTAuthenticationClaimsSet();

    assertEquals(clientID.getValue(), assertion.getClientID().getValue());
    assertEquals(clientID.getValue(), assertion.getIssuer().getValue());
    assertEquals(clientID.getValue(), assertion.getSubject().getValue());
    assertEquals(audience.getValue(), assertion.getAudience().getValue());
    assertEquals(exp.getTime(), assertion.getExpirationTime().getTime());
    assertEquals(nbf.getTime(), assertion.getNotBeforeTime().getTime());
    assertEquals(iat.getTime(), assertion.getIssueTime().getTime());
    assertEquals(jti.getValue(), assertion.getJWTID().getValue());
View Full Code Here

   */
  public List<Audience> getAudience() {

    if (getClaim(AUD_CLAIM_NAME) instanceof String) {
      // Special case - aud is a string
      return new Audience(getStringClaim(AUD_CLAIM_NAME)).toSingleAudienceList();
    }

    // General case - JSON string array
    List<String> rawList = getStringListClaim(AUD_CLAIM_NAME);

    List<Audience> audList = new ArrayList<>(rawList.size());

    for (String s: rawList)
      audList.add(new Audience(s));

    return audList;
  }
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.id.Audience

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.