Search in sources :

Example 6 with LogoutToken

use of org.keycloak.representations.LogoutToken in project keycloak by keycloak.

the class LogoutTest method testFrontChannelLogout.

@Test
public void testFrontChannelLogout() throws Exception {
    ClientsResource clients = adminClient.realm(oauth.getRealm()).clients();
    ClientRepresentation rep = clients.findByClientId(oauth.getClientId()).get(0);
    rep.setName("My Testing App");
    rep.setFrontchannelLogout(true);
    rep.getAttributes().put(OIDCConfigAttributes.FRONT_CHANNEL_LOGOUT_URI, oauth.APP_ROOT + "/admin/frontchannelLogout");
    clients.get(rep.getId()).update(rep);
    try {
        oauth.clientSessionState("client-session");
        oauth.doLogin("test-user@localhost", "password");
        String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
        OAuthClient.AccessTokenResponse tokenResponse = oauth.doAccessTokenRequest(code, "password");
        String idTokenString = tokenResponse.getIdToken();
        String logoutUrl = oauth.getLogoutUrl().idTokenHint(idTokenString).build();
        driver.navigate().to(logoutUrl);
        LogoutToken logoutToken = testingClient.testApp().getFrontChannelLogoutToken();
        Assert.assertNotNull(logoutToken);
        IDToken idToken = new JWSInput(idTokenString).readJsonContent(IDToken.class);
        Assert.assertEquals(logoutToken.getIssuer(), idToken.getIssuer());
        Assert.assertEquals(logoutToken.getSid(), idToken.getSessionId());
        assertTrue(driver.getTitle().equals("Logging out"));
        assertTrue(driver.getPageSource().contains("You are logging out from following apps"));
        assertTrue(driver.getPageSource().contains("My Testing App"));
    } finally {
        rep.setFrontchannelLogout(false);
        rep.getAttributes().put(OIDCConfigAttributes.FRONT_CHANNEL_LOGOUT_URI, "");
        clients.get(rep.getId()).update(rep);
    }
}
Also used : OAuthClient(org.keycloak.testsuite.util.OAuthClient) ClientsResource(org.keycloak.admin.client.resource.ClientsResource) LogoutToken(org.keycloak.representations.LogoutToken) IDToken(org.keycloak.representations.IDToken) JWSInput(org.keycloak.jose.jws.JWSInput) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 7 with LogoutToken

use of org.keycloak.representations.LogoutToken in project keycloak by keycloak.

the class LogoutTest method testFrontChannelLogoutWithPostLogoutRedirectUri.

@Test
public void testFrontChannelLogoutWithPostLogoutRedirectUri() throws Exception {
    ClientsResource clients = adminClient.realm(oauth.getRealm()).clients();
    ClientRepresentation rep = clients.findByClientId(oauth.getClientId()).get(0);
    rep.setFrontchannelLogout(true);
    rep.getAttributes().put(OIDCConfigAttributes.FRONT_CHANNEL_LOGOUT_URI, oauth.APP_ROOT + "/admin/frontchannelLogout");
    clients.get(rep.getId()).update(rep);
    try {
        oauth.clientSessionState("client-session");
        oauth.doLogin("test-user@localhost", "password");
        String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
        OAuthClient.AccessTokenResponse tokenResponse = oauth.doAccessTokenRequest(code, "password");
        String idTokenString = tokenResponse.getIdToken();
        String logoutUrl = oauth.getLogoutUrl().idTokenHint(idTokenString).postLogoutRedirectUri(oauth.APP_AUTH_ROOT).build();
        driver.navigate().to(logoutUrl);
        LogoutToken logoutToken = testingClient.testApp().getFrontChannelLogoutToken();
        Assert.assertNotNull(logoutToken);
        IDToken idToken = new JWSInput(idTokenString).readJsonContent(IDToken.class);
        Assert.assertEquals(logoutToken.getIssuer(), idToken.getIssuer());
        Assert.assertEquals(logoutToken.getSid(), idToken.getSessionId());
    } finally {
        rep.setFrontchannelLogout(false);
        rep.getAttributes().put(OIDCConfigAttributes.FRONT_CHANNEL_LOGOUT_URI, "");
        clients.get(rep.getId()).update(rep);
    }
}
Also used : OAuthClient(org.keycloak.testsuite.util.OAuthClient) ClientsResource(org.keycloak.admin.client.resource.ClientsResource) LogoutToken(org.keycloak.representations.LogoutToken) IDToken(org.keycloak.representations.IDToken) JWSInput(org.keycloak.jose.jws.JWSInput) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 8 with LogoutToken

use of org.keycloak.representations.LogoutToken in project keycloak by keycloak.

the class TestApplicationResourceProvider method frontchannelLogout.

@GET
@Path("/admin/frontchannelLogout")
public void frontchannelLogout(@QueryParam("sid") String sid, @QueryParam("iss") String issuer) {
    LogoutToken token = new LogoutToken();
    token.setSid(sid);
    token.issuer(issuer);
    frontChannelLogoutTokens.add(token);
}
Also used : LogoutToken(org.keycloak.representations.LogoutToken) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

LogoutToken (org.keycloak.representations.LogoutToken)8 Path (javax.ws.rs.Path)2 Test (org.junit.Test)2 ClientsResource (org.keycloak.admin.client.resource.ClientsResource)2 JWSInput (org.keycloak.jose.jws.JWSInput)2 IDToken (org.keycloak.representations.IDToken)2 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)2 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)2 OAuthClient (org.keycloak.testsuite.util.OAuthClient)2 IOException (java.io.IOException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Signature (java.security.Signature)1 SignatureException (java.security.SignatureException)1 LinkedList (java.util.LinkedList)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 NameValuePair (org.apache.http.NameValuePair)1 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)1