Search in sources :

Example 1 with CheckAccessTokenResponse

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

the class CheckAccessTokenOperation method execute.

@Override
public IOpResponse execute(CheckAccessTokenParams params) throws Exception {
    final OpenIdConfigurationResponse discoveryResponse = getDiscoveryService().getConnectDiscoveryResponseByRpId(params.getRpId());
    final String idToken = params.getIdToken();
    final String accessToken = params.getAccessToken();
    final Jwt jwt = Jwt.parse(idToken);
    final Date issuedAt = jwt.getClaims().getClaimAsDate(JwtClaimName.ISSUED_AT);
    final Date expiresAt = jwt.getClaims().getClaimAsDate(JwtClaimName.EXPIRATION_TIME);
    final CheckAccessTokenResponse opResponse = new CheckAccessTokenResponse();
    opResponse.setActive(isAccessTokenValid(accessToken, jwt, discoveryResponse));
    opResponse.setIssuedAt(issuedAt);
    opResponse.setExpiresAt(expiresAt);
    return opResponse;
}
Also used : Jwt(io.jans.as.model.jwt.Jwt) CheckAccessTokenResponse(io.jans.ca.common.response.CheckAccessTokenResponse) OpenIdConfigurationResponse(io.jans.as.client.OpenIdConfigurationResponse) Date(java.util.Date)

Example 2 with CheckAccessTokenResponse

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

Aggregations

CheckAccessTokenResponse (io.jans.ca.common.response.CheckAccessTokenResponse)2 OpenIdConfigurationResponse (io.jans.as.client.OpenIdConfigurationResponse)1 Jwt (io.jans.as.model.jwt.Jwt)1 ClientInterface (io.jans.ca.client.ClientInterface)1 GetTokensByCodeResponse2 (io.jans.ca.client.GetTokensByCodeResponse2)1 CheckAccessTokenParams (io.jans.ca.common.params.CheckAccessTokenParams)1 RegisterSiteResponse (io.jans.ca.common.response.RegisterSiteResponse)1 Date (java.util.Date)1 Parameters (org.testng.annotations.Parameters)1 Test (org.testng.annotations.Test)1