use of io.jans.as.model.common.GrantType in project jans by JanssenProject.
the class TokenEncryptionHttpDeprecated method requestIdTokenAlgA256KWEncA256GCM.
@Parameters({ "userId", "userSecret", "redirectUris", "sectorIdentifierUri" })
// @Test // Before run this test, set openidScopeBackwardCompatibility to true
@Deprecated
public void requestIdTokenAlgA256KWEncA256GCM(final String userId, final String userSecret, final String redirectUris, final String sectorIdentifierUri) {
try {
showTitle("requestIdTokenAlgA256KWEncA256GCM");
List<GrantType> grantTypes = Arrays.asList(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
// 1. Dynamic Client Registration
RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "jans test app", StringUtils.spaceSeparatedToList(redirectUris));
registerRequest.setIdTokenEncryptedResponseAlg(KeyEncryptionAlgorithm.A256KW);
registerRequest.setIdTokenEncryptedResponseEnc(BlockEncryptionAlgorithm.A256GCM);
registerRequest.addCustomAttribute("jansTrustedClnt", "true");
registerRequest.setSectorIdentifierUri(sectorIdentifierUri);
registerRequest.setGrantTypes(grantTypes);
RegisterClient registerClient = new RegisterClient(registrationEndpoint);
registerClient.setRequest(registerRequest);
RegisterResponse response = registerClient.exec();
showClient(registerClient);
assertRegisterResponseOk(response, 200, false);
String clientId = response.getClientId();
String clientSecret = response.getClientSecret();
// 2. Request authorization
TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
tokenRequest.setUsername(userId);
tokenRequest.setPassword(userSecret);
tokenRequest.setScope("openid");
tokenRequest.setAuthUsername(clientId);
tokenRequest.setAuthPassword(clientSecret);
TokenClient tokenClient = new TokenClient(tokenEndpoint);
tokenClient.setRequest(tokenRequest);
TokenResponse tokenResponse = tokenClient.exec();
showClient(tokenClient);
assertTokenResponseOk(tokenResponse, true);
assertNotNull(tokenResponse.getScope(), "The scope is null");
assertNotNull(tokenResponse.getIdToken(), "The id token is null");
String idToken = tokenResponse.getIdToken();
// 3. Read Encrypted ID Token
Jwe jwe = Jwe.parse(idToken, null, clientSecret.getBytes(StandardCharsets.UTF_8));
assertJweStandarClaimsNotNull(jwe, false);
assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.OX_OPENID_CONNECT_VERSION));
} catch (Exception ex) {
fail(ex.getMessage(), ex);
}
}
use of io.jans.as.model.common.GrantType in project jans by JanssenProject.
the class TokenEncryptionHttpDeprecated method requestIdTokenAlgRSA15EncA128CBCPLUSHS256.
@Parameters({ "userId", "userSecret", "redirectUris", "clientJwksUri", "RS256_enc_keyId", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri" })
// @Test // Before run this test, set openidScopeBackwardCompatibility to true
@Deprecated
public void requestIdTokenAlgRSA15EncA128CBCPLUSHS256(final String userId, final String userSecret, final String redirectUris, final String jwksUri, final String keyId, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) {
try {
showTitle("requestIdTokenAlgRSA15EncA128CBCPLUSHS256");
List<GrantType> grantTypes = Arrays.asList(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
// 1. Dynamic Client Registration
RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "jans test app", StringUtils.spaceSeparatedToList(redirectUris));
registerRequest.setJwksUri(jwksUri);
registerRequest.setIdTokenEncryptedResponseAlg(KeyEncryptionAlgorithm.RSA1_5);
registerRequest.setIdTokenEncryptedResponseEnc(BlockEncryptionAlgorithm.A128CBC_PLUS_HS256);
registerRequest.addCustomAttribute("jansTrustedClnt", "true");
registerRequest.setSectorIdentifierUri(sectorIdentifierUri);
registerRequest.setGrantTypes(grantTypes);
RegisterClient registerClient = new RegisterClient(registrationEndpoint);
registerClient.setRequest(registerRequest);
RegisterResponse response = registerClient.exec();
showClient(registerClient);
assertRegisterResponseOk(response, 200, false);
String clientId = response.getClientId();
String clientSecret = response.getClientSecret();
// 2. Request authorization
TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
tokenRequest.setUsername(userId);
tokenRequest.setPassword(userSecret);
tokenRequest.setScope("openid");
tokenRequest.setAuthUsername(clientId);
tokenRequest.setAuthPassword(clientSecret);
TokenClient tokenClient = new TokenClient(tokenEndpoint);
tokenClient.setRequest(tokenRequest);
TokenResponse tokenResponse = tokenClient.exec();
showClient(tokenClient);
assertTokenResponseOk(tokenResponse, true);
assertNotNull(tokenResponse.getScope(), "The scope is null");
assertNotNull(tokenResponse.getIdToken(), "The id token is null");
String idToken = tokenResponse.getIdToken();
// 3. Read Encrypted ID Token
AuthCryptoProvider cryptoProvider = new AuthCryptoProvider(keyStoreFile, keyStoreSecret, null);
PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId);
Jwe jwe = Jwe.parse(idToken, privateKey, null);
assertJweStandarClaimsNotNull(jwe, false);
assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.OX_OPENID_CONNECT_VERSION));
} catch (Exception ex) {
fail(ex.getMessage(), ex);
}
}
use of io.jans.as.model.common.GrantType in project jans by JanssenProject.
the class TokenBindingHttpTest method tokenBindingWithImplicitFlow.
@Parameters({ "userId", "userSecret", "redirectUris", "redirectUri", "sectorIdentifierUri" })
@Test
public void tokenBindingWithImplicitFlow(final String userId, final String userSecret, final String redirectUris, final String redirectUri, final String sectorIdentifierUri) throws Exception {
showTitle("tokenBindingWithImplicitFlow");
List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN);
List<GrantType> grantTypes = Arrays.asList(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
// 1. Register client
RegisterResponse registerResponse = registerClientInternal(redirectUri, responseTypes, grantTypes, sectorIdentifierUri);
String clientId = registerResponse.getClientId();
// 2. Request authorization
AuthorizationResponse authorizationResponse = requestAuthorization(userId, userSecret, redirectUri, responseTypes, clientId);
Jwt jwt = Jwt.parse(authorizationResponse.getIdToken());
Assert.assertEquals(EXPECTED_ID_HASH, jwt.getClaims().getClaimAsJSON(JwtClaimName.CNF).optString(JwtClaimName.TOKEN_BINDING_HASH));
}
use of io.jans.as.model.common.GrantType in project jans by JanssenProject.
the class AuthorizationResponseModeJwtResponseTypeCodeSignedEncryptedHttpTest method ensureRequestObjectSignedbyRS256AlgorithmFails.
@Parameters({ "redirectUri", "redirectUris", "clientJwksUri", "RSA_OAEP_keyId", "RS256_keyId", "dnName", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri" })
// Enable FAPI to run this test!
@Test(enabled = false)
public void ensureRequestObjectSignedbyRS256AlgorithmFails(final String redirectUri, final String redirectUris, final String clientJwksUri, final String encryptionKeyId, final String signingKeyId, final String dnName, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) throws Exception {
showTitle("ensureRequestObjectSignedbyRS256AlgorithmFails");
List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE);
List<GrantType> GrantTypes = Arrays.asList(GrantType.AUTHORIZATION_CODE);
// 1. Dynamic Client Registration
RegisterResponse registerResponse = registerClient(redirectUris, responseTypes, GrantTypes, sectorIdentifierUri, clientJwksUri, SignatureAlgorithm.RS256, KeyEncryptionAlgorithm.RSA_OAEP, BlockEncryptionAlgorithm.A256GCM);
String clientId = registerResponse.getClientId();
// 2. Request authorization
List<String> scope = Arrays.asList("openid", "profile", "address", "email");
String state = UUID.randomUUID().toString();
String nonce = UUID.randomUUID().toString();
AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scope, redirectUri, null);
AuthCryptoProvider cryptoProvider1 = new AuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
JwtAuthorizationRequest jwsAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, SignatureAlgorithm.RS256, cryptoProvider1);
jwsAuthorizationRequest.setKeyId(signingKeyId);
// Added bad aud to request object claims
jwsAuthorizationRequest.setAud("https://www.other1.example.com/");
jwsAuthorizationRequest.setRedirectUri(redirectUri);
jwsAuthorizationRequest.setResponseMode(ResponseMode.JWT);
jwsAuthorizationRequest.setState(state);
// FAPI: nonce param is required
jwsAuthorizationRequest.setNonce(nonce);
// FAPI: require the request object to
jwsAuthorizationRequest.setNbf((int) Instant.now().getEpochSecond());
// contain an exp claim that has a
// lifetime of no longer than 60 minutes
// after the nbf claim
// FAPI: require the request object to
jwsAuthorizationRequest.setExp(jwsAuthorizationRequest.getNbf() + 3600);
// contain an exp claim that has a
// lifetime of no longer than 60
// minutes after the nbf claim
Jwt authJws = Jwt.parse(jwsAuthorizationRequest.getEncodedJwt());
JwkClient jwkClient = new JwkClient(jwksUri);
JwkResponse jwkResponse = jwkClient.exec();
String serverKeyId = jwkResponse.getKeyId(Algorithm.RSA_OAEP);
assertNotNull(serverKeyId);
JSONObject jwks = JwtUtil.getJSONWebKeys(jwksUri);
AuthCryptoProvider cryptoProvider2 = new AuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
privateKey = cryptoProvider2.getPrivateKey(encryptionKeyId);
JwtAuthorizationRequest jweAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, SignatureAlgorithm.RS256, cryptoProvider2);
jweAuthorizationRequest.setKeyId(serverKeyId);
jweAuthorizationRequest.setNestedPayload(authJws);
jweAuthorizationRequest.setKeyId(signingKeyId);
jweAuthorizationRequest.setResponseMode(ResponseMode.JWT);
jweAuthorizationRequest.setState(state);
jweAuthorizationRequest.setScopes(scope);
jweAuthorizationRequest.setResponseTypes(responseTypes);
jweAuthorizationRequest.setRedirectUri(redirectUri);
// FAPI: nonce param is required
jweAuthorizationRequest.setNonce(nonce);
// FAPI: require the request object to
jweAuthorizationRequest.setNbf((int) Instant.now().getEpochSecond());
// contain an exp claim that has a
// lifetime of no longer than 60 minutes
// after the nbf claim
// Added invalid exp value to request
jweAuthorizationRequest.setExp(jwsAuthorizationRequest.getNbf() + 3600);
// object which is 70 minutes in the
// future
String authJwe = jweAuthorizationRequest.getEncodedJwt(jwks);
authorizationRequest.setRequest(authJwe);
AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint);
authorizeClient.setRequest(authorizationRequest);
AuthorizationResponse authorizationResponse = authorizeClient.exec();
showClient(authorizeClient);
assertNotNull(authorizationResponse.getResponse());
Jwe response = Jwe.parse(authorizationResponse.getResponse(), privateKey, null);
assertJweResponse(response);
assertEquals(response.getClaims().getClaimAsString("error"), "invalid_request_object");
// Clear private key to do not affect to other tests
privateKey = null;
}
use of io.jans.as.model.common.GrantType in project jans by JanssenProject.
the class AuthorizationResponseModeJwtResponseTypeCodeSignedEncryptedHttpTest method ensureRequestObjectWithNoneSigningAlgorithmFails.
@Parameters({ "redirectUri", "redirectUris", "clientJwksUri", "RSA_OAEP_keyId", "PS256_keyId", "dnName", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri" })
// Enable FAPI to run this test!
@Test(enabled = false)
public void ensureRequestObjectWithNoneSigningAlgorithmFails(final String redirectUri, final String redirectUris, final String clientJwksUri, final String encryptionKeyId, final String signingKeyId, final String dnName, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) throws Exception {
showTitle("ensureRequestObjectWithNoneSigningAlgorithmFails");
List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE);
List<GrantType> GrantTypes = Arrays.asList(GrantType.AUTHORIZATION_CODE);
// 1. Dynamic Client Registration
RegisterResponse registerResponse = registerClient(redirectUris, responseTypes, GrantTypes, sectorIdentifierUri, clientJwksUri, SignatureAlgorithm.PS256, KeyEncryptionAlgorithm.RSA_OAEP, BlockEncryptionAlgorithm.A256GCM);
String clientId = registerResponse.getClientId();
// 2. Request authorization
List<String> scope = Arrays.asList("openid", "profile", "address", "email");
String state = UUID.randomUUID().toString();
String nonce = UUID.randomUUID().toString();
AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scope, redirectUri, null);
AuthCryptoProvider cryptoProvider1 = new AuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
JwtAuthorizationRequest jwsAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, SignatureAlgorithm.PS256, cryptoProvider1);
jwsAuthorizationRequest.setKeyId(signingKeyId);
// Added bad aud to request object claims
jwsAuthorizationRequest.setAud("https://www.other1.example.com/");
jwsAuthorizationRequest.setRedirectUri(redirectUri);
jwsAuthorizationRequest.setResponseMode(ResponseMode.JWT);
jwsAuthorizationRequest.setState(state);
// FAPI: nonce param is required
jwsAuthorizationRequest.setNonce(nonce);
// FAPI: require the request object to
jwsAuthorizationRequest.setNbf((int) Instant.now().getEpochSecond());
// contain an exp claim that has a
// lifetime of no longer than 60 minutes
// after the nbf claim
// FAPI: require the request object to
jwsAuthorizationRequest.setExp(jwsAuthorizationRequest.getNbf() + 3600);
// contain an exp claim that has a
// lifetime of no longer than 60
// minutes after the nbf claim
Jwt authJws = Jwt.parse(jwsAuthorizationRequest.getEncodedJwt());
JwkClient jwkClient = new JwkClient(jwksUri);
JwkResponse jwkResponse = jwkClient.exec();
String serverKeyId = jwkResponse.getKeyId(Algorithm.RSA_OAEP);
assertNotNull(serverKeyId);
JSONObject jwks = JwtUtil.getJSONWebKeys(jwksUri);
AuthCryptoProvider cryptoProvider2 = new AuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
privateKey = cryptoProvider2.getPrivateKey(encryptionKeyId);
JwtAuthorizationRequest jweAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, SignatureAlgorithm.NONE, cryptoProvider2);
jweAuthorizationRequest.setKeyId(serverKeyId);
jweAuthorizationRequest.setNestedPayload(authJws);
jweAuthorizationRequest.setKeyId(signingKeyId);
jweAuthorizationRequest.setResponseMode(ResponseMode.JWT);
jweAuthorizationRequest.setState(state);
jweAuthorizationRequest.setScopes(scope);
jweAuthorizationRequest.setResponseTypes(responseTypes);
jweAuthorizationRequest.setRedirectUri(redirectUri);
// FAPI: nonce param is required
jweAuthorizationRequest.setNonce(nonce);
// FAPI: require the request object to
jweAuthorizationRequest.setNbf((int) Instant.now().getEpochSecond());
// contain an exp claim that has a
// lifetime of no longer than 60 minutes
// after the nbf claim
// Added invalid exp value to request
jweAuthorizationRequest.setExp(jwsAuthorizationRequest.getNbf() + 3600);
// object which is 70 minutes in the
// future
String authJwe = jweAuthorizationRequest.getEncodedJwt(jwks);
authorizationRequest.setRequest(authJwe);
AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint);
authorizeClient.setRequest(authorizationRequest);
AuthorizationResponse authorizationResponse = authorizeClient.exec();
showClient(authorizeClient);
assertNotNull(authorizationResponse.getResponse());
Jwe response = Jwe.parse(authorizationResponse.getResponse(), privateKey, null);
assertJweResponse(response);
assertEquals(response.getClaims().getClaimAsString("error"), "invalid_request_object");
// Clear private key to do not affect to other tests
privateKey = null;
}
Aggregations