@@ -4,8 +4,10 @@ const os = require('os')
44const ini = require ( 'ini' )
55const _ = require ( 'lodash' )
66const util = require ( 'util' )
7+ const QRCode = require ( 'qrcode' )
78const TencentLogin = require ( 'tencent-login' )
89const tencentcloud = require ( 'tencentcloud-sdk-nodejs' )
10+ const { GetUserAuthInfo } = require ( 'serverless-tencent-tools' ) . Account
911const ClientProfile = require ( 'tencentcloud-sdk-nodejs/tencentcloud/common/profile/client_profile.js' )
1012const HttpProfile = require ( 'tencentcloud-sdk-nodejs/tencentcloud/common/profile/http_profile.js' )
1113const AbstractModel = require ( 'tencentcloud-sdk-nodejs/tencentcloud/common/abstract_model' )
@@ -17,7 +19,6 @@ const constants = {
1719class GetUserAppIdResponse extends AbstractModel {
1820 constructor ( ) {
1921 super ( )
20-
2122 this . RequestId = null
2223 }
2324
@@ -26,6 +27,7 @@ class GetUserAppIdResponse extends AbstractModel {
2627 return
2728 }
2829 this . AppId = 'RequestId' in params ? params . AppId : null
30+ this . OwnerUin = 'RequestId' in params ? params . OwnerUin : null
2931 this . RequestId = 'RequestId' in params ? params . RequestId : null
3032 }
3133}
@@ -54,6 +56,36 @@ class TencentProvider {
5456 return constants . providerName
5557 }
5658
59+ async getUserAuth ( uin ) {
60+ try {
61+ const getUserAuthInfo = new GetUserAuthInfo ( )
62+ const result = await getUserAuthInfo . isAuth ( uin )
63+ if ( result [ 'Error' ] == true ) {
64+ console . log ( 'Failed to get real name authentication result.' )
65+ process . exit ( - 1 )
66+ } else {
67+ if ( result [ 'Message' ] [ 'Authentication' ] == 1 ) {
68+ return true
69+ }
70+ const verifyUrl = 'https://cloud.tencent.com/verify/identity'
71+ console . log (
72+ "You don't have real name authentication yet. You can open the url or scan QR code for real name authentication."
73+ )
74+ console . log ( 'Real name authentication url: ' )
75+ console . log ( verifyUrl )
76+ console . log ( 'Real name authentication QR code: ' )
77+ QRCode . toString ( verifyUrl , { type : 'terminal' } , function ( err , url ) {
78+ console . log ( url )
79+ } )
80+ console . log ( 'Please re operate after real name authentication.' )
81+ process . exit ( - 1 )
82+ }
83+ } catch ( e ) {
84+ console . log ( e )
85+ process . exit ( - 1 )
86+ }
87+ }
88+
5789 getAppid ( credentials ) {
5890 const secret_id = credentials . SecretId
5991 const secret_key = credentials . SecretKey
@@ -137,6 +169,14 @@ class TencentProvider {
137169 uuid : tencent_credentials . uuid ,
138170 timestamp : tencent_credentials . timestamp
139171 }
172+ // From cam to getting appid
173+ const userInfo = await this . getAppid ( {
174+ SecretId : tencent . tencent_secret_id ,
175+ SecretKey : tencent . tencent_secret_key ,
176+ token : tencent . token
177+ } )
178+ tencent . tencent_owneruin = userInfo . OwnerUin
179+ tencent . tencent_appid = userInfo . AppId
140180 await fs . writeFileSync ( './.env_temp' , JSON . stringify ( tencent ) )
141181 return tencent
142182 } catch ( e ) {
@@ -152,10 +192,16 @@ class TencentProvider {
152192 try {
153193 const tencent = { }
154194 const tencent_credentials_read = JSON . parse ( data )
155- if (
156- Date . now ( ) / 1000 - tencent_credentials_read . timestamp <= 6000 &&
157- tencent_credentials_read . tencent_appid
158- ) {
195+ if ( Date . now ( ) / 1000 - tencent_credentials_read . timestamp <= 6000 ) {
196+ const userInfo = await this . getAppid ( {
197+ SecretId : tencent_credentials_read . tencent_secret_id ,
198+ SecretKey : tencent_credentials_read . tencent_secret_key ,
199+ token : tencent_credentials_read . token
200+ } )
201+
202+ // From cam to getting appid
203+ tencent_credentials_read . tencent_owneruin = userInfo . OwnerUin
204+ tencent_credentials_read . tencent_appid = userInfo . AppId
159205 return tencent_credentials_read
160206 }
161207 const login = new TencentLogin ( )
@@ -175,6 +221,14 @@ class TencentProvider {
175221 tencent . uuid = tencent_credentials_read . uuid
176222 tencent . timestamp = Date . now ( ) / 1000
177223 await fs . writeFileSync ( './.env_temp' , JSON . stringify ( tencent ) )
224+ // From cam to getting appid
225+ const userInfo = await this . getAppid ( {
226+ SecretId : tencent . tencent_secret_id ,
227+ SecretKey : tencent . tencent_secret_key ,
228+ token : tencent . token
229+ } )
230+ tencent . tencent_owneruin = userInfo . OwnerUin
231+ tencent . tencent_appid = userInfo . AppId
178232 return tencent
179233 }
180234 return await that . doLogin ( )
@@ -242,6 +296,7 @@ class TencentProvider {
242296 SecretKey : this . options . credentials . tencent_secret_key
243297 } )
244298 this . options . credentials . tencent_appid = appid . AppId
299+ this . options . credentials . tencent_owneruin = appid . OwnerUin
245300 }
246301 } catch ( e ) { }
247302 return
0 commit comments