Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
hrs_app_h5
/
bill
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c00bfb1f
authored
Jun 16, 2020
by
展昭
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
redirectPath
parent
6c58a978
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
6 deletions
src/router/index.js
src/router/index.js
View file @
c00bfb1f
...
...
@@ -38,7 +38,7 @@ function getAccessToken(authcode) {
let
commonPms
=
GetCommonPms
();
let
url
=
`
${
oidc_config
.
authority
}
/connect/token?
${
commonPms
}
`
;
let
pms
=
{
"client_id"
:
oidc_config
.
client_id
,
"client_id"
:
oidc_config
.
client_id
,
"client_secret"
:
oidc_config
.
client_secret
,
"grant_type"
:
"auth_code"
,
"scope"
:
"openid offline_access"
,
...
...
@@ -46,9 +46,9 @@ function getAccessToken(authcode) {
}
axios
.
post
(
url
,
qs
.
stringify
(
pms
)).
then
(
res
=>
{
if
(
res
&&
res
.
status
)
{
console
.
log
(
'res.data='
,
res
.
data
);
console
.
log
(
'res.data='
,
res
.
data
);
const
accessToken
=
res
.
data
.
access_token
;
console
.
log
(
'accessToken='
,
accessToken
);
console
.
log
(
'accessToken='
,
accessToken
);
resolve
(
accessToken
);
}
else
{
...
...
@@ -59,7 +59,7 @@ function getAccessToken(authcode) {
});
}
async
function
getToken
(
access_token
,
appid
,
next
)
{
async
function
getToken
(
access_token
,
appid
,
redirectPath
)
{
let
pms
=
{
client_id
:
oidc_config
.
client_id
,
client_secret
:
oidc_config
.
client_secret
,
...
...
@@ -79,7 +79,7 @@ async function getToken(access_token, appid, next) {
if
(
res
.
status
==
200
)
{
const
accessToken
=
res
.
data
.
access_token
;
localStorage
.
setItem
(
"token"
,
accessToken
);
next
()
this
.
$router
.
push
(
redirectPath
);
}
},
err
=>
{
...
...
@@ -91,17 +91,34 @@ async function getToken(access_token, appid, next) {
});
}
function
getPathByTo
(
to
,
authcode_key
)
{
let
toPath
=
to
.
path
||
"/"
;
for
(
let
key
in
to
.
query
)
{
if
(
key
==
authcode_key
)
{
continue
;
}
toPath
+=
toPath
.
indexOf
(
"?"
)
>
-
1
?
"&"
:
"?"
;
toPath
+=
`
${
key
}
=
${
to
.
query
[
key
]}
`
;
}
toPath
=
toPath
.
indexOf
(
'?'
)
>
-
1
?
toPath
+
"&t="
+
(
new
Date
()).
valueOf
()
:
toPath
+
"?t="
+
(
new
Date
()).
valueOf
();
return
toPath
;
}
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
const
authcode
=
to
.
query
.
authCode
||
to
.
query
.
authcode
;
const
appid
=
to
.
query
.
appId
||
to
.
query
.
appid
;
if
(
!!
authcode
&&
!!
appid
)
{
getAccessToken
(
authcode
).
then
(
res
=>
{
const
token
=
res
;
getToken
(
token
,
appid
,
next
);
const
redirectPath
=
getPathByTo
(
to
,
'authcode'
);
getToken
(
token
,
appid
,
redirectPath
);
}).
catch
(
err
=>
{
console
.
log
(
'err='
,
err
);
})
}
else
{
next
()
}
...
...
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