use of org.apache.cxf.systest.jaxrs.security.oauth2.common.OAuth2TestUtils.AuthorizationCodeParameters in project cxf by apache.
the class OIDCFlowTest method testAuthorizationCodeFlowUnsignedJWT.
@org.junit.Test
public void testAuthorizationCodeFlowUnsignedJWT() throws Exception {
String address = "https://localhost:" + port + "/unsignedjwtservices/";
WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "alice", "security", null);
// Save the Cookie for the second request...
WebClient.getConfig(client).getRequestContext().put(org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
JwtClaims claims = new JwtClaims();
claims.setIssuer("consumer-id");
claims.setIssuedAt(Instant.now().getEpochSecond());
claims.setAudiences(Collections.singletonList("https://localhost:" + port + "/unsignedjwtservices/"));
JwsHeaders headers = new JwsHeaders();
headers.setAlgorithm("none");
JwtToken token = new JwtToken(headers, claims);
JwsJwtCompactProducer jws = new JwsJwtCompactProducer(token);
String request = jws.getSignedEncodedJws();
// Get Authorization Code
AuthorizationCodeParameters parameters = new AuthorizationCodeParameters();
parameters.setConsumerId("consumer-id");
parameters.setScope("openid");
parameters.setResponseType("code");
parameters.setPath("authorize/");
parameters.setRequest(request);
String location = OAuth2TestUtils.getLocation(client, parameters);
String code = OAuth2TestUtils.getSubstring(location, "code");
assertNotNull(code);
}
use of org.apache.cxf.systest.jaxrs.security.oauth2.common.OAuth2TestUtils.AuthorizationCodeParameters in project cxf by apache.
the class OIDCFlowTest method testAuthorizationCodeFlowUnsignedJWTWithState.
@org.junit.Test
public void testAuthorizationCodeFlowUnsignedJWTWithState() throws Exception {
String address = "https://localhost:" + port + "/unsignedjwtservices/";
WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "alice", "security", null);
// Save the Cookie for the second request...
WebClient.getConfig(client).getRequestContext().put(org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
JwtClaims claims = new JwtClaims();
claims.setIssuer("consumer-id");
claims.setIssuedAt(Instant.now().getEpochSecond());
claims.setAudiences(Collections.singletonList("https://localhost:" + port + "/unsignedjwtservices/"));
JwsHeaders headers = new JwsHeaders();
headers.setAlgorithm("none");
JwtToken token = new JwtToken(headers, claims);
JwsJwtCompactProducer jws = new JwsJwtCompactProducer(token);
String request = jws.getSignedEncodedJws();
// Get Authorization Code
AuthorizationCodeParameters parameters = new AuthorizationCodeParameters();
parameters.setConsumerId("consumer-id");
parameters.setScope("openid");
parameters.setResponseType("code");
parameters.setPath("authorize/");
parameters.setState("123456789");
parameters.setRequest(request);
String location = OAuth2TestUtils.getLocation(client, parameters);
String code = OAuth2TestUtils.getSubstring(location, "code");
assertNotNull(code);
}
use of org.apache.cxf.systest.jaxrs.security.oauth2.common.OAuth2TestUtils.AuthorizationCodeParameters in project cxf by apache.
the class OIDCFlowTest method testHybridCodeToken.
@org.junit.Test
public void testHybridCodeToken() throws Exception {
String address = "https://localhost:" + port + "/services/";
WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "alice", "security", null);
// Save the Cookie for the second request...
WebClient.getConfig(client).getRequestContext().put(org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
// Get location
AuthorizationCodeParameters parameters = new AuthorizationCodeParameters();
parameters.setConsumerId("consumer-id");
parameters.setScope("openid");
parameters.setNonce("123456789");
parameters.setResponseType("code token");
parameters.setPath("authorize-hybrid/");
String location = OAuth2TestUtils.getLocation(client, parameters);
assertNotNull(location);
// Check code
String code = OAuth2TestUtils.getSubstring(location, "code");
assertNotNull(code);
// Check id_token
String idToken = OAuth2TestUtils.getSubstring(location, "id_token");
assertNull(idToken);
// Check Access Token
String implicitAccessToken = OAuth2TestUtils.getSubstring(location, "access_token");
assertNotNull(implicitAccessToken);
idToken = OAuth2TestUtils.getSubstring(location, "id_token");
assertNull(idToken);
// Now get the access token with the code
client = WebClient.create(address, "consumer-id", "this-is-a-secret", null);
ClientAccessToken accessToken = OAuth2TestUtils.getAccessTokenWithAuthorizationCode(client, code);
assertNotNull(accessToken.getTokenKey());
assertTrue(accessToken.getApprovedScope().contains("openid"));
// Check id_token from the token endpoint
idToken = accessToken.getParameters().get("id_token");
assertNotNull(idToken);
validateIdToken(idToken, null);
// check the code hash is returned from the token endpoint
JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(idToken);
// returning c_hash in the id_token returned after exchanging the code is optional
assertNull(jwtConsumer.getJwtClaims().getClaim(IdToken.AUTH_CODE_HASH_CLAIM));
if (isAccessTokenInJWTFormat()) {
validateAccessToken(accessToken.getTokenKey());
}
}
use of org.apache.cxf.systest.jaxrs.security.oauth2.common.OAuth2TestUtils.AuthorizationCodeParameters in project cxf by apache.
the class OIDCFlowTest method testHybridCodeIdTokenToken.
@org.junit.Test
public void testHybridCodeIdTokenToken() throws Exception {
String address = "https://localhost:" + port + "/services/";
WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "alice", "security", null);
// Save the Cookie for the second request...
WebClient.getConfig(client).getRequestContext().put(org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
// Get location
AuthorizationCodeParameters parameters = new AuthorizationCodeParameters();
parameters.setConsumerId("consumer-id");
parameters.setScope("openid");
parameters.setNonce("123456789");
parameters.setResponseType("code id_token token");
parameters.setPath("authorize-hybrid/");
String location = OAuth2TestUtils.getLocation(client, parameters);
assertNotNull(location);
// Check code
String code = OAuth2TestUtils.getSubstring(location, "code");
assertNotNull(code);
// Check id_token
String idToken = OAuth2TestUtils.getSubstring(location, "id_token");
assertNotNull(idToken);
validateIdToken(idToken, "123456789");
// check the code hash is returned from the implicit authorization endpoint
JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(idToken);
JwtToken jwt = jwtConsumer.getJwtToken();
assertNotNull(jwt.getClaims().getClaim(IdToken.AUTH_CODE_HASH_CLAIM));
// Check Access Token
String accessToken = OAuth2TestUtils.getSubstring(location, "access_token");
assertNotNull(accessToken);
jwtConsumer = new JwsJwtCompactConsumer(idToken);
jwt = jwtConsumer.getJwtToken();
assertNotNull(jwt.getClaims().getClaim(IdToken.ACCESS_TOKEN_HASH_CLAIM));
OidcUtils.validateAccessTokenHash(accessToken, jwt, true);
assertNotNull(jwt.getClaims().getClaim(IdToken.AUTH_CODE_HASH_CLAIM));
if (isAccessTokenInJWTFormat()) {
validateAccessToken(accessToken);
}
}
use of org.apache.cxf.systest.jaxrs.security.oauth2.common.OAuth2TestUtils.AuthorizationCodeParameters in project cxf by apache.
the class PublicClientTest method testAuthorizationCodeGrantNoRedirectURI.
@org.junit.Test
public void testAuthorizationCodeGrantNoRedirectURI() throws Exception {
URL busFile = PublicClientTest.class.getResource("publicclient.xml");
String address = "https://localhost:" + port + "/services/";
WebClient client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "alice", "security", busFile.toString());
// Save the Cookie for the second request...
WebClient.getConfig(client).getRequestContext().put(org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
// Get Authorization Code
try {
// Get Authorization Code
AuthorizationCodeParameters parameters = new AuthorizationCodeParameters();
parameters.setConsumerId("fredPublic");
String codeVerifier = Base64UrlUtility.encode(CryptoUtils.generateSecureRandomBytes(32));
CodeVerifierTransformer transformer = new PlainCodeVerifier();
parameters.setCodeChallenge(transformer.transformCodeVerifier(codeVerifier));
parameters.setCodeChallengeMethod(transformer.getChallengeMethod());
parameters.setResponseType(OAuthConstants.CODE_RESPONSE_TYPE);
parameters.setPath("authorize/");
OAuth2TestUtils.getLocation(client, parameters);
fail("Failure expected on a missing (registered) redirectURI");
} catch (Exception ex) {
// expected
}
}
Aggregations