/** * Static function to create a signable JSON token initialized with the proper parameters for * performing an assertion token request. * * @param scope Scope for which we are requesting access. * @param audience Audience field in the json web token. * @return Signable JSON web token (JWT). */ public static JsonToken createJsonTokenForScopes(String scope, String audience) { AppIdentityService identityService = AppIdentityServiceFactory.getAppIdentityService(); AppEngineSigner signer = new AppEngineSigner("", identityService); SignedJsonAssertionToken jwt = new SignedJsonAssertionToken(signer); jwt.setAudience(audience); jwt.setScope(scope); jwt.setNonce(Long.toString(GENERATOR.nextLong())); Instant now = new Instant(); jwt.setIssuedAt(now); jwt.setExpiration(now.plus(Duration.standardHours(1))); LOGGER.fine("JWT: " + jwt.toString()); return jwt; } }
public byte[] sign(byte[] source) throws SignatureException { SigningResult key = identityService.signForApp(source); this.setSigningKeyId(key.getKeyName()); return key.getSignature(); } }