use of org.apache.cxf.rs.security.oauth2.common.Client in project cxf by apache.
the class OIDCFlowTest method testAuthorizationCodeFlowWithRefresh.
@org.junit.Test
public void testAuthorizationCodeFlowWithRefresh() 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 Authorization Code
String code = OAuth2TestUtils.getAuthorizationCode(client, "openid");
assertNotNull(code);
// Now get the access token
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"));
assertNotNull(accessToken.getRefreshToken());
String idToken = accessToken.getParameters().get("id_token");
assertNotNull(idToken);
validateIdToken(idToken, null);
// Refresh the access token
client = WebClient.create(address, OAuth2TestUtils.setupProviders(), "consumer-id", "this-is-a-secret", null);
client.path("token");
client.type("application/x-www-form-urlencoded").accept("application/json");
Form form = new Form();
form.param("grant_type", "refresh_token");
form.param("refresh_token", accessToken.getRefreshToken());
form.param("client_id", "consumer-id");
form.param("scope", "openid");
Response response = client.post(form);
accessToken = response.readEntity(ClientAccessToken.class);
assertNotNull(accessToken.getTokenKey());
assertNotNull(accessToken.getRefreshToken());
accessToken.getParameters().get("id_token");
assertNotNull(idToken);
if (isAccessTokenInJWTFormat()) {
validateAccessToken(accessToken.getTokenKey());
}
}
use of org.apache.cxf.rs.security.oauth2.common.Client in project cxf by apache.
the class OIDCFlowTest method testImplicitFlowNoAccessToken.
@org.junit.Test
public void testImplicitFlowNoAccessToken() 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 Access Token
client.type("application/json").accept("application/json");
client.query("client_id", "consumer-id");
client.query("redirect_uri", "http://www.blah.apache.org");
client.query("scope", "openid");
client.query("response_type", "id_token");
client.query("nonce", "123456789");
client.path("authorize-implicit/");
Response response = client.get();
OAuthAuthorizationData authzData = response.readEntity(OAuthAuthorizationData.class);
// Now call "decision" to get the access token
client.path("decision");
client.type("application/x-www-form-urlencoded");
Form form = new Form();
form.param("session_authenticity_token", authzData.getAuthenticityToken());
form.param("client_id", authzData.getClientId());
form.param("redirect_uri", authzData.getRedirectUri());
form.param("scope", authzData.getProposedScope());
if (authzData.getResponseType() != null) {
form.param("response_type", authzData.getResponseType());
}
if (authzData.getNonce() != null) {
form.param("nonce", authzData.getNonce());
}
form.param("oauthDecision", "allow");
response = client.post(form);
String location = response.getHeaderString("Location");
// Check Access Token - it should not be present
String accessToken = OAuth2TestUtils.getSubstring(location, "access_token");
assertNull(accessToken);
// Check IdToken
String idToken = OAuth2TestUtils.getSubstring(location, "id_token");
assertNotNull(idToken);
validateIdToken(idToken, null);
JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(idToken);
JwtToken jwt = jwtConsumer.getJwtToken();
assertNull(jwt.getClaims().getClaim(IdToken.ACCESS_TOKEN_HASH_CLAIM));
assertNotNull(jwt.getClaims().getClaim(IdToken.NONCE_CLAIM));
}
use of org.apache.cxf.rs.security.oauth2.common.Client in project cxf by apache.
the class OIDCFlowTest method testAuthorizationCodeFlowWithAudience.
@org.junit.Test
public void testAuthorizationCodeFlowWithAudience() 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 Authorization Code
String code = OAuth2TestUtils.getAuthorizationCode(client, "openid", "consumer-id-aud", null, null);
assertNotNull(code);
// Now get the access token
client = WebClient.create(address, "consumer-id-aud", "this-is-a-secret", null);
String audience = "https://localhost:" + port + "/secured/bookstore/books";
ClientAccessToken accessToken = OAuth2TestUtils.getAccessTokenWithAuthorizationCode(client, code, "consumer-id-aud", audience);
assertNotNull(accessToken.getTokenKey());
if (isAccessTokenInJWTFormat()) {
validateAccessToken(accessToken.getTokenKey());
}
}
use of org.apache.cxf.rs.security.oauth2.common.Client in project cxf by apache.
the class OIDCFlowTest method testAuthorizationCodeFlowWithNonce.
@org.junit.Test
public void testAuthorizationCodeFlowWithNonce() 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 Authorization Code
String code = OAuth2TestUtils.getAuthorizationCode(client, "openid", "consumer-id", "123456789", null);
assertNotNull(code);
// Now get the access token
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"));
String idToken = accessToken.getParameters().get("id_token");
assertNotNull(idToken);
validateIdToken(idToken, "123456789");
if (isAccessTokenInJWTFormat()) {
validateAccessToken(accessToken.getTokenKey());
}
}
use of org.apache.cxf.rs.security.oauth2.common.Client in project cxf by apache.
the class OIDCFlowTest method testAuthorizationCodeFlowWithScope.
@org.junit.Test
public void testAuthorizationCodeFlowWithScope() 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 Authorization Code
String code = OAuth2TestUtils.getAuthorizationCode(client, "openid read_balance");
assertNotNull(code);
// Now get the access token
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"));
assertTrue(accessToken.getApprovedScope().contains("read_balance"));
String idToken = accessToken.getParameters().get("id_token");
assertNotNull(idToken);
validateIdToken(idToken, null);
if (isAccessTokenInJWTFormat()) {
validateAccessToken(accessToken.getTokenKey());
}
}
Aggregations