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