Skip to content

Commit

Permalink
fix:运行平台改完自动识别的不需要用户在传递
Browse files Browse the repository at this point in the history
  • Loading branch information
dongfengtao committed Mar 13, 2024
1 parent 049ea9a commit 91f0565
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 36 deletions.
16 changes: 9 additions & 7 deletions examples/miniapp-taro/src/pages/index/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Authing } from '@authing/miniapp-taro'
// import { encryptFunction } from '@authing/miniapp-jsencrypt'

import { encryptFunction } from '@authing/miniapp-sm2encrypt'
const RUN_PLATFORM = 'wx'; //运行平台默认 wx
const EXT_IDP_CONNIDENTIFIER = "EXT_IDP_CONNIDENTIFIER"

const APP_SECRET = 'APP_SECRET';
Expand All @@ -19,7 +18,6 @@ const authing = new Authing({
appId: 'appId',
host: 'host',
userPoolId: 'userPoolId',
platform: RUN_PLATFORM,
encryptFunction
})

Expand Down Expand Up @@ -103,14 +101,18 @@ export default class Index extends Component<PropsWithChildren> {

const res = await authing.loginByPhone({
extIdpConnidentifier: EXT_IDP_CONNIDENTIFIER,
douyinMiniProgramCodeAndPhonePayload: {
// 之前的暂时保留
wechatMiniProgramCodeAndPhonePayload: {
wxPhoneInfo: {
code
}
},
// 通用参数
miniProgramCodeAndPhonePayload: {
phoneParams: {
code, //这个 code 需要修改一下
encryptedData,
iv,
}
},
wechatMiniProgramCodeAndPhonePayload: {
},
wxPhoneInfo: {
code
}
Expand Down
49 changes: 29 additions & 20 deletions examples/miniapp-uniapp/src/pages/index/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@
import { Authing } from '/Users/mac/Desktop/www/authing-js-sdk/packages/miniapp-uniapp/dist/bundle-uniapp'
import { encryptFunction } from '@authing/miniapp-jsencrypt'
const AUTHING_EXT_IDP_CONN_IDENTIFIER = "AUTHING_EXT_IDP_CONN_IDENTIFIER"
const RUN_PLATFORM = 'wx'; //运行平台默认抖音
const APP_SECRET = 'APP_SECRET';
const APP_ID = "APP_ID";
const authing = new Authing({
appId: "appId",
host: 'host',
userPoolId: 'userPoolId',
platform: RUN_PLATFORM,
encryptFunction
})
Expand All @@ -71,26 +69,37 @@
},
methods: {
/**
* 需要在真机上测试,微信开发者工具不会返回 code
* @param {*} e
*/
async loginByPhone (e) {
const { code } = e.detail
console.log('e: ', e)
const res = await authing.loginByPhone({
extIdpConnidentifier: AUTHING_EXT_IDP_CONN_IDENTIFIER,
wechatMiniProgramCodeAndPhonePayload: {
wxPhoneInfo: {
code
}
/**
* 需要在真机上测试,微信开发者工具不会返回 code
* @param {*} e
*/
async loginByPhone(e) {
const { code, iv, encryptedData } = e.detail;
console.log('e: ', e)
const res = await authing.loginByPhone({
extIdpConnidentifier: AUTHING_EXT_IDP_CONN_IDENTIFIER,
// 之前的暂时保留
// wechatMiniProgramCodeAndPhonePayload: {
// wxPhoneInfo: {
// code
// }
// },
// 通用参数
miniProgramCodeAndPhonePayload: {
phoneParams: {
encryptedData,
iv,
},
options: {
scope: 'openid profile offline_access'
wxPhoneInfo: {
code
}
})
console.log('authing.loginByPhone res: ', res)
},
},
options: {
scope: 'openid profile offline_access'
}
})
console.log('authing.loginByPhone res: ', res)
},
async loginByCode () {
const res = await authing.loginByCode({
Expand Down
12 changes: 6 additions & 6 deletions packages/miniapp/src/Authing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
getLoginStateKey,
getPlatformLoginCodeKey,
request,
getCurrentMiniProgram,
StorageProvider
} from './helpers'

Expand All @@ -61,7 +62,7 @@ export class Authing {
this.options = {
...options,
host: options.host || 'https://core.authing.cn',
platform: options.platform || 'wx'
platform: options.platform || getCurrentMiniProgram() || 'wx'
}

this.storage = new StorageProvider()
Expand Down Expand Up @@ -335,7 +336,7 @@ export class Authing {
const {
extIdpConnidentifier,
wechatMiniProgramCodeAndPhonePayload,
douyinMiniProgramCodeAndPhonePayload,
miniProgramCodeAndPhonePayload,
options
} = data

Expand All @@ -350,8 +351,7 @@ export class Authing {
switch (this.options.platform) {
case PlatformsMenu.wx:

const wxPhoneInfo = wechatMiniProgramCodeAndPhonePayload?.wxPhoneInfo

const wxPhoneInfo = wechatMiniProgramCodeAndPhonePayload?.wxPhoneInfo || miniProgramCodeAndPhonePayload?.wxPhoneInfo
if (!wxPhoneInfo || !wxPhoneInfo.code) {
return returnError({
message: 'wxPhoneInfo.code is required'
Expand Down Expand Up @@ -384,7 +384,7 @@ export class Authing {
break
case PlatformsMenu.tt:

const phoneParams = douyinMiniProgramCodeAndPhonePayload?.phoneParams
const phoneParams = miniProgramCodeAndPhonePayload?.phoneParams

if (!phoneParams) {
return returnError({
Expand All @@ -397,7 +397,7 @@ export class Authing {

if (!loginParamsCode) {
return returnError({
message: 'get tt login params error'
message: 'get tt login params error ,please use the miniProgramCodeAndPhonePayload'
})
}

Expand Down
15 changes: 15 additions & 0 deletions packages/miniapp/src/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Platforms,
PlatformsMenu,
} from '../types'


Expand All @@ -11,3 +12,17 @@ export function getPlatformLoginCodeKey (appId: string,platform: Platforms | und

return ['authing', appId, `${platform ? platform : 'wx' }-login-code`].join(':')
}

declare const wx: any
declare const tt: any

export function getCurrentMiniProgram():PlatformsMenu {
if (typeof tt!== 'undefined' && typeof tt.getSystemInfo !== 'undefined') {
return PlatformsMenu.tt
} else if (typeof wx !== 'undefined' && typeof wx.getSystemInfo !== 'undefined') {
return PlatformsMenu.wx
} else {
return PlatformsMenu.wx
}

}
9 changes: 6 additions & 3 deletions packages/miniapp/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,15 @@ export interface LoginByPhoneOptions {
code: string
}
}
douyinMiniProgramCodeAndPhonePayload?: {
phoneParams: {
code: string
miniProgramCodeAndPhonePayload?: {
phoneParams?: {
code?: string
iv: string
encryptedData: string
}
wxPhoneInfo?: {
code: string
}
}
options?: LoginOptions
}
Expand Down

0 comments on commit 91f0565

Please sign in to comment.