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());
}
Aggregations