[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"public-article:200":3},{"id":4,"createdAt":5,"title":6,"content":7,"summary":8,"image":9,"uid":10,"user":11,"categoryId":18,"category":19,"subCategoryId":21,"subCategory":22,"comments":24,"status":14,"reason":25,"notice":25,"visitCount":26,"commentCount":27,"keywords":28},200,"2026-11-09T04:15:31.823Z","【Google】Google OAuth登录的Cloud配置","## 一、背景\n在配置Android App的Google授权登录时，需要在[](http://console.cloud.google.com/)和[](http://play.google.com/)进行配置，这里形成文档，供后续新Android App配置参考使用。\n\n## 二、OAuth配置\nGoogle OAuth开发文档网址：[](https://developers.google.com/identity/protocols/oauth2?hl=zh-cn)\nGoogle OAuth的配置网址：[](https://console.cloud.google.com)\n\\\n前提条件：\n- 成为Google play开发者，能访问Play Store Console后台\n\n### 2.1 创建Google project\n在OAuth配置网址，按下列截图流程依次创建一个Android app项目\n![image.png](https://image.xinwei.ltd/image1794196836433.png 'image.png')\n\n\\\n填入项目名字，组织和父组织可以选择“No organization”\n![image.png](https://image.xinwei.ltd/image1794196857026.png 'image.png')\n\n### 2.2 配置OAuth\n如下图，一步步进入到OAuth的配置（这里假设刚创建project中的project name是test-flow）\n![image.png](https://image.xinwei.ltd/image1794196894419.png 'image.png')\n\\\n![image.png](https://image.xinwei.ltd/image1794196905640.png 'image.png')\n\\\n![image.png](https://image.xinwei.ltd/image1794196926377.png 'image.png')\n\\\n点击\"Get started\"后，一步步完成project配置\n![image.png](https://image.xinwei.ltd/image1794196944964.png 'image.png')\n\\\n这里输入app的名字，选择你的Google开发者邮箱\n![image.png](https://image.xinwei.ltd/image1794196963752.png 'image.png')\n\\\n这里选择“外部”受众，就可以让所有有Google账号的用户可以使用app中的Google服务。\n![image.png](https://image.xinwei.ltd/image1794196979415.png 'image.png')\n\\\n还是输入开发者Google邮箱即可，推荐统一使用开发者邮箱接收信息（这里的邮箱可以输入多个）。\n![image.png](https://image.xinwei.ltd/image1794197002318.png 'image.png')\n\n\\\n完成配置\n![image.png](https://image.xinwei.ltd/image1794197013452.png 'image.png')\n![image.png](https://image.xinwei.ltd/image1794197030302.png 'image.png')\n\n### 2.3 配置Android客户端\n紧接2.2的步骤，是需要配置一个客户端，对于我们来说，就是可以在一个project下创建不同平台的客户端。\n具体操作，紧跟2.2后如下面的截图，选择Android类型\n![image.png](https://image.xinwei.ltd/image1794197047499.png 'image.png')\n选择完Android类型后，是需要配置Android应用信息的步骤\n下图中的信息：\n- Name: 就取Android app名字就好（不会被app用户看到的客户端名字定义）\n- package name：包名 （非开发人员可以问开发人员获取）\n- SHA-1 签名：这里需要打开Play Store开发者后台去获取Google play的SHA-1签名\n（可以看截图中的那行描述文字，在google play console的相应位置去获取）\nFor Google Play distribution, find the fingerprint in the Google Play Console under \"Protected with Play > Play Store protection > Manage Play app signing\". For other distributions (such as local APKs), use this command to get the fingerprint:\n![image.png](https://image.xinwei.ltd/image1794197064170.png 'image.png')\n（如下是google play console中的SHA-1签名位置如下）\n![image.png](https://image.xinwei.ltd/image1794197079231.png 'image.png')\n\\\n点击“创建”\n![image.png](https://image.xinwei.ltd/image1794197097903.png 'image.png')\n\n\\\n弹出了成功弹窗，提示可以下载配置的json文件（可以下或者不下载，因为都能找得到配置）\n![image.png](https://image.xinwei.ltd/image1794197117588.png 'image.png')\n\\\n完成创建后，client菜单页面中就显示了这个Android app的一个OAuth的【Google Play签名】的配置项（这里的Android client 1就是刚刚2.2中的Name输入框中默认的名字，可以修改）。\n![image.png](https://image.xinwei.ltd/image1794197133268.png 'image.png')\n\n> 之前弹窗中和这里列表中显示的“Client ID”，可以点击复制下来，供Android开发者使用。\n\n### 2.4 配置Web Client OAuth\n在2.3中我们配置了Android类型的Google play store签名的OAuth Client ID，这句话一定要注意。\nGoogle play store签名的OAuth Client ID，指的是从Google play下载的不管内测还是发布的app，都可以使用这个client  ID去调用Google OAuth API服务\nAndroid app的OAuth client ID配置好后，那么就需要给服务端配置一个Web OAuth Client ID，目的就是让服务端可以配置服务端用的Google OAuth SDK的client ID。\n\n接下来的流程，如下面的图所示：\n![image.png](https://image.xinwei.ltd/image1794197248450.png 'image.png')\n![image.png](https://image.xinwei.ltd/image1794197258280.png 'image.png')\n\\\n在web client id创建时，可以只输入一个名字，下面红色框内的域名配置，我们可以等会到左侧菜单栏的【Branding】的配置项中去配置，如果这里配置了当然也会像截图中的tip所说“会自动配置到授权内容部分”。\n\n![image.png](https://image.xinwei.ltd/image1794197283615.png 'image.png')\n\\\n创建完成，并一定要留意弹窗【留意创建完成后的弹窗】\n![image.png](https://image.xinwei.ltd/image1794197305234.png 'image.png')\n> 【特别注意】【特别注意】【特别注意】\n这里一定要下载这个JSON文件并妥善保存，这里的secret是提供给服务端使用的（虽然当前，依然可以进入创建的这个web client ID中查看secret，但不保证后续Google会取消web client id中查看secret的功能，所以最好按照Google提示下载并妥善保存）。\n\n![image.png](https://image.xinwei.ltd/image1794197329676.png 'image.png')\n\n### 2.5 特别注意【生效时间几个小时到1天不等，所有app要提前配置好】\n我们在创建Android OAuth Client ID 和 Web OAuth Client ID的时候，下方“创建”按钮上方，都有提示“Note: It may take 5 minutes to a few hours for settings to take effect”，生效时间是不确定的。\n> 按照最近几次的创建经历，生效时间在3小时到6小时左右，所以如果有用到Google OAuth API服务的App，都是需要提前配置好这些，避免时间损耗。\n\n![image.png](https://image.xinwei.ltd/image1794197360913.png 'image.png')\n\n### 2.6 配置未生效时App中的表现\n当Google 的OAuth配置还没有生效时，那么最常见的现象，就是在Android app中点击Google授权登录，尽管弹出了Google邮箱选择弹窗，但是点击邮箱，会一直报错：[16] Account reauth failed.\n\n```code\nerror = {GoogleSignInException} GoogleSignInException(code GoogleSignInExceptionCode.canceled, [16] Account reauth failed., null)\n code = {GoogleSignInExceptionCode} GoogleSignInExceptionCode.canceled\n  index = 1\n  _name = \"canceled\"\n description = \"[16] Account reauth failed.\"\n details = null\n```\n\n### 2.7 先看Audience\n这里表示的是，是否把该project设置为对外公开，并且发布状态的地方。\n含义解释：对外公开External才能让拥有Google账号的用户使用我们的app，前提条件是当前project需要已发布状态，而要把project发布，就需要先配置Branding.否则应用就只能被Google play console的内测许可邮箱测试使用，外部用户无法使用app中的Google OAuth服务.\n\n> 也就是说当前project最终需要的Branding中的状态是：In production、External.\n\n所以下一步，先去步骤2.8 中配置Branding.\n![image.png](https://image.xinwei.ltd/image1794197457145.png 'image.png')\n\n### 2.8 配置Branding（当前Google要求Branding中必须全部配置）\n如这个页面中所示，对于早期的Google开发者邮箱的Cloud中的配置，是不需要配置如下截图中的App domain的，但是最近新建的Google Cloud中提示是必须都要输入的。\n![image.png](https://image.xinwei.ltd/image1794197474466.png 'image.png')\n\n![image.png](https://image.xinwei.ltd/image1794197483902.png 'image.png')\n\n- App Name：填Android app的名字\n- User support email：Android app客服邮箱，使用开发者Google邮箱也可\n- App logo：上传一个120*120 px的App logo即可\n- App domain中提供\n1. Application home page:  Android app应用的首页h5网址\n2. Application privacy policy link：Android app中的隐私网址\n3. Application terms of service link：Android app中的用户协议网址\n- Authorized domains\n这里就直接填写你在上方3个输入框中填写的一级域名即可，是可以添加多个的，你点击“Add domain”按钮就可以添加\n比如你在3个输入框中使用到的网址分别是：1. https://app.google-app.com/index；2. https://www.google-app.com/privacy; 3. https://h5.google-app.com/consent; \n那么你在这个输入的地方就应该添加1个一级域名：google-app.com 即可\n\n\\\n示例如下：\n![image.png](https://image.xinwei.ltd/image1794197530061.png 'image.png')\n![image.png](https://image.xinwei.ltd/image1794197537990.png 'image.png')\n![image.png](https://image.xinwei.ltd/image1794197547591.png 'image.png')\n再回到Audience中将project的状态进行发布。\n\n### 2.9 在Audience中发布project\n现在回到Audience中，“发布 app”按钮才会是可以点击的。如果你之前在创建project的时候选择了“internal”，那么这时你也应该在下面截图中的\"User type\"中选择“External”。\n\n![image.png](https://image.xinwei.ltd/image1794197568867.png 'image.png')\n![image.png](https://image.xinwei.ltd/image1794197580545.png 'image.png')\n\\\n点击“确认”后，project变成了“In production”状态\n![image.png](https://image.xinwei.ltd/image1794197594681.png 'image.png')\n\n### 3.0  配置Project的OAuth数据请求范围\n这项配置是允许OAuth API可以获取的信息，指使用Google账号登录app的那些用户，他们的哪些信息会被我们获取到。\n按照下图去新增scopes.\n![image.png](https://image.xinwei.ltd/image1794197612970.png 'image.png')\n\\\n勾选前三项\n![image.png](https://image.xinwei.ltd/image1794197628543.png 'image.png')\n\n\\\n勾选后记得点击“更新”按钮保存修改\n![image.png](https://image.xinwei.ltd/image1794197647751.png 'image.png')\n\\\n加完后，就有显示在下方的数据范围列表\n![image.png](https://image.xinwei.ltd/image1794197671729.png 'image.png')\n\n## 三、总结\n经过上面所有的配置，我们来看各个开发端能拿到的信息\n- Android开发者能拿到：\n1. Android OAuth Client ID；\n2. Web OAuth Client ID；\n\n- Web server后端开发者能拿到：\n1. Web OAuth Client ID；\n2. Web OAuth Client Secret；\n3. Android应用的包名；\n\n那么Android端和服务端就可以拿着这些信息进行各自端SDK的集成去实现Google OAuth服务.\n\n> 截图中出现的一些\"品牌验证\"(Branding Verification)三角符号的警告或者提醒，暂时可以忽略，不影响Google OAuth业务功能。\n\n","想让App、网站支持 Google 账号登录，首先要在 Google Cloud 控制台完成 OAuth 2.0 配置。本文介绍如何创建项目、设置 OAuth 同意屏幕和测试用户、创建 Web 应用的 OAuth 客户端，并给出详细的图示，一步一步操作即可完成Google OAuth的配置。","https://image.xinwei.ltd/image1794196836433.png 'image.png'",499668042977349,{"phone":12,"userId":10,"nickName":13,"vipType":14,"avatar":15,"sign":16,"createdAt":17},"13121171998","全栈老韩",1,"https://image.xinwei.ltd/images/IMG_5430.JPG","全栈工程师，擅长iOS App开发、前端（vue、react、nuxt、小程序&Taro）开发、Flutter、React Native、后端（midwayjs、golang、express、koa）开发、docker容器、seo优化等。","2024-01-01T16:14:30.305Z",2,{"id":18,"name":20},"IT技术",10,{"id":21,"name":23,"parentId":18},"Android",[],"",21,0,"Google OAuth, Android OAuth, Google OAuth 登录配置, Google Cloud OAuth 2.0 配置教程,Google 第三方登录接入, Google Auth Platform 配置,Google OAuth Client ID 创建,Google OAuth redirect_uri_mismatch 解决方法"]