@Override public byte[] sign(byte[] toSign) { return appIdentityService.signForApp(toSign).getSignature(); }
@Override public GetAccessTokenResult getNewAccessToken(List<String> scopes) { return appIdentityService.getAccessToken(scopes); } }
/** * @param builder builder * * @since 1.14 */ protected AppIdentityCredential(Builder builder) { // Lazily retrieved rather than setting as the default value in order to not add runtime // dependencies on AppIdentityServiceFactory unless it is actually being used. appIdentityService = builder.appIdentityService == null ? AppIdentityServiceFactory.getAppIdentityService() : builder.appIdentityService; scopes = builder.scopes; }
/** * Refresh the access token by getting it from the App Identity service */ @Override public AccessToken refreshAccessToken() throws IOException { if (createScopedRequired()) { throw new IOException("AppEngineCredentials requires createScoped call before use."); } GetAccessTokenResult accessTokenResponse = appIdentityService.getAccessToken(scopes); String accessToken = accessTokenResponse.getAccessToken(); Date expirationTime = accessTokenResponse.getExpirationTime(); return new AccessToken(accessToken, expirationTime); }
List<String> scopes = new ArrayList<>(); scopes.add("https://www.googleapis.com/auth/devstorage.full_control"); AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService(); AppIdentityService.GetAccessTokenResult accessToken = appIdentity.getAccessToken(scopes); urlConnection.setRequestProperty("Authorization","Bearer "+accessToken.getAccessToken());
public byte[] sign(byte[] source) throws SignatureException { SigningResult key = identityService.signForApp(source); this.setSigningKeyId(key.getKeyName()); return key.getSignature(); } }
@Override public GetAccessTokenResult getAccessToken(Iterable<String> scopes) { getAccessTokenCallCount++; int scopeCount = 0; for (String scope : scopes) { if (scope != null) { scopeCount++; } } if (scopeCount == 0) { throw new AppIdentityServiceFailureException("No scopes specified."); } return new GetAccessTokenResult(accessTokenText, new Date(System.currentTimeMillis() + 3600000)); }
protected AppEngineSigner(String keyId, AppIdentityService identityService) { super(identityService.getServiceAccountName(), keyId); this.identityService = identityService; }
private String createParsed(AppIdentityService.ParsedAppId parsed) { return parsed.getDomain() + " : " + parsed.getId() + " : " + parsed.getPartition(); }
public void setSignature(byte[] signature) { this.signingResult = new SigningResult("keyName", signature); }
@Override public Data getTokenData() { AppIdentityCredential credential = getCredential(); Collection<String> scopes = credential.getScopes(); AppIdentityService.GetAccessTokenResult result = credential.getAppIdentityService().getAccessToken( scopes ); String accessToken = result.getAccessToken(); Date expirationTime = result.getExpirationTime(); return new Data( accessToken, expirationTime ); } }
@Override public void intercept(HttpRequest request) throws IOException { String accessToken = appIdentityService.getAccessToken(scopes).getAccessToken(); BearerToken.authorizationHeaderAccessMethod().intercept(request, accessToken); }
public AppIdentityAccessTokenProvider() { this.appIdentityService = AppIdentityServiceFactory.getAppIdentityService(); }
private static final AppIdentityService identityService = AppIdentityServiceFactory.getAppIdentityService(); String token = identityService .getAccessToken(Arrays.asList("https://www.googleapis.com/auth/devstorage.full_control")).getAccessToken();
@Override public GetAccessTokenResult getAccessToken(Iterable<String> scopes) { getAccessTokenCallCount++; int scopeCount = 0; for (String scope : scopes) { if (scope != null) { scopeCount++; } } if (scopeCount == 0) { throw new AppIdentityServiceFailureException("No scopes specified."); } return new GetAccessTokenResult(accessTokenText, expiration); }
@Override public String getAccount() { return appIdentityService.getServiceAccountName(); }
@Override public SigningResult signForApp(byte[] bytes) { try { Signature dsa = Signature.getInstance("SHA256withRSA"); dsa.initSign(privateKey); dsa.update(bytes); return new SigningResult(SERVICE_ACCOUNT_EMAIL, dsa.sign()); } catch(Exception e) { throw new RuntimeException(e); } }
@Override protected TokenResponse executeRefreshToken() throws IOException { GetAccessTokenResult tokenResult = appIdentity.getAppIdentityService() .getAccessToken(appIdentity.getScopes()); TokenResponse response = new TokenResponse(); response.setAccessToken(tokenResult.getAccessToken()); long expiresInSeconds = (tokenResult.getExpirationTime().getTime() - System.currentTimeMillis()) / 1000; response.setExpiresInSeconds(expiresInSeconds); return response; } }
@Provides @Singleton AppIdentityService provideAppIdentityService() { return AppIdentityServiceFactory.getAppIdentityService(); }
@Before public void setUp() { appIdentity = AppIdentityServiceFactory.getAppIdentityService(); }