更新记录
1.0.0(2026-03-28)
- 首次发布。
- 支持 Apple 登录、凭证状态查询与支持性判断。
平台兼容性
uni-app(5.03)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| √ | √ | - | - | √ | - | - | √ | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | - | - | - | - |
uni-app x(5.03)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| - | - | - | √ | - | - |
hans-apple-auth
Apple 登录认证 UTS 插件。
使用前提
- 工程运行在 iOS 13 及以上。
- Apple Developer 后台已为对应 App ID 开启
Sign In with Apple。 - 业务服务端负责校验
identityToken或处理authorizationCode。 - 首次授权返回的
email、fullName需要业务端及时落库,后续授权通常不会再次返回。
引入方式
import {
signInWithApple,
getAppleCredentialState,
isAppleAuthSupported,
setAppleAuthDebugEnabled,
isAppleAuthDebugEnabled,
AppleAuthSignInOptions,
AppleAuthCredentialStateOptions,
AppleAuthSignInSuccess,
AppleAuthCredentialStateResult,
AppleAuthFail
} from '@/uni_modules/hans-apple-auth'
API
isAppleAuthSupported()
返回当前设备是否支持 Apple 登录。
const supported = isAppleAuthSupported()
console.log('apple auth supported', supported)
signInWithApple(options)
发起 Apple 登录。
const options : AppleAuthSignInOptions = {
scopes: ['email', 'fullName'],
state: 'demo-state',
success: (res) => {
console.log('apple sign in success', res)
},
fail: (err) => {
console.error('apple sign in fail', err)
}
}
signInWithApple(options)
参数:
scopes: 可选,授权范围,推荐传email、fullNamestate: 可选,透传给 Apple 的 statenonce: 可选,透传给 Apple 的 noncesuccess(res: AppleAuthSignInSuccess): 成功回调fail(err: AppleAuthFail): 失败回调complete(res: AppleAuthSignInSuccess | AppleAuthFail): 完成回调
成功返回 AppleAuthSignInSuccess,字段如下:
user: Apple 用户唯一标识identityToken: Apple 返回的 JWTauthorizationCode: Apple 授权码email: 首次授权时可能返回fullName: 首次授权时可能返回state: 原样返回传入的 staterealUserStatus: Apple 返回的用户真实性状态
getAppleCredentialState(options)
查询 Apple 凭证状态。
const options : AppleAuthCredentialStateOptions = {
user: 'apple-user-id',
success: (res) => {
console.log('credential state', res)
},
fail: (err) => {
console.error('credential state fail', err)
}
}
getAppleCredentialState(options)
参数:
user: 必填,Apple 用户唯一标识success(res: AppleAuthCredentialStateResult): 成功回调fail(err: AppleAuthFail): 失败回调complete(res: AppleAuthCredentialStateResult | AppleAuthFail): 完成回调
成功返回 AppleAuthCredentialStateResult,字段如下:
user: Apple 用户唯一标识state: Apple 返回的凭证状态值stateText: 凭证状态文本
stateText 可能值:
authorizedrevokednotFoundtransferredunknown
setAppleAuthDebugEnabled(enabled)
设置是否输出调试日志。
setAppleAuthDebugEnabled(true)
参数:
enabled:true表示开启调试日志,false表示关闭调试日志
isAppleAuthDebugEnabled()
返回当前是否已开启调试日志。
const enabled = isAppleAuthDebugEnabled()
console.log('apple auth debug enabled', enabled)
错误对象
失败回调返回 AppleAuthFail,字段如下:
errCode: 插件错误码errMsg: 错误消息message: 错误描述cause: 原始错误原因,存在时可用于排查
错误码
9011001: 当前平台或系统版本不支持 Apple 登录9011002: 用户取消授权9011003: Apple 授权流程失败9011004: 返回的 credential 类型不符合预期9011005: 必要授权字段缺失9011006: 查询 credential state 失败9011007: 调用参数不合法9011008: 插件内部桥接或状态异常

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