java - 在开发服务器上配置 AppIdentityService 的使用

标签 java google-app-engine authorization

我有一个应用程序当前使用 com.google.appendinge.api.appidentity.AppIdentityService 来促进使用同一应用程序的身份验证和授权 [即。相同帐户] 通过 SpreadsheetService API 的电子表格数据。在部署到 GAE 环境的生产模式下效果很好。但由于显而易见的原因,它在我的开发 appengine 环境中运行时不起作用(身份验证错误,这并不奇怪)。

我的问题是:是否可以“支持”配置本地开发服务器以使用必要的 key 和证书信息来使 AppIdentityService 按预期工作?

我阅读了文章 https://sites.google.com/site/oauthgoog/authenticate-google-app-engine-app并且我理解它暗示这是可能的,但我误解了关键点,并且希望对此有任何反馈。

在一个完美的世界里,我希望我的测试环境尽可能地模仿生产模式。我也在考虑在我的测试环境中使用“普通”oauth2 Web 应用程序身份验证,但如果可能的话,我更愿意坚持使用 AppIdentityService。

我怀疑 appengine-api-stubs.jar 中的 com.google.appengine.api.appidentity.dev.LocalAppIdentityService 类是预期的技术,但有人否则还使用它在开发服务器中提供 AppIdentityService 身份验证吗?我最初的假设是替换在 com.google.appengine.spi.FactoryProvider 中找到的类 com.google.appengine.api.appidentity.IAppIdentityServiceFactoryProvider 以使用我自己的工厂类使用上面的 LocalAppIdentityService 类。还是我找错树了?

使用适用于 Java 的 GAE SDK 1.8.8。

最佳答案

在本地开发服务器下运行时,GAE Java App Identity API 调用 GoogleCredentials library to retrieve the default application credential .

  1. The environment variable GOOGLE_APPLICATION_CREDENTIALS is checked. If this variable is specified it should point to a file that defines the credentials. The simplest way to get a credential for this purpose is to create a service account using the Google Developers Console in the section APIs & Auth, in the sub-section Credentials. Create a service account or choose an existing one and select Generate new JSON key. Set the environment variable to the path of the JSON file downloaded.
  2. If you have installed the Google Cloud SDK on your machine and have run the command gcloud auth login, your identity can be used as a proxy to test code calling APIs from that machine.
  3. If you are running in Google App Engine production, the built-in service account associated with the application will be used.
  4. If you are running in Google Compute Engine production, the built-in service account associated with the virtual machine instance will be used.
  5. If none of these conditions is true, an error will occur.

看起来选项 #2 对您来说可能是最简单的(运行 gcloud auth login 以让您的代码在本地运行时使用您的 Google 帐户进行身份验证),但您也可以执行 #1。

关于java - 在开发服务器上配置 AppIdentityService 的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21236314/

相关文章:

java - Android(Java)中的十六进制到字符串?

java - Hibernate - C3P0 - 连接池 - 事务

java - QuickSort 在线程 "main"java.lang.StackOverflowError 中给出异常

python - 如何将多个参数传递给 Google App Engine python 中的处理程序?

c# - WCF 自定义授权

java - 无法启动服务? (语音识别)

python - 用于 python 日志级别和调试级别的 Google api 客户端不起作用

google-app-engine - Google App Engine 全局变量 (ServletContext)

authorization - FB.login 返回无效的 OAuth 访问 token

authentication - 如何在 Vaadin 应用程序中使用单点登录