Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
a94910ea
Commit
a94910ea
authored
Nov 13, 2020
by
wangyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: (authCtl) 磐农项目 token function 优化
parent
e0513e66
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
21 deletions
+9
-21
icp-deliver/app/base/controller/impl/auth/authCtl.js
+9
-21
No files found.
icp-deliver/app/base/controller/impl/auth/authCtl.js
View file @
a94910ea
...
@@ -5,6 +5,7 @@ var settings = require("../../../../config/settings");
...
@@ -5,6 +5,7 @@ var settings = require("../../../../config/settings");
const
CtlBase
=
require
(
"../../ctl.base"
);
const
CtlBase
=
require
(
"../../ctl.base"
);
const
axios
=
require
(
"axios"
);
const
axios
=
require
(
"axios"
);
const
co
=
require
(
"co"
);
class
AuthCtl
extends
CtlBase
{
class
AuthCtl
extends
CtlBase
{
constructor
()
{
constructor
()
{
...
@@ -29,24 +30,7 @@ class AuthCtl extends CtlBase {
...
@@ -29,24 +30,7 @@ class AuthCtl extends CtlBase {
async
getOpenToken
(
body
)
{
async
getOpenToken
(
body
)
{
const
url
=
`
${
settings
.
ydzUrl
()}
/auth/getToken`
const
url
=
`
${
settings
.
ydzUrl
()}
/auth/getToken`
const
ydzKey
=
settings
.
ydzKey
();
const
ydzKey
=
settings
.
ydzKey
();
let
params
=
{
return
await
this
.
publicTokenFun
(
url
,
"authorization_code"
,
ydzKey
.
appKey
,
body
.
code
,
"code"
);
grantType
:
"authorization_code"
,
appKey
:
ydzKey
.
appKey
,
redirectUri
:
""
,
code
:
body
.
code
}
const
res
=
await
this
.
getRequest
(
url
,
params
);
if
(
res
.
data
.
code
==
200
)
{
let
ydzToken
=
{
access_token
:
res
.
data
.
result
.
access_token
,
refresh_token
:
res
.
data
.
result
.
refresh_token
}
const
addRedisResult
=
await
this
.
redisClient
.
setWithEx
(
'ydzToken'
,
JSON
.
stringify
(
ydzToken
),
6
*
24
*
60
*
60
);
// const getRedisResult = await this.redisClient.get('ydzToken');
return
system
.
getResult
(
addRedisResult
);
}
else
{
return
system
.
getResultFail
(
201
,
res
.
data
.
message
);
}
}
}
/**
/**
...
@@ -56,11 +40,15 @@ class AuthCtl extends CtlBase {
...
@@ -56,11 +40,15 @@ class AuthCtl extends CtlBase {
const
url
=
`
${
settings
.
ydzUrl
()}
/auth/refreshToken`
const
url
=
`
${
settings
.
ydzUrl
()}
/auth/refreshToken`
const
ydzKey
=
settings
.
ydzKey
();
const
ydzKey
=
settings
.
ydzKey
();
const
getRedisResult
=
JSON
.
parse
(
await
this
.
redisClient
.
get
(
'ydzToken'
)).
refresh_token
;
const
getRedisResult
=
JSON
.
parse
(
await
this
.
redisClient
.
get
(
'ydzToken'
)).
refresh_token
;
return
await
this
.
publicTokenFun
(
url
,
"refresh_token"
,
ydzKey
.
appKey
,
getRedisResult
,
"refreshToken"
)
}
async
publicTokenFun
(
url
,
grantType
,
appKey
,
data
,
specialKey
)
{
let
params
=
{
let
params
=
{
grantType
:
"refresh_token"
,
grantType
,
appKey
:
ydzKey
.
appKey
,
appKey
refreshToken
:
getRedisResult
}
}
params
[
specialKey
]
=
data
;
const
res
=
await
this
.
getRequest
(
url
,
params
);
const
res
=
await
this
.
getRequest
(
url
,
params
);
if
(
res
.
data
.
code
==
200
)
{
if
(
res
.
data
.
code
==
200
)
{
let
ydzToken
=
{
let
ydzToken
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment