我在 Android Studio 中设置了一些云端点,并实现了一个身份验证器 (com.google.api.server.spi.config.Authenticator),每次调用云端点时都会调用该身份验证器。
现在我想使用我的身份验证器通过 GiTkit(Google Identity Toolkit)检查 Android 的登录情况。当我调试端点时,我可以使用本地 URL(如 http://localhost:8080/_ah/api/userApi/v1/login/)检查它们。 。 在 Android 模拟器中,本地环回地址为 10.0.2.2,因此 URL 为 http://10.0.2.2:8080/_ah/api/userApi/v1/login/ (在 Android 浏览器中运行)。
但我无法在 Google 开发者控制台(Web 应用程序的客户端 ID)中将 localhost 形式的授权重定向 URI 更改为此 URL。 (无效重定向: http://10.0.2.2:8080/_ah/api/userApi/v1/login/ 必须以公共(public)顶级域(例如 .com 或 .org)结尾)
如何在 Android 模拟器(或手机)中与 GiTkit 一起调试我的 Cloud Endpoint?
最佳答案
我从 Derek Salama 那里得到了答案,在 Google 群组中这是不可能的:https://groups.google.com/forum/#!topic/google-identity-toolkit/RNyW8xN7q7E
Hi Martin,
You're correct that the redirect URI for the Client ID cannot be an IP address, and thus http://10.0.2.2:8080/ doesn't work while http://localhost:8080 does.
I don't know of any magic that would let you access the localhost from an Android emulator without using the IP address. When developing with Identity Toolkit and Cloud Endpoints, I first test the Authenticator implementation with the Endpoints API explorer (after using curl to get a valid ID token). Once I'm confident the authenticator is working, I deploy to appengine and test the Android app against a live instance.
我现在已经根据https://developers.google.com/identity/toolkit/web/setup-frontend设置了一个本地主机示例站点以便于调试。
关于android - 如何在 Android 模拟器中使用 GiTkit 调试 Cloudendpoints,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30847088/