更新记录

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 插件。

使用前提

  1. 工程运行在 iOS 13 及以上。
  2. Apple Developer 后台已为对应 App ID 开启 Sign In with Apple
  3. 业务服务端负责校验 identityToken 或处理 authorizationCode
  4. 首次授权返回的 emailfullName 需要业务端及时落库,后续授权通常不会再次返回。

引入方式

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: 可选,授权范围,推荐传 emailfullName
  • state: 可选,透传给 Apple 的 state
  • nonce: 可选,透传给 Apple 的 nonce
  • success(res: AppleAuthSignInSuccess): 成功回调
  • fail(err: AppleAuthFail): 失败回调
  • complete(res: AppleAuthSignInSuccess | AppleAuthFail): 完成回调

成功返回 AppleAuthSignInSuccess,字段如下:

  • user: Apple 用户唯一标识
  • identityToken: Apple 返回的 JWT
  • authorizationCode: Apple 授权码
  • email: 首次授权时可能返回
  • fullName: 首次授权时可能返回
  • state: 原样返回传入的 state
  • realUserStatus: 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 可能值:

  • authorized
  • revoked
  • notFound
  • transferred
  • unknown

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: 插件内部桥接或状态异常

隐私、权限声明

1. 本插件需要申请的系统权限列表:

无需额外系统权限

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件本身不上传数据,业务服务器会接收 Apple 凭据用于登录校验

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

暂无用户评论。