Search in sources :

Example 11 with IdToken

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());
}
Also used : IdToken(org.apache.cxf.rs.security.oidc.common.IdToken) JwsJwtCompactConsumer(org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer) Consumer(org.apache.cxf.rs.security.oauth2.client.Consumer) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) WebClient(org.apache.cxf.jaxrs.client.WebClient)

Example 12 with IdToken

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;
}
Also used : IdToken(org.apache.cxf.rs.security.oidc.common.IdToken)

Aggregations

IdToken (org.apache.cxf.rs.security.oidc.common.IdToken)12 ClientTokenContext (org.apache.cxf.rs.security.oauth2.client.ClientTokenContext)2 OAuthServiceException (org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException)2 Calendar (java.util.Calendar)1 Date (java.util.Date)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 MessageContextImpl (org.apache.cxf.jaxrs.ext.MessageContextImpl)1 JwsJwtCompactConsumer (org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer)1 JwtException (org.apache.cxf.rs.security.jose.jwt.JwtException)1 JwtToken (org.apache.cxf.rs.security.jose.jwt.JwtToken)1 Consumer (org.apache.cxf.rs.security.oauth2.client.Consumer)1 AccessTokenRegistration (org.apache.cxf.rs.security.oauth2.common.AccessTokenRegistration)1 Client (org.apache.cxf.rs.security.oauth2.common.Client)1 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)1 ServerAccessToken (org.apache.cxf.rs.security.oauth2.common.ServerAccessToken)1 UserInfo (org.apache.cxf.rs.security.oidc.common.UserInfo)1 Test (org.junit.Test)1