更新记录
1.0.0(2026-05-27)
1.0.0 首次发布,支持 uni-app App iOS 端拉起 Google 登录并获取 serverAuthCode,提供退出登录接口。
平台兼容性
uni-app(5.0)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| × | √ | × | × | × | × | × | 12 | × |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| × | × | × | × | × | × | × | × | × | × | × | × |
my-google-login
my-google-login 是一个面向 uni-app 的 UTS API 插件,当前版本仅支持 App iOS 平台。
插件能力非常聚焦:
- 拉起 iOS 原生 Google 登录
- 获取服务端登录所需的
serverAuthCode - 提供退出登录接口
googleLogout
本插件不负责直接换取 access token,也不封装你的业务登录接口。推荐用法是:App 侧获取 serverAuthCode 后,交给你自己的服务端完成 OAuth 换 token 与业务登录。
平台支持
| 平台 | 支持情况 |
|---|---|
| uni-app Vue2 | 支持 |
| uni-app Vue3 | 支持 |
| App iOS | 支持 |
| App Android | 暂不支持 |
| App Harmony | 暂不支持 |
| H5 | 暂不支持 |
| 各类小程序 | 暂不支持 |
| uni-app x | 暂未验证 |
插件依赖
- iOS 原生依赖:
GoogleSignIn 9.0.0 - iOS 最低系统版本:
12.0
相关配置见 uni_modules/my-google-login/utssdk/app-ios/config.json。
接口说明
getGoogleCode(options)
拉起 Google 登录并返回服务端可用的 serverAuthCode。
参数
type GoogleLoginOptions = {
clientId: string
serverClientId: string
success?: (res: GoogleLoginSuccess) => void
fail?: (res: GoogleLoginFail) => void
complete?: (res: GoogleLoginSuccess | GoogleLoginFail) => void
}
type GoogleLoginSuccess = {
code: string
}
参数说明
clientId:Google Cloud 中创建的 iOS OAuth Client IDserverClientId:Google Cloud 中创建的 Web / Server OAuth Client ID,用于返回serverAuthCode
googleLogout()
退出当前 Google 登录状态。
使用前准备
1. 在 Google Cloud Console 创建 OAuth 客户端
你至少需要准备两类 Client ID:
- 一个
iOS Client ID - 一个
Web / Server Client ID
其中:
clientId传 iOS Client IDserverClientId传 Web / Server Client ID
2. 配置 iOS 回调信息
当前插件版本在 uni_modules/my-google-login/utssdk/app-ios/Info.plist 中声明了 Google 登录所需的配置。
你需要将下面两个值替换成你自己的配置:
GIDClientIDCFBundleURLSchemes
示例:
<key>GIDClientID</key>
<string>你的-iOS-client-id.apps.googleusercontent.com</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.你的反转clientid</string>
</array>
</dict>
</array>
注意:CFBundleURLSchemes 必须与你在 Google 后台生成的 iOS Client ID 对应,否则登录回调会失败。
3. 在页面中调用插件
<script setup>
// #ifdef APP-PLUS
import { getGoogleCode, googleLogout } from '@/uni_modules/my-google-login'
// #endif
const GOOGLE_IOS_CLIENT_ID = '你的iOSClientID.apps.googleusercontent.com'
const GOOGLE_SERVER_CLIENT_ID = '你的ServerClientID.apps.googleusercontent.com'
const handleGoogleLogin = () => {
// #ifdef APP-PLUS
getGoogleCode({
clientId: GOOGLE_IOS_CLIENT_ID,
serverClientId: GOOGLE_SERVER_CLIENT_ID,
success: (res) => {
console.log('Google serverAuthCode:', res.code)
// 将 res.code 发送给你的服务端换取 token
},
fail: (err) => {
console.error('Google 登录失败:', err)
}
})
// #endif
}
const handleGoogleLogout = () => {
// #ifdef APP-PLUS
googleLogout()
// #endif
}
</script>
接入流程建议
推荐接入链路如下:
- App 调用
getGoogleCode - 插件返回
serverAuthCode - App 将
code提交到你的服务端 - 服务端向 Google 换取 token 或用户身份信息
- 服务端生成你自己的登录态并返回给 App
错误码说明
| 错误码 | 说明 |
|---|---|
| 9011001 | Google 登录失败 |
| 9011002 | 未获取到 Google 授权码 |
| 9011003 | 参数不合法,通常是 clientId 或 serverClientId 为空 |
| 9011004 | 当前页面上下文不可用,无法拉起原生登录页 |
注意事项
- 当前版本仅实现
iOS,请勿在 Android、Harmony、H5 或小程序平台调用 - 插件返回的是
serverAuthCode,不是accessToken,也不是idToken - 如果你要发布到正式环境,请务必使用你自己的 Google Cloud 配置,不要保留示例中的 Client ID
- 如果登录成功后没有拿到
code,优先检查serverClientId是否为服务端 Client ID - 如果无法正常回调,优先检查
Info.plist中的URL Scheme是否与 iOS Client ID 完全匹配
隐私声明
- 插件自身不采集、不存储、不上传业务数据
- 插件不包含广告
- 插件不申请相机、定位、麦克风、通讯录、短信等敏感权限
- 登录过程中会通过 Google 官方 SDK 与 Google 官方服务通信,以完成授权登录
目录结构
uni_modules/my-google-login
├─ package.json
├─ readme.md
├─ changelog.md
└─ utssdk
├─ interface.uts
├─ unierror.uts
└─ app-ios
├─ config.json
├─ index.uts
└─ Info.plist

收藏人数:
购买普通授权版(
试用
赞赏(0)
下载 0
赞赏 0
下载 12063302
赞赏 1917
赞赏
京公网安备:11010802035340号