use of com.nimbusds.oauth2.sdk.id.Subject in project vitam-ui by ProgrammeVitam.
the class CustomTokenValidatorTest method setUp.
@Before
public void setUp() {
configuration = mock(OidcConfiguration.class);
final OIDCProviderMetadata metadata = mock(OIDCProviderMetadata.class);
when(metadata.getIssuer()).thenReturn(new Issuer(ISSUER));
when(configuration.findProviderMetadata()).thenReturn(metadata);
when(configuration.getClientId()).thenReturn(CLIENT_ID);
when(configuration.getSecret()).thenReturn(CLIENT_SECRET);
when(metadata.getIDTokenJWSAlgs()).thenReturn(Arrays.asList(JWSAlgorithm.HS256));
generator = new JwtGenerator(new SecretSignatureConfiguration(CLIENT_SECRET, JWSAlgorithm.HS256));
claims = new HashMap<>();
claims.put("iss", ISSUER);
claims.put("sub", SUBJECT);
claims.put("aud", CLIENT_ID);
final long now = new Date().getTime() / 1000;
claims.put("exp", now + 1000);
claims.put("iat", now);
nonce = new Nonce();
claims.put("nonce", nonce.toString());
validator = new CustomTokenValidator(configuration);
}
use of com.nimbusds.oauth2.sdk.id.Subject in project product-is by wso2.
the class OIDCAuthzCodeIdTokenValidationTestCase method testAuthCodeGrantSendGetTokensPost.
@Test(groups = "wso2.is", description = "Send get access token request.", dependsOnMethods = "testAuthCodeGrantSendApprovalPost")
public void testAuthCodeGrantSendGetTokensPost() throws Exception {
ClientID clientID = new ClientID(consumerKey);
Secret clientSecret = new Secret(consumerSecret);
ClientSecretBasic clientSecretBasic = new ClientSecretBasic(clientID, clientSecret);
URI callbackURI = new URI(CALLBACK_URL);
AuthorizationCodeGrant authorizationCodeGrant = new AuthorizationCodeGrant(authorizationCode, callbackURI);
TokenRequest tokenReq = new TokenRequest(new URI(OAuth2Constant.ACCESS_TOKEN_ENDPOINT), clientSecretBasic, authorizationCodeGrant);
HTTPResponse tokenHTTPResp = tokenReq.toHTTPRequest().send();
Assert.assertNotNull(tokenHTTPResp, "Access token http response is null.");
TokenResponse tokenResponse = OIDCTokenResponseParser.parse(tokenHTTPResp);
Assert.assertNotNull(tokenResponse, "Access token response is null.");
Assert.assertFalse(tokenResponse instanceof TokenErrorResponse, "Access token response contains errors.");
OIDCTokenResponse oidcTokenResponse = (OIDCTokenResponse) tokenResponse;
OIDCTokens oidcTokens = oidcTokenResponse.getOIDCTokens();
Assert.assertNotNull(oidcTokens, "OIDC Tokens object is null.");
idToken = oidcTokens.getIDTokenString();
Assert.assertNotNull(idToken, "ID token is null");
JWTClaimsSet jwtClaimsSet = SignedJWT.parse(idToken).getJWTClaimsSet();
Assert.assertEquals(jwtClaimsSet.getClaim("nonce"), TEST_NONCE, "Invalid nonce received.");
Assert.assertEquals(jwtClaimsSet.getSubject(), userId, "Invalid subject received.");
Assert.assertEquals(jwtClaimsSet.getIssuer(), "https://localhost:9853/oauth2/token", "Invalid issuer received.");
}
use of com.nimbusds.oauth2.sdk.id.Subject in project Kustvakt by KorAP.
the class OpenIdTokenService method createIdTokenClaims.
private JWTClaimsSet createIdTokenClaims(String client_id, String username, ZonedDateTime authenticationTime, String nonce) throws KustvaktException {
// A locally unique and never reassigned identifier within the
// Issuer for the End-User
Subject sub = new Subject(username);
Issuer iss = new Issuer(config.getIssuerURI());
Audience aud = new Audience(client_id);
ArrayList<Audience> audList = new ArrayList<Audience>(1);
audList.add(aud);
Date iat = TimeUtils.getNow().toDate();
Date exp = TimeUtils.getNow().plusSeconds(config.getTokenTTL()).toDate();
IDTokenClaimsSet claims = new IDTokenClaimsSet(iss, sub, audList, exp, iat);
Date authTime = Date.from(authenticationTime.toInstant());
claims.setAuthenticationTime(authTime);
if (nonce != null && !nonce.isEmpty()) {
claims.setNonce(new Nonce(nonce));
}
try {
return claims.toJWTClaimsSet();
} catch (ParseException e) {
throw new KustvaktException(StatusCodes.ID_TOKEN_CLAIM_ERROR, e.getMessage());
}
}
use of com.nimbusds.oauth2.sdk.id.Subject in project OpenConext-oidcng by OpenConext.
the class TokenEndpointTest method clientSecretJWT.
private ClientSecretJWT clientSecretJWT(String issuer, String tokenEndPoint, String secret, Date expiration) throws JOSEException {
// Issuer and subject in client JWT assertion must designate the same client identifier
JWTAssertionDetails jwtAssertionDetails = new JWTAssertionDetails(new Issuer(issuer), new Subject(issuer), Audience.create(tokenEndPoint), expiration, null, null, null, null);
SignedJWT signedJWT = JWTAssertionFactory.create(jwtAssertionDetails, JWSAlgorithm.HS256, new Secret(secret));
return new ClientSecretJWT(signedJWT);
}
use of com.nimbusds.oauth2.sdk.id.Subject in project asgardeo-java-oidc-sdk by asgardeo.
the class IDTokenValidatorTest method testAudience.
@Test(dataProvider = "AudienceData")
public void testAudience(List<String> audience, Set<String> trustedAudience, String clientID, String azpValue) throws SSOAgentServerException, JOSEException {
Nonce nonce = new Nonce();
config.setTrustedAudience(trustedAudience);
config.setConsumerKey(new ClientID(clientID));
JWTClaimsSet claims = new JWTClaimsSet.Builder().issuer(config.getIssuer().getValue()).subject("alice").audience(audience).expirationTime(new Date()).issueTime(new Date()).claim("nonce", nonce.getValue()).claim("azp", azpValue).build();
SignedJWT idToken = new SignedJWT(new JWSHeader(JWSAlgorithm.RS256), claims);
JWSSigner signer = new RSASSASigner(key);
idToken.sign(signer);
IDTokenValidator validator = new IDTokenValidator(config, idToken);
IDTokenClaimsSet claimsSet = validator.validate(nonce);
List<Audience> audiences = claimsSet.getAudience();
audiences.forEach(aud -> assertTrue(trustedAudience.contains(aud.getValue())));
}
Aggregations