更新记录
1.0.0(2026-08-18)
需要去 google申请授权吗,web,iOS,安卓,
,<!-- Google 登录:iOS Client ID -->
GIDClientID
XXXXXXXXX.apps.googleusercontent.com
<!-- URL Scheme:反向 Client ID,用于登录回调 -->
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.XXXXXXXXX/string>
</array>
</dict>
</array>
使用的案例:
Google Sign-In 验证
<input class="client-id-input" v-model="serverClientId" placeholder="Web Client ID" />
<button class="login-button" @click="signIn">登录</button>
<button class="logout-button" @click="signOut">登出</button>
状态:{{ resultText }}
用户 ID:{{ userId }}
邮箱:{{ email }}
名称:{{ displayName }}
头像:{{ avatarUrl }}
ID Token:{{ tokenState }}
import { login, logout } from '@/uni_modules/my-google-signin'
const serverClientId = ref('xxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com')//web 的 auth
const resultText = ref('等待登录')
const userId = ref('-')
const email = ref('-')
const displayName = ref('-')
const avatarUrl = ref('-')
const tokenState = ref('未获取')
function clearProfile() {
userId.value = '-'
email.value = '-'
displayName.value = '-'
avatarUrl.value = '-'
tokenState.value = '未获取'
}
function signIn() {
clearProfile()
resultText.value = '正在请求 Google 登录'
login({
serverClientId: serverClientId.value,
success: (result) => {
console.log(result)
resultText.value = '登录成功,已获得 Google ID Token'
userId.value = result.userId ?? '-'
email.value = result.email ?? 'Credential Manager 未返回,需由服务端解析 ID Token'
displayName.value = result.displayName ?? '-'
avatarUrl.value = result.avatarUrl ?? '-'
tokenState.value = '已获取,长度 ' + result.idToken.length
},
fail: (failure) => {
resultText.value = '登录失败:' + failure.errMsg
}
})
}
function signOut() {
logout({
success: () => {
clearProfile()
resultText.value = '已清除 Credential Manager 本地状态'
},
fail: (failure) => {
resultText.value = '登出失败:' + failure.errMsg
}
})
}
<style>
.verify-page {
display: flex;
flex-direction: column;
padding: 24px;
/* gap: 16rpx; */
}
.verify-title {
font-size: 20px;
color: #18212f;
}
.client-id-input {
height: 44px;
padding-left: 12px;
padding-right: 12px;
border-width: 1px;
border-style: solid;
border-color: #b7c0cc;
border-radius: 4px;
font-size: 14px;
color: #18212f;
}
.action-row {
display: flex;
flex-direction: row;
/* gap: 12px; */
}
.login-button {
flex: 1;
background-color: #1a73e8;
color: #ffffff;
}
.logout-button {
flex: 1;
background-color: #edf1f5;
color: #18212f;
}
.result-text {
font-size: 14px;
color: #425466;
white-space: normal;
}
</style>
平台兼容性
uni-app(5.21)
| Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-vue插件版本 |
app-nvue |
Android |
Android插件版本 |
iOS |
iOS插件版本 |
鸿蒙 |
| - |
- |
- |
- |
√ |
1.0.0 |
- |
6.0 |
1.0.0 |
14 |
1.0.0 |
- |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
小红书小程序 |
快应用-华为 |
快应用-联盟 |
| - |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
uni-app x(5.21)
| Chrome |
Safari |
Android |
Android插件版本 |
iOS |
iOS插件版本 |
鸿蒙 |
微信小程序 |
| - |
- |
6.0 |
1.0.0 |
14 |
1.0.0 |
- |
- |
my-google-signin
uni-app x 的 Android 与 iOS Google 登录 UTS 插件。登录成功时回传供服务端验证的 Google ID Token。
支持平台
- Android:Credential Manager 1.5.0 与 Google ID 1.1.1
- iOS:GoogleSignIn CocoaPod 7.1.0,最低 iOS 13
接入前置条件
- 在 Google Cloud Console 创建 Web 应用类型的 OAuth Client ID,并在调用
login 时作为 serverClientId 传入。
- Android 必须在 OAuth Android 客户端中配置实际应用包名与签名 SHA-1。
- iOS 的
GIDClientID 和反向 URL Scheme 位于 utssdk/app-ios/info.plist,必须替换为当前 iOS OAuth Client ID 对应的值后再构建。
- 服务端必须验证 ID Token 的签名、过期时间、
aud 与 serverClientId;客户端返回 Token 不代表服务端登录已完成。
API
login(options):发起授权并通过 success 返回 idToken、用户 ID、邮箱、显示名称和头像地址。
logout(options):清除本机 Google 登录态,不撤销用户对应用的授权。
- 失败回调只返回
errMsg,不使用业务错误码。
- Android 显式 Sign in with Google 与 iOS GoogleSignIn 流程均不支持
nonce,传入非空值会直接进入失败回调。
- Credential Manager 返回的原生资料不保证包含邮箱;服务端验证 ID Token 后应以声明中的邮箱为准。