IdToken extends OAuth2Token { public String getSignedToken(final PrivateKey key, final String keyId, final SignatureAlgorithm keyAlg) { return Jwts.builder().setSubject(subject) .setIssuedAt(Date.from(Instant.ofEpochSecond(issueTime))) .setExpiration(Date.from(Instant.ofEpochSecond(expiryTime))) .setIssuer(issuer) .setAudience(audience) .claim(CLAIM_AUTH_TIME, authTime) .claim(CLAIM_VERSION, version) .setHeaderParam(HDR_KEY_ID, keyId) .signWith(key, keyAlg) .compact(); } IdToken();  IdToken(final String token, JwtsSigningKeyResolver keyResolver);  IdToken(final String token, PublicKey publicKey); String getSignedToken(final PrivateKey key, final String keyId,
            final SignatureAlgorithm keyAlg);  }
@Test public void testIdTokenSignedToken() { long now = System.currentTimeMillis() / 1000; IdToken token = createIdToken(now); PrivateKey privateKey = Crypto.loadPrivateKey(ecPrivateKey); String idJws = token.getSignedToken(privateKey, "eckey1", SignatureAlgorithm.ES256); assertNotNull(idJws); JwtsSigningKeyResolver resolver = new JwtsSigningKeyResolver(null, null); resolver.addPublicKey("eckey1", Crypto.loadPublicKey(ecPublicKey)); IdToken checkToken = new IdToken(idJws, resolver); validateIdToken(checkToken, now); }
@Test public void testIdTokenSignedTokenPublicKey() { long now = System.currentTimeMillis() / 1000; IdToken token = createIdToken(now); PrivateKey privateKey = Crypto.loadPrivateKey(ecPrivateKey); String idJws = token.getSignedToken(privateKey, "eckey1", SignatureAlgorithm.ES256); assertNotNull(idJws); IdToken checkToken = new IdToken(idJws, Crypto.loadPublicKey(ecPublicKey)); validateIdToken(checkToken, now); }