use of org.apache.cxf.rs.security.oidc.common.IdToken in project cxf by apache.
the class OIDCFlowTest method testAuthorizationCodeFlowRefreshToken.
@org.junit.Test
public void testAuthorizationCodeFlowRefreshToken() 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, String.join(" ", OidcUtils.getOpenIdScope(), OAuthConstants.REFRESH_TOKEN_SCOPE), "consumer-id-oidc");
assertNotNull(code);
// Now get the access token
client = WebClient.create(address, "consumer-id-oidc", "this-is-a-secret", null);
ClientAccessToken accessToken = OAuth2TestUtils.getAccessTokenWithAuthorizationCode(client, code, "consumer-id-oidc", null);
assertNotNull(accessToken.getTokenKey());
assertTrue(accessToken.getApprovedScope().contains("openid"));
IdToken idToken = getIdToken(accessToken, address + "keys/", "consumer-id-oidc");
assertNotNull(idToken);
Long issuedAt = idToken.getIssuedAt();
TimeUnit.SECONDS.sleep(1L);
accessToken = OAuthClientUtils.refreshAccessToken(client, new Consumer("consumer-id-oidc"), accessToken);
idToken = getIdToken(accessToken, address + "keys/", "consumer-id-oidc");
assertNotEquals(issuedAt, idToken.getIssuedAt());
}
use of org.apache.cxf.rs.security.oidc.common.IdToken in project cxf by apache.
the class IdTokenProviderImpl method getIdToken.
@Override
public IdToken getIdToken(String clientId, UserSubject authenticatedUser, List<String> scopes) {
IdToken token = new IdToken();
token.setIssuedAt(OAuthUtils.getIssuedAt());
token.setExpiryTime(token.getIssuedAt() + 60L);
token.setAudience(clientId);
token.setSubject(authenticatedUser.getLogin());
token.setIssuer("OIDC IdP");
return token;
}
Aggregations