当前位置: 首页>>代码示例>>Java>>正文


Java AppIdentityServiceFactory.getAppIdentityService方法代码示例

本文整理汇总了Java中com.google.appengine.api.appidentity.AppIdentityServiceFactory.getAppIdentityService方法的典型用法代码示例。如果您正苦于以下问题:Java AppIdentityServiceFactory.getAppIdentityService方法的具体用法?Java AppIdentityServiceFactory.getAppIdentityService怎么用?Java AppIdentityServiceFactory.getAppIdentityService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.appengine.api.appidentity.AppIdentityServiceFactory的用法示例。


在下文中一共展示了AppIdentityServiceFactory.getAppIdentityService方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createFirebaseToken

import com.google.appengine.api.appidentity.AppIdentityServiceFactory; //导入方法依赖的package包/类
/**
 * Create a secure JWT token for the given userId.
 */
public String createFirebaseToken(Game game, String userId) {
  final AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService();
  final BaseEncoding base64 = BaseEncoding.base64();

  String header = base64.encode("{\"typ\":\"JWT\",\"alg\":\"RS256\"}".getBytes());

  // Construct the claim
  String channelKey = game.getChannelKey(userId);
  String clientEmail = appIdentity.getServiceAccountName();
  long epochTime = System.currentTimeMillis() / 1000;
  long expire = epochTime + 60 * 60; // an hour from now

  Map<String, Object> claims = new HashMap<String, Object>();
  claims.put("iss", clientEmail);
  claims.put("sub", clientEmail);
  claims.put("aud", IDENTITY_ENDPOINT);
  claims.put("uid", channelKey);
  claims.put("iat", epochTime);
  claims.put("exp", expire);

  String payload = base64.encode(new Gson().toJson(claims).getBytes());
  String toSign = String.format("%s.%s", header, payload);
  AppIdentityService.SigningResult result = appIdentity.signForApp(toSign.getBytes());
  return String.format("%s.%s", toSign, base64.encode(result.getSignature()));
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:29,代码来源:FirebaseChannel.java

示例2: createShortUrl

import com.google.appengine.api.appidentity.AppIdentityServiceFactory; //导入方法依赖的package包/类
/**
 * Returns a shortened URL by calling the Google URL Shortener API.
 *
 * <p>Note: Error handling elided for simplicity.
 */
public String createShortUrl(String longUrl) throws Exception {
  ArrayList<String> scopes = new ArrayList<String>();
  scopes.add("https://www.googleapis.com/auth/urlshortener");
  final AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService();
  final AppIdentityService.GetAccessTokenResult accessToken = appIdentity.getAccessToken(scopes);
  // The token asserts the identity reported by appIdentity.getServiceAccountName()
  JSONObject request = new JSONObject();
  request.put("longUrl", longUrl);

  URL url = new URL("https://www.googleapis.com/urlshortener/v1/url?pp=1");
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  connection.setDoOutput(true);
  connection.setRequestMethod("POST");
  connection.addRequestProperty("Content-Type", "application/json");
  connection.addRequestProperty("Authorization", "Bearer " + accessToken.getAccessToken());

  OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
  request.write(writer);
  writer.close();

  if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
    // Note: Should check the content-encoding.
    //       Any JSON parser can be used; this one is used for illustrative purposes.
    JSONTokener responseTokens = new JSONTokener(connection.getInputStream());
    JSONObject response = new JSONObject(responseTokens);
    return (String) response.get("id");
  } else {
    try (InputStream s = connection.getErrorStream();
        InputStreamReader r = new InputStreamReader(s, StandardCharsets.UTF_8)) {
      throw new RuntimeException(String.format(
          "got error (%d) response %s from %s",
          connection.getResponseCode(),
          CharStreams.toString(r),
          connection.toString()));
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:43,代码来源:UrlShortener.java

示例3: createShortUrl

import com.google.appengine.api.appidentity.AppIdentityServiceFactory; //导入方法依赖的package包/类
/**
 * Returns a shortened URL by calling the Google URL Shortener API.
 *
 * <p>Note: Error handling elided for simplicity.
 */
public String createShortUrl(String longUrl) throws Exception {
  ArrayList<String> scopes = new ArrayList<String>();
  scopes.add("https://www.googleapis.com/auth/urlshortener");
  final AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService();
  final AppIdentityService.GetAccessTokenResult accessToken = appIdentity.getAccessToken(scopes);
  // The token asserts the identity reported by appIdentity.getServiceAccountName()
  JSONObject request = new JSONObject();
  request.put("longUrl", longUrl);

  URL url = new URL("https://www.googleapis.com/urlshortener/v1/url?pp=1");
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  connection.setDoOutput(true);
  connection.setRequestMethod("POST");
  connection.addRequestProperty("Content-Type", "application/json");
  connection.addRequestProperty("Authorization", "Bearer " + accessToken.getAccessToken());

  OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
  request.write(writer);
  writer.close();

  if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
    // Note: Should check the content-encoding.
    //       Any JSON parser can be used; this one is used for illustrative purposes.
    JSONTokener responseTokens = new JSONTokener(connection.getInputStream());
    JSONObject response = new JSONObject(responseTokens);
    return (String) response.get("id");
  } else {
    try (InputStream s = connection.getErrorStream();
        InputStreamReader r = new InputStreamReader(s, StandardCharsets.UTF_8)) {
      throw new RuntimeException(
          String.format(
              "got error (%d) response %s from %s",
              connection.getResponseCode(), CharStreams.toString(r), connection.toString()));
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:42,代码来源:UrlShortener.java

示例4: getProjectId

import com.google.appengine.api.appidentity.AppIdentityServiceFactory; //导入方法依赖的package包/类
/**
 * Returns the project ID.
 *
 * @return the project ID.
 */
public static String getProjectId() {
    AppIdentityService identityService =
            AppIdentityServiceFactory.getAppIdentityService();

    // The project ID associated to an app engine application is the same
    // as the app ID.
    return identityService.parseFullAppId(ApiProxy.getCurrentEnvironment()
            .getAppId()).getId();
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-samples-java,代码行数:15,代码来源:PubsubUtils.java

示例5: CloudFileManager

import com.google.appengine.api.appidentity.AppIdentityServiceFactory; //导入方法依赖的package包/类
public CloudFileManager() {
  AppIdentityService appIdentityService = AppIdentityServiceFactory.getAppIdentityService();
  defaultBucket = appIdentityService.getDefaultGcsBucketName();
  productionManifestFile = new GcsFilename(defaultBucket, Config.MANIFEST_NAME);
  stagingManifestFile = new GcsFilename(defaultBucket, Config.MANIFEST_NAME_STAGING);
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:7,代码来源:CloudFileManager.java

示例6: SignForAppServlet

import com.google.appengine.api.appidentity.AppIdentityServiceFactory; //导入方法依赖的package包/类
public SignForAppServlet() {
  appIdentity = AppIdentityServiceFactory.getAppIdentityService();
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:4,代码来源:SignForAppServlet.java

示例7: AppIdentityAccessTokenProvider

import com.google.appengine.api.appidentity.AppIdentityServiceFactory; //导入方法依赖的package包/类
public AppIdentityAccessTokenProvider() {
  this.appIdentityService = AppIdentityServiceFactory.getAppIdentityService();
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-gcs-client,代码行数:4,代码来源:AppIdentityAccessTokenProvider.java

示例8: setUp

import com.google.appengine.api.appidentity.AppIdentityServiceFactory; //导入方法依赖的package包/类
@Before
public void setUp() {
    appIdentity = AppIdentityServiceFactory.getAppIdentityService();
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:5,代码来源:AppIdentityServiceTest.java

示例9: getAccessToken

import com.google.appengine.api.appidentity.AppIdentityServiceFactory; //导入方法依赖的package包/类
/**
 * Get the access token for a list of scopes.
 *
 * @param scopes the scopes to get the access tokens for.
 * @return the access token.
 */
public static String getAccessToken(List<String> scopes) {
  final AppIdentityService appIdService = AppIdentityServiceFactory.getAppIdentityService();
  AppIdentityService.GetAccessTokenResult result = appIdService.getAccessToken(scopes);
  return result.getAccessToken();
}
 
开发者ID:GoogleCloudPlatform,项目名称:solutions-google-compute-engine-orchestrator,代码行数:12,代码来源:GceApiUtils.java


注:本文中的com.google.appengine.api.appidentity.AppIdentityServiceFactory.getAppIdentityService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。