Search in sources :

Example 6 with GetClientTokenResponse

use of io.jans.ca.common.response.GetClientTokenResponse in project jans by JanssenProject.

the class Tester method getAuthorization.

public static String getAuthorization(RegisterSiteResponse site) {
    final GetClientTokenParams params = new GetClientTokenParams();
    params.setScope(Lists.newArrayList("openid", "jans_client_api"));
    params.setOpHost(site.getOpHost());
    params.setClientId(site.getClientId());
    params.setClientSecret(site.getClientSecret());
    GetClientTokenResponse resp = Tester.newClient(HOST).getClientToken(params);
    assertNotNull(resp);
    assertTrue(!Strings.isNullOrEmpty(resp.getAccessToken()));
    return "Bearer " + resp.getAccessToken();
}
Also used : GetClientTokenResponse(io.jans.ca.common.response.GetClientTokenResponse) GetClientTokenParams(io.jans.ca.common.params.GetClientTokenParams)

Example 7 with GetClientTokenResponse

use of io.jans.ca.common.response.GetClientTokenResponse in project jans by JanssenProject.

the class GetTokensByCodeTest method refreshToken.

public static GetClientTokenResponse refreshToken(GetTokensByCodeResponse2 resp, ClientInterface client, RegisterSiteResponse site) {
    notEmpty(resp.getRefreshToken());
    // refresh token
    final GetAccessTokenByRefreshTokenParams refreshParams = new GetAccessTokenByRefreshTokenParams();
    refreshParams.setRpId(site.getRpId());
    refreshParams.setScope(Lists.newArrayList("openid", "jans_client_api"));
    refreshParams.setRefreshToken(resp.getRefreshToken());
    GetClientTokenResponse refreshResponse = client.getAccessTokenByRefreshToken(Tester.getAuthorization(site), null, refreshParams);
    assertNotNull(refreshResponse);
    notEmpty(refreshResponse.getAccessToken());
    notEmpty(refreshResponse.getRefreshToken());
    return refreshResponse;
}
Also used : GetAccessTokenByRefreshTokenParams(io.jans.ca.common.params.GetAccessTokenByRefreshTokenParams) GetClientTokenResponse(io.jans.ca.common.response.GetClientTokenResponse)

Example 8 with GetClientTokenResponse

use of io.jans.ca.common.response.GetClientTokenResponse in project jans by JanssenProject.

the class GetClientTokenTest method getClientToken_withOpConfigurationEndpoint.

@Parameters({ "host", "opConfigurationEndpoint" })
@Test
public void getClientToken_withOpConfigurationEndpoint(String host, String opConfigurationEndpoint) {
    final GetClientTokenParams params = new GetClientTokenParams();
    params.setOpConfigurationEndpoint(opConfigurationEndpoint);
    params.setScope(Lists.newArrayList("openid"));
    params.setClientId(Tester.getSetupClient().getClientId());
    params.setClientSecret(Tester.getSetupClient().getClientSecret());
    GetClientTokenResponse resp = Tester.newClient(host).getClientToken(params);
    assertNotNull(resp);
    notEmpty(resp.getAccessToken());
}
Also used : GetClientTokenResponse(io.jans.ca.common.response.GetClientTokenResponse) GetClientTokenParams(io.jans.ca.common.params.GetClientTokenParams) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 9 with GetClientTokenResponse

use of io.jans.ca.common.response.GetClientTokenResponse 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

GetClientTokenResponse (io.jans.ca.common.response.GetClientTokenResponse)9 GetClientTokenParams (io.jans.ca.common.params.GetClientTokenParams)6 Parameters (org.testng.annotations.Parameters)4 Test (org.testng.annotations.Test)4 TokenClient (io.jans.as.client.TokenClient)2 TokenResponse (io.jans.as.client.TokenResponse)2 RegisterSiteResponse (io.jans.ca.common.response.RegisterSiteResponse)2 HttpException (io.jans.ca.server.HttpException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 TokenRequest (io.jans.as.client.TokenRequest)1 AuthenticationMethod (io.jans.as.model.common.AuthenticationMethod)1 SignatureAlgorithm (io.jans.as.model.crypto.signature.SignatureAlgorithm)1 Jwt (io.jans.as.model.jwt.Jwt)1 ClientInterface (io.jans.ca.client.ClientInterface)1 GetAccessTokenByRefreshTokenParams (io.jans.ca.common.params.GetAccessTokenByRefreshTokenParams)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 Rp (io.jans.ca.server.service.Rp)1