You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google OAuth 2.0 for Android缺失client_secret与redirect_uri配置问题

Google OAuth2原生应用token兑换配置问题解决方案
  • client_secret说明:Android/iOS类型的OAuth客户端ID无需配置client_secret——移动应用无法安全存储密钥,Google针对这类原生应用的授权码兑换流程已省略该参数,发起token请求时仅需携带授权码、client_id和redirect_uri即可。
  • redirect_uri配置:
    • Android平台:默认redirect_uri为 com.googleusercontent.apps.{你的Client ID}:/oauth2redirect,将{你的Client ID}替换为你在控制台创建的Android客户端ID即可。
    • iOS平台:默认格式同上,也可自定义URL Scheme,需在Xcode项目中配置对应URL类型,同时在Google Cloud Console的iOS客户端设置中填写该Scheme。
  • 多平台登录替代方案:若Google官方Java库不满足跨平台需求,可基于OAuth2标准协议手动实现流程:
    1. 构造授权URL,包含client_id、scope、response_type=code、redirect_uri等必要参数。
    2. 唤起系统浏览器完成用户授权,获取授权码。
    3. 向https://oauth2.googleapis.com/token发送POST请求,携带grant_type=authorization_code、client_id、code、redirect_uri参数(无需client_secret),即可获取access_token和refresh_token。

内容的提问来源于stack exchange,提问作者peter.o

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 08:17:15