Android端Google Sign-In的默认重定向URI是什么?
Android Google OAuth 正确默认重定向URL 问题
出于安全考量,Google不建议启用自定义重定向URL。若未开启该选项,必须使用官方指定的默认重定向URL,否则登录流程会触发「Custom URI scheme is not enabled for your Android client」错误。目前在Cloud Console中勾选「Enable custom URI scheme」后登录可正常运行,说明问题仅在于未使用正确的默认重定向URL,但官方文档未明确给出该URL的具体格式。
核心疑问:Google要求的Android默认重定向URL是什么?
- iOS端官方有明确指引:需使用格式为
com.googleusercontent.apps.CLIENT_ID:/oauth2redirect/google的重定向URL(官方初始建议仅提及com.googleusercontent.apps.CLIENT_ID,但实际需添加路径才能生效)。 - Android端已尝试以下多种变体,但均无效(除非禁用安全限制):
com.googleusercontent.apps.CLIENT_ID:/oauth2redirect/googlePACKAGE_NAME:/oauth2redirect/google的各类变体
正确的Android默认重定向URL
当未启用自定义URI scheme时,Google要求的Android默认重定向URI为:
com.googleusercontent.apps.<你的客户端ID>
无需额外添加路径部分。同时需要确保你的AndroidManifest.xml中配置了对应的intent-filter,示例如下:
<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="com.googleusercontent.apps.1234567890abcdefghijklmnopqrstuvwxyz" /> </intent-filter>
其中1234567890abcdefghijklmnopqrstuvwxyz需替换为你在Cloud Console中注册的实际客户端ID,且客户端ID必须与Android客户端的配置完全匹配。
内容的提问来源于stack exchange,提问作者The Beruriah Incident
相关产品推荐
相关产品推荐

