Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pissirSmartHome
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alfredo Chissotti
pissirSmartHome
Commits
3ef450c9
Commit
3ef450c9
authored
2 years ago
by
Elisa Giglio
Browse files
Options
Downloads
Patches
Plain Diff
fix refresh token
parent
915b9df0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
webserver/public/js/authentication/script.js
+6
-10
6 additions, 10 deletions
webserver/public/js/authentication/script.js
webserver/public/js/mqtt/mqtthat.js
+1
-1
1 addition, 1 deletion
webserver/public/js/mqtt/mqtthat.js
with
7 additions
and
11 deletions
webserver/public/js/authentication/script.js
+
6
−
10
View file @
3ef450c9
...
...
@@ -36,7 +36,7 @@ else if(uri.includes("#")){
else
{
await
requestFirstToken
(
uriAuthCode
);
// post per la richiesta del token
if
(
token
!==
null
)
{
expirationTime
=
moment
().
add
(
token
.
expires_in
,
`s`
);
expirationTime
=
moment
().
add
(
token
.
refresh_
expires_in
,
`s`
);
sessionStorage
.
setItem
(
"
expirationTime
"
,
expirationTime
.
toJSON
());
const
myDomains
=
await
RequestToDomain
.
getMyDomains
();
...
...
@@ -93,7 +93,7 @@ async function requestFirstToken(uriAuthCode) {
async
function
getToken
()
{
const
now
=
moment
();
if
(
now
-
expirationTime
<
1
)
{
if
(
expirationTime
-
now
<
60000
)
{
//this token has expired, so request new token
await
requestUsingRefreshToken
();
}
...
...
@@ -121,7 +121,7 @@ async function getToken() {
if
(
response
.
ok
)
{
alreadyRefreshed
=
true
;
sessionStorage
.
setItem
(
"
token
"
,
JSON
.
stringify
(
token
));
expirationTime
=
moment
().
add
(
token
.
expires_in
,
`s`
);
expirationTime
=
moment
().
add
(
token
.
refresh_
expires_in
,
`s`
);
sessionStorage
.
setItem
(
"
expirationTime
"
,
expirationTime
.
toJSON
());
oldTimeout
=
timeoutRefresh
();
}
...
...
@@ -140,12 +140,8 @@ function timeoutRefresh() {
clearTimeout
(
oldTimeout
);
return
setTimeout
(
async
()
=>
{
console
.
log
(
"
fired!
"
,{
alreadyRefreshed
})
if
(
!
alreadyRefreshed
)
{
await
requestUsingRefreshToken
();
alreadyRefreshed
=
false
;
console
.
log
(
"
refreshed!
"
)
}
await
requestUsingRefreshToken
();
alreadyRefreshed
=
false
;
},
(
token
.
expires_in
*
1000
)
-
5000
);
// richiedo il nuovo token 5 secondi prima che il token scada
}
...
...
@@ -164,7 +160,7 @@ async function logoutKeycloak() {
async
function
getIdToken
()
{
const
now
=
moment
();
if
(
now
-
expirationTime
<
1
)
{
if
(
expirationTime
-
now
<
60000
)
{
//this token has expired, so request new token
await
requestUsingRefreshToken
();
}
...
...
This diff is collapsed.
Click to expand it.
webserver/public/js/mqtt/mqtthat.js
+
1
−
1
View file @
3ef450c9
...
...
@@ -23,7 +23,7 @@ const connectOptions = {
onSuccess
:
onConnect
,
userName
:
"
gruppo2
"
,
password
:
"
funziona
"
,
//
useSSL: true,
useSSL
:
true
,
// cleanSession: false,
onFailure
:
onFailure
,
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment