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() {
    this.appIdentityService = AppIdentityServiceFactory.getAppIdentityService();
  }

  @Override
  public GetAccessTokenResult getNewAccessToken(List<String> scopes) {
    if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Development) {
      throw new IllegalStateException(
          "The access token from AppIdentity won't work in the development environment.");
    }
    return appIdentityService.getAccessToken(scopes);
  }
}

@@ -780,238 +780,8 @@
 ) %7B%0A
-    if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Development) %7B%0A      throw new IllegalStateException(%0A          %22The access token from AppIdentity won't work in the development environment.%22);%0A    %7D%0A
     

allow AppIdentity oauth token to work in development environment.