Search in sources :

Example 6 with GetClientTokenParams

use of io.jans.ca.common.params.GetClientTokenParams in project jans by JanssenProject.

the class AccessTokenAsJwtTest method getClientToken.

@Parameters({ "host", "opHost", "redirectUrls", "postLogoutRedirectUrls" })
@Test
public void getClientToken(String host, String opHost, String redirectUrls, String postLogoutRedirectUrls) throws InvalidJwtException {
    final RegisterSiteParams params = new RegisterSiteParams();
    params.setOpHost(opHost);
    params.setRedirectUris(Lists.newArrayList(redirectUrls.split(" ")));
    params.setPostLogoutRedirectUris(Lists.newArrayList(postLogoutRedirectUrls.split(" ")));
    params.setScope(Lists.newArrayList("openid", "uma_protection", "profile"));
    params.setAccessTokenAsJwt(true);
    params.setGrantTypes(Lists.newArrayList(GrantType.AUTHORIZATION_CODE.getValue(), GrantType.CLIENT_CREDENTIALS.getValue()));
    final RegisterSiteResponse resp = Tester.newClient(host).registerSite(params);
    assertResponse(resp);
    final GetClientTokenParams tokenParams = new GetClientTokenParams();
    tokenParams.setOpHost(opHost);
    tokenParams.setScope(Lists.newArrayList("openid"));
    tokenParams.setClientId(resp.getClientId());
    tokenParams.setClientSecret(resp.getClientSecret());
    GetClientTokenResponse tokenResponse = Tester.newClient(host).getClientToken(tokenParams);
    assertNotNull(tokenResponse);
    notEmpty(tokenResponse.getAccessToken());
    final Jwt parse = Jwt.parse(tokenResponse.getAccessToken());
    assertNotNull(parse);
    System.out.println("access token as JWT: " + tokenResponse.getAccessToken() + ", claims: " + parse.getClaims());
}
Also used : Jwt(io.jans.as.model.jwt.Jwt) RegisterSiteParams(io.jans.ca.common.params.RegisterSiteParams) RegisterSiteResponse(io.jans.ca.common.response.RegisterSiteResponse) GetClientTokenResponse(io.jans.ca.common.response.GetClientTokenResponse) GetClientTokenParams(io.jans.ca.common.params.GetClientTokenParams) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Aggregations

GetClientTokenParams (io.jans.ca.common.params.GetClientTokenParams)6 GetClientTokenResponse (io.jans.ca.common.response.GetClientTokenResponse)6 Parameters (org.testng.annotations.Parameters)4 Test (org.testng.annotations.Test)4 RegisterSiteResponse (io.jans.ca.common.response.RegisterSiteResponse)2 Jwt (io.jans.as.model.jwt.Jwt)1 ClientInterface (io.jans.ca.client.ClientInterface)1 IntrospectAccessTokenParams (io.jans.ca.common.params.IntrospectAccessTokenParams)1 RegisterSiteParams (io.jans.ca.common.params.RegisterSiteParams)1 IntrospectAccessTokenResponse (io.jans.ca.common.response.IntrospectAccessTokenResponse)1