Search in sources :

Example 1 with GetTokensByCodeResponse2

use of io.jans.ca.client.GetTokensByCodeResponse2 in project jans by JanssenProject.

the class AuthorizationCodeFlowTest method requestTokens.

private GetTokensByCodeResponse2 requestTokens(ClientInterface client, RegisterSiteResponse site, String userId, String userSecret) {
    final String state = CoreUtils.secureRandomString();
    final String nonce = "7r46ut6emu9gi11gn8044um640";
    final GetTokensByCodeParams params = new GetTokensByCodeParams();
    params.setRpId(site.getRpId());
    params.setCode(codeRequest(client, site.getRpId(), userId, userSecret, state, nonce));
    params.setState(state);
    final GetTokensByCodeResponse2 resp = client.getTokenByCode(Tester.getAuthorization(), null, params);
    assertNotNull(resp);
    notEmpty(resp.getAccessToken());
    notEmpty(resp.getIdToken());
    return resp;
}
Also used : GetTokensByCodeResponse2(io.jans.ca.client.GetTokensByCodeResponse2)

Example 2 with GetTokensByCodeResponse2

use of io.jans.ca.client.GetTokensByCodeResponse2 in project jans by JanssenProject.

the class CheckAccessTokenTest method test.

@Parameters({ "host", "redirectUrls", "userId", "userSecret", "opHost" })
@Test
public void test(String host, String redirectUrls, String userId, String userSecret, String opHost) {
    ClientInterface client = Tester.newClient(host);
    String nonce = CoreUtils.secureRandomString();
    String state = CoreUtils.secureRandomString();
    RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls);
    GetTokensByCodeResponse2 response = GetTokensByCodeTest.tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, nonce, state);
    final CheckAccessTokenParams params = new CheckAccessTokenParams();
    params.setAccessToken(response.getAccessToken());
    params.setIdToken(response.getIdToken());
    params.setRpId(site.getRpId());
    final CheckAccessTokenResponse checkR = client.checkAccessToken(Tester.getAuthorization(site), null, params);
    assertNotNull(checkR);
    assertTrue(checkR.isActive());
    assertNotNull(checkR.getExpiresAt());
    assertNotNull(checkR.getIssuedAt());
}
Also used : CheckAccessTokenResponse(io.jans.ca.common.response.CheckAccessTokenResponse) CheckAccessTokenParams(io.jans.ca.common.params.CheckAccessTokenParams) ClientInterface(io.jans.ca.client.ClientInterface) RegisterSiteResponse(io.jans.ca.common.response.RegisterSiteResponse) GetTokensByCodeResponse2(io.jans.ca.client.GetTokensByCodeResponse2) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 3 with GetTokensByCodeResponse2

use of io.jans.ca.client.GetTokensByCodeResponse2 in project jans by JanssenProject.

the class DifferentAuthServerTest method getUserInfo_withDifferentAuthServer.

@Parameters({ "host", "opHost", "authServer", "redirectUrls", "clientId", "clientSecret", "userId", "userSecret" })
@Test
public void getUserInfo_withDifferentAuthServer(String host, String opHost, String authServer, String redirectUrls, String clientId, String clientSecret, String userId, String userSecret) {
    ClientInterface client = Tester.newClient(host);
    RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls);
    RegisterSiteResponse authServerResp = RegisterSiteTest.registerSite(client, authServer, redirectUrls);
    final GetTokensByCodeResponse2 tokens = requestTokens(client, opHost, site, authServerResp, userId, userSecret, site.getClientId(), redirectUrls);
    GetUserInfoParams params = new GetUserInfoParams();
    params.setRpId(site.getRpId());
    params.setAccessToken(tokens.getAccessToken());
    params.setIdToken(tokens.getIdToken());
    final JsonNode resp = client.getUserInfo(Tester.getAuthorization(authServerResp), authServerResp.getRpId(), params);
    assertNotNull(resp);
    assertNotNull(resp.get("sub"));
}
Also used : GetUserInfoParams(io.jans.ca.common.params.GetUserInfoParams) JsonNode(com.fasterxml.jackson.databind.JsonNode) ClientInterface(io.jans.ca.client.ClientInterface) RegisterSiteResponse(io.jans.ca.common.response.RegisterSiteResponse) GetTokensByCodeResponse2(io.jans.ca.client.GetTokensByCodeResponse2) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 4 with GetTokensByCodeResponse2

use of io.jans.ca.client.GetTokensByCodeResponse2 in project jans by JanssenProject.

the class DifferentAuthServerTest method requestTokens.

private GetTokensByCodeResponse2 requestTokens(ClientInterface client, String opHost, RegisterSiteResponse site, RegisterSiteResponse authServer, String userId, String userSecret, String clientId, String redirectUrls) {
    final String state = CoreUtils.secureRandomString();
    final String nonce = CoreUtils.secureRandomString();
    final GetTokensByCodeParams params = new GetTokensByCodeParams();
    params.setRpId(site.getRpId());
    params.setCode(GetTokensByCodeTest.codeRequest(client, opHost, site, userId, userSecret, clientId, redirectUrls, state, nonce));
    params.setState(state);
    final GetTokensByCodeResponse2 resp = client.getTokenByCode(Tester.getAuthorization(authServer), authServer.getRpId(), params);
    assertNotNull(resp);
    notEmpty(resp.getAccessToken());
    notEmpty(resp.getIdToken());
    return resp;
}
Also used : GetTokensByCodeParams(io.jans.ca.common.params.GetTokensByCodeParams) GetTokensByCodeResponse2(io.jans.ca.client.GetTokensByCodeResponse2)

Example 5 with GetTokensByCodeResponse2

use of io.jans.ca.client.GetTokensByCodeResponse2 in project jans by JanssenProject.

the class GetTokensByCodeTest method getToken_withRS512.

@Parameters({ "host", "opHost", "redirectUrls", "userId", "userSecret" })
@Test
public void getToken_withRS512(String host, String opHost, String redirectUrls, String userId, String userSecret) {
    ClientInterface client = Tester.newClient(host);
    final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls, "RS512");
    GetTokensByCodeResponse2 tokensResponse = tokenByCode(client, site, opHost, userId, userSecret, site.getClientId(), redirectUrls, CoreUtils.secureRandomString(), CoreUtils.secureRandomString());
}
Also used : ClientInterface(io.jans.ca.client.ClientInterface) RegisterSiteResponse(io.jans.ca.common.response.RegisterSiteResponse) GetTokensByCodeResponse2(io.jans.ca.client.GetTokensByCodeResponse2) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Aggregations

GetTokensByCodeResponse2 (io.jans.ca.client.GetTokensByCodeResponse2)26 RegisterSiteResponse (io.jans.ca.common.response.RegisterSiteResponse)22 ClientInterface (io.jans.ca.client.ClientInterface)21 Parameters (org.testng.annotations.Parameters)21 Test (org.testng.annotations.Test)21 GetTokensByCodeParams (io.jans.ca.common.params.GetTokensByCodeParams)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 GetUserInfoParams (io.jans.ca.common.params.GetUserInfoParams)2 CheckAccessTokenParams (io.jans.ca.common.params.CheckAccessTokenParams)1 CheckIdTokenParams (io.jans.ca.common.params.CheckIdTokenParams)1 CheckAccessTokenResponse (io.jans.ca.common.response.CheckAccessTokenResponse)1 CheckIdTokenResponse (io.jans.ca.common.response.CheckIdTokenResponse)1 List (java.util.List)1 BadRequestException (javax.ws.rs.BadRequestException)1