1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- const {
- preBind,
- postBind
- } = require('../../lib/utils/relate')
- const {
- LOG_TYPE
- } = require('../../common/constants')
- const {
- ERROR
- } = require('../../common/error')
- const {
- initApple
- } = require('../../lib/third-party/index')
- /**
- * 绑定苹果账号
- * @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#bind-apple
- * @param {Object} params
- * @param {String} params.identityToken 苹果登录返回identityToken
- * @returns
- */
- module.exports = async function (params = {}) {
- const schema = {
- identityToken: 'string'
- }
- this.middleware.validate(params, schema)
- const uid = this.authInfo.uid
- const {
- identityToken
- } = params
- const appleApi = initApple.call(this)
- let verifyResult
- try {
- verifyResult = await appleApi.verifyIdentityToken(identityToken)
- } catch (error) {
- await this.middleware.uniIdLog({
- success: false,
- type: LOG_TYPE.BIND_APPLE
- })
- throw {
- errCode: ERROR.GET_THIRD_PARTY_ACCOUNT_FAILED
- }
- }
- const {
- openid
- } = verifyResult
- const bindAccount = {
- apple_openid: openid
- }
- await preBind.call(this, {
- uid,
- bindAccount,
- logType: LOG_TYPE.BIND_APPLE
- })
- return postBind.call(this, {
- uid,
- bindAccount,
- extraData: {},
- logType: LOG_TYPE.BIND_APPLE
- })
- }
|