Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello_uni-id-pages
提交
b47d5cc9
H
hello_uni-id-pages
项目概览
DCloud
/
hello_uni-id-pages
通知
1062
Star
33
Fork
43
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
2
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello_uni-id-pages
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
b47d5cc9
编写于
7月 27, 2022
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: config utils
上级
17c1aaca
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
109 addition
and
105 deletion
+109
-105
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/utils.js
...d-pages/uniCloud/cloudfunctions/uni-id-co/common/utils.js
+1
-21
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
...i-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
+4
-4
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/third-party/index.js
...niCloud/cloudfunctions/uni-id-co/lib/third-party/index.js
+4
-27
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/config.js
...ges/uniCloud/cloudfunctions/uni-id-co/lib/utils/config.js
+68
-3
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/weixin.js
...ges/uniCloud/cloudfunctions/uni-id-co/lib/utils/weixin.js
+2
-8
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/dev/get-supported-login-type.js
...unctions/uni-id-co/module/dev/get-supported-login-type.js
+30
-42
未找到文件。
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/utils.js
浏览文件 @
b47d5cc9
...
...
@@ -163,25 +163,6 @@ function coverMobile (mobile) {
return
mobile
.
slice
(
0
,
3
)
+
'
****
'
+
mobile
.
slice
(
7
)
}
function
getOauthConfig
(
params
=
{})
{
const
{
config
,
oatuhProivder
,
clientPlatform
,
requiredItem
=
[]
}
=
params
if
(
!
config
.
oauth
||
!
config
.
oauth
[
oatuhProivder
])
{
throw
new
Error
(
`Missing config param:
${
clientPlatform
}
.
${
oatuhProivder
}
`
)
}
const
oauthConfig
=
config
.
oauth
[
oatuhProivder
]
requiredItem
.
forEach
((
item
)
=>
{
if
(
!
oauthConfig
[
item
])
{
throw
new
Error
(
`Missing config param:
${
clientPlatform
}
.
${
oatuhProivder
}
.
${
item
}
`
)
}
})
return
oauthConfig
}
module
.
exports
=
{
getType
,
isValidString
,
...
...
@@ -196,6 +177,5 @@ module.exports = {
snake2camelJson
,
getExtension
,
getVerifyCode
,
coverMobile
,
getOauthConfig
coverMobile
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
浏览文件 @
b47d5cc9
...
...
@@ -102,10 +102,10 @@ module.exports = {
})
// 包含uni-id配置合并等功能的工具集
this
.
config
=
new
ConfigUtils
({
appId
:
clientInfo
.
appId
,
platform
:
clientPlatform
})
.
getPlatformConfig
()
this
.
config
Utils
=
new
ConfigUtils
({
context
:
this
})
this
.
config
=
this
.
configUtils
.
getPlatformConfig
()
this
.
validator
=
new
Validator
()
/**
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/third-party/index.js
浏览文件 @
b47d5cc9
...
...
@@ -4,54 +4,31 @@ const AliAccount = require('./alipay/account/index')
const
AppleAccount
=
require
(
'
./apple/account/index
'
)
const
createApi
=
require
(
'
./share/create-api
'
)
const
{
getOauthConfig
}
=
require
(
'
../../common/utils
'
)
module
.
exports
=
{
initWeixin
:
function
()
{
const
oauthConfig
=
getOauthConfig
({
config
:
this
.
config
,
oatuhProivder
:
'
weixin
'
,
clientPlatform
:
this
.
clientPlatform
,
requiredItem
:
[
'
appid
'
,
'
appsecret
'
]
})
const
oauthConfig
=
this
.
configUtils
.
getOauthConfig
({
provider
:
'
weixin
'
})
return
createApi
(
WxAccount
,
{
appId
:
oauthConfig
.
appid
,
secret
:
oauthConfig
.
appsecret
})
},
initQQ
:
function
()
{
const
oauthConfig
=
getOauthConfig
({
config
:
this
.
config
,
oatuhProivder
:
'
qq
'
,
clientPlatform
:
this
.
clientPlatform
,
requiredItem
:
[
'
appid
'
,
'
appsecret
'
]
})
const
oauthConfig
=
this
.
configUtils
.
getOauthConfig
({
provider
:
'
qq
'
})
return
createApi
(
QQAccount
,
{
appId
:
oauthConfig
.
appid
,
secret
:
oauthConfig
.
appsecret
})
},
initAlipay
:
function
()
{
const
oauthConfig
=
getOauthConfig
({
config
:
this
.
config
,
oatuhProivder
:
'
alipay
'
,
clientPlatform
:
this
.
clientPlatform
,
requiredItem
:
[
'
appid
'
,
'
privateKey
'
]
})
const
oauthConfig
=
this
.
configUtils
.
getOauthConfig
({
provider
:
'
alipay
'
})
return
createApi
(
AliAccount
,
{
appId
:
oauthConfig
.
appid
,
privateKey
:
oauthConfig
.
privateKey
})
},
initApple
:
function
()
{
const
oauthConfig
=
getOauthConfig
({
config
:
this
.
config
,
oatuhProivder
:
'
apple
'
,
clientPlatform
:
this
.
clientPlatform
,
requiredItem
:
[
'
bundleId
'
]
})
const
oauthConfig
=
this
.
configUtils
.
getOauthConfig
({
provider
:
'
apple
'
})
return
createApi
(
AppleAccount
,
{
bundleId
:
oauthConfig
.
bundleId
})
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/config.js
浏览文件 @
b47d5cc9
const
{
getWeixinPlatform
}
=
require
(
'
./weixin
'
)
const
requiredConfig
=
{
'
web.h5-weixin
'
:
[
'
appid
'
,
'
appsecret
'
],
'
web.web-weixin
'
:
[
'
appid
'
,
'
appsecret
'
],
'
app.weixin
'
:
[
'
appid
'
,
'
appsecret
'
],
'
mp-weixin.weixin
'
:
[
'
appid
'
,
'
appsecret
'
],
'
app.qq
'
:
[
'
appid
'
,
'
appsecret
'
],
'
mp-alipay.alipay
'
:
[
'
appid
'
,
'
privateKey
'
],
'
app.apple
'
:
[
'
bundleId
'
]
}
class
ConfigUtils
{
constructor
({
appId
,
platform
context
}
=
{})
{
this
.
context
=
context
this
.
clientInfo
=
context
.
getClientInfo
()
const
{
appId
,
uniPlatform
}
=
this
.
clientInfo
this
.
appId
=
appId
this
.
platform
=
platform
switch
(
uniPlatform
)
{
case
'
app
'
:
case
'
app-plus
'
:
this
.
platform
=
'
app
'
break
case
'
web
'
:
case
'
h5
'
:
this
.
platform
=
'
web
'
break
default
:
this
.
platform
=
uniPlatform
break
}
}
getConfigArray
()
{
...
...
@@ -47,6 +77,41 @@ class ConfigUtils {
}
return
Object
.
assign
(
defaultConfig
,
appConfig
,
appConfig
[
platform
])
}
getOauthProvider
({
provider
}
=
{})
{
const
clientPlatform
=
this
.
platform
let
oatuhProivder
=
provider
if
(
provider
===
'
weixin
'
&&
clientPlatform
===
'
web
'
)
{
const
weixinPlatform
=
getWeixinPlatform
.
call
(
this
.
context
)
if
(
weixinPlatform
===
'
h5
'
||
weixinPlatform
===
'
web
'
)
{
oatuhProivder
=
weixinPlatform
+
'
-weixin
'
// h5-weixin 公众号,web-weixin pc端
}
}
return
oatuhProivder
}
getOauthConfig
({
provider
}
=
{})
{
const
config
=
this
.
getPlatformConfig
()
const
clientPlatform
=
this
.
platform
const
oatuhProivder
=
this
.
getOauthConfig
({
provider
})
const
requireConfigKey
=
requiredConfig
[
`
${
clientPlatform
}
.
${
oatuhProivder
}
`
]
||
[]
if
(
!
config
.
oauth
||
!
config
.
oauth
[
oatuhProivder
])
{
throw
new
Error
(
`Config param required:
${
clientPlatform
}
.
${
oatuhProivder
}
`
)
}
const
oauthConfig
=
config
.
oauth
[
oatuhProivder
]
requireConfigKey
.
forEach
((
item
)
=>
{
if
(
!
oauthConfig
[
item
])
{
throw
new
Error
(
`Config param required:
${
clientPlatform
}
.
${
oatuhProivder
}
.
${
item
}
`
)
}
})
return
oauthConfig
}
}
module
.
exports
=
ConfigUtils
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/weixin.js
浏览文件 @
b47d5cc9
...
...
@@ -5,19 +5,13 @@ const {
const
{
ERROR
}
=
require
(
'
../../common/error
'
)
const
{
getOauthConfig
}
=
require
(
'
../../common/utils
'
)
function
decryptWeixinData
({
encryptedData
,
sessionKey
,
iv
}
=
{})
{
const
oauthConfig
=
getOauthConfig
({
config
:
this
.
config
,
oatuhProivder
:
'
weixin
'
,
clientPlatform
:
this
.
clientPlatform
,
requiredItem
:
[
'
appid
'
]
const
oauthConfig
=
this
.
configUtils
.
getOauthConfig
({
provider
:
'
weixin
'
})
const
decipher
=
crypto
.
createDecipheriv
(
'
aes-128-cbc
'
,
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/dev/get-supported-login-type.js
浏览文件 @
b47d5cc9
function
isMobileCodeSupported
(
config
)
{
function
isMobileCodeSupported
()
{
const
config
=
this
.
config
return
!!
(
config
.
service
&&
config
.
service
.
sms
&&
config
.
service
.
sms
.
smsKey
)
}
function
isUniverifySupport
(
config
)
{
function
isUniverifySupport
()
{
const
config
=
this
.
config
return
!!
(
config
.
service
&&
config
.
service
.
univerify
&&
config
.
service
.
univerify
.
apiKey
)
}
function
isWeixinSupported
(
config
)
{
return
!!
(
config
.
oauth
&&
config
.
oauth
.
weixin
&&
config
.
oauth
.
weixin
.
appsecret
)
function
isWeixinSupported
()
{
this
.
configUtils
.
getOauthConfig
({
provider
:
'
weixin
'
})
return
true
}
function
isQQSupported
(
config
)
{
return
!!
(
config
.
oauth
&&
config
.
oauth
.
qq
&&
config
.
oauth
.
qq
.
appsecret
)
function
isQQSupported
()
{
this
.
configUtils
.
getOauthConfig
({
provider
:
'
qq
'
})
return
true
}
function
isAppleSupported
(
config
)
{
return
!!
(
config
.
oauth
&&
config
.
oauth
.
apple
&&
config
.
oauth
.
apple
.
bundleId
)
function
isAppleSupported
()
{
this
.
configUtils
.
getOauthConfig
({
provider
:
'
apple
'
})
return
true
}
function
isAlipaySupported
(
config
)
{
return
!!
(
config
.
oauth
&&
config
.
oauth
.
alipay
&&
config
.
oauth
.
alipay
.
privateKey
)
function
isAlipaySupported
()
{
this
.
configUtils
.
getOauthConfig
({
provider
:
'
alipay
'
})
return
true
}
const
loginTypeTester
=
{
...
...
@@ -31,49 +45,23 @@ const loginTypeTester = {
alipay
:
isAlipaySupported
}
const
ConfigUtils
=
require
(
'
../../lib/utils/config
'
)
/**
* 获取支持的登录方式
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#get-supported-login-type
* @param {Object} params
* @param {String} params.appId 应用AppId
* @param {String} params.platform 应用平台
* @returns
*/
module
.
exports
=
function
(
params
=
{})
{
const
schema
=
{
appId
:
{
type
:
'
string
'
,
required
:
false
},
platform
:
{
type
:
'
string
'
,
required
:
false
}
}
this
.
middleware
.
validate
(
params
,
schema
)
const
{
appId
,
platform
}
=
params
const
{
appId
:
currentAppId
}
=
this
.
getClientInfo
()
const
currentPlatform
=
this
.
clientPlatform
const
config
=
new
ConfigUtils
({
appId
:
appId
||
currentAppId
,
platform
:
platform
||
currentPlatform
}).
getPlatformConfig
()
module
.
exports
=
function
()
{
const
supportedLoginType
=
[
'
username-password
'
,
'
mobile-password
'
,
'
email-password
'
]
for
(
const
type
in
loginTypeTester
)
{
if
(
loginTypeTester
[
type
](
config
))
{
supportedLoginType
.
push
(
type
)
}
try
{
if
(
loginTypeTester
[
type
].
call
(
this
))
{
supportedLoginType
.
push
(
type
)
}
}
catch
(
error
)
{}
}
return
{
errCode
:
0
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录