package com.google.appengine.tools.cloudstorage.oauth;

import com.google.appengine.api.appidentity.AppIdentityService;
import com.google.appengine.api.appidentity.AppIdentityService.GetAccessTokenResult;
import com.google.appengine.api.appidentity.AppIdentityServiceFactory;
import com.google.appengine.api.utils.SystemProperty;

import java.util.List;

/**
 * Provider that uses the AppIdentityService for generating access tokens.
 */
final class AppIdentityAccessTokenProvider implements AccessTokenProvider {
  private final AppIdentityService appIdentityService;

  public AppIdentityAccessTokenProvider() {
    if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Development) {
      throw new IllegalStateException(
          "The access token from AppIdentity won't work in the development environment.");
    }
    this.appIdentityService = AppIdentityServiceFactory.getAppIdentityService();
  }

  @Override
  public GetAccessTokenResult getNewAccessToken(List<String> scopes) {
    return appIdentityService.getAccessToken(scopes);
  }
}

@@ -603,24 +603,193 @@
 rovider() %7B%0A
+    this.appIdentityService = AppIdentityServiceFactory.getAppIdentityService();%0A  %7D%0A%0A  @Override%0A  public GetAccessTokenResult getNewAccessToken(List%3CString%3E scopes) %7B%0A
     if (Syst
@@ -1010,177 +1010,8 @@
   %7D%0A
-    this.appIdentityService = AppIdentityServiceFactory.getAppIdentityService();%0A  %7D%0A%0A  @Override%0A  public GetAccessTokenResult getNewAccessToken(List%3CString%3E scopes) %7B%0A
     

Move check for development environment into the getNewAccessToken method.