Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Catalog
catalog.genesys-pgr.org
Commits
1e3fe909
Commit
1e3fe909
authored
Oct 23, 2018
by
Matija Obreza
Browse files
Fix: set correct Auth cookie expiry times
parent
6cecf9fb
Pipeline
#7187
passed with stages
in 6 minutes and 57 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
server/middleware/checkAuthToken.ts
View file @
1e3fe909
...
...
@@ -24,10 +24,10 @@ export default function checkAuthToken(req, res, dispatch) {
console
.
log
(
'
Init checkAuthToken method
'
);
return
checkAuthTokenRequest
(
req
,
dispatch
)
.
then
((
data
)
=>
{
console
.
log
(
`Setting cookie to expire in
${
data
.
exp
}
ms
from`
,
data
);
res
.
cookie
(
'
access_token
'
,
data
.
access_token
,
{
path
:
'
/
'
,
maxAge
:
data
.
exp
||
data
.
expires_in
||
/* 1hr */
1000
*
60
*
60
});
console
.
log
(
`Setting cookie to expire in
${
(
data
.
exp
||
data
.
expires_in
)
/
60
}
min
from`
,
data
);
res
.
cookie
(
'
access_token
'
,
data
.
access_token
,
{
path
:
'
/
'
,
expires
:
new
Date
(
data
.
exp
*
1000
||
new
Date
().
getTime
()
+
((
data
.
expires_in
*
1000
)
||
(
/* 1hr */
1000
*
60
*
60
)))
});
if
(
data
.
authorities
)
{
res
.
cookie
(
'
authorities
'
,
JSON
.
stringify
(
data
.
authorities
),
{
path
:
'
/
'
,
maxAge
:
data
.
exp
||
data
.
expires_in
||
/* 1hr */
1000
*
60
*
60
});
res
.
cookie
(
'
authorities
'
,
JSON
.
stringify
(
data
.
authorities
),
{
path
:
'
/
'
,
expires
:
new
Date
(
data
.
exp
*
1000
||
new
Date
().
getTime
()
+
((
data
.
expires_in
*
1000
)
||
(
/* 1hr */
1000
*
60
*
60
)))
});
}
else
{
res
.
clearCookie
(
'
authorities
'
);
}
...
...
src/actions/login.ts
View file @
1e3fe909
...
...
@@ -12,7 +12,8 @@ export function checkAccessTokens(dispatch) {
const
applicationLogin
=
()
=>
LoginService
.
loginApp
()
.
then
((
data
)
=>
{
saveCookies
({
access_token
:
data
.
access_token
,
authorities
:
[
ROLE_CLIENT
]},
data
.
exp
);
// console.log('loginApp token', data);
saveCookies
({
access_token
:
data
.
access_token
,
authorities
:
[
ROLE_CLIENT
]},
data
.
exp
*
1000
||
new
Date
().
getTime
()
+
data
.
expires_in
*
1000
);
dispatch
(
loginApp
(
data
));
})
.
catch
((
error
)
=>
{
...
...
@@ -75,7 +76,8 @@ export const loginRequest = (username, password) => (dispatch) => {
return
LoginService
.
login
(
username
,
password
)
.
then
((
data
)
=>
{
saveCookies
(
data
,
data
.
exp
);
// console.log('User login token', data);
saveCookies
(
data
,
data
.
exp
*
1000
||
new
Date
().
getTime
()
+
data
.
expires_in
*
1000
);
return
dispatch
(
loginUser
(
data
));
});
};
...
...
@@ -103,7 +105,8 @@ export const verifyGoogleTokenRequest = (accessToken) => (dispatch, getState) =>
return
LoginService
.
verifyGoogleToken
(
token
,
accessToken
)
.
then
((
data
)
=>
{
saveCookies
(
data
,
data
.
exp
);
// console.log('Verified Google token', data);
saveCookies
(
data
,
data
.
exp
*
1000
||
new
Date
().
getTime
()
+
data
.
expires_in
*
1000
);
return
dispatch
(
loginApp
(
data
));
});
};
...
...
src/ui/layout/Header/index.tsx
View file @
1e3fe909
...
...
@@ -124,7 +124,8 @@ class Header extends React.Component<IHeaderProps | any, any> {
this
.
props
.
logoutRequest
()
.
then
(()
=>
this
.
props
.
loginAppRequest
())
.
then
((
data
)
=>
{
saveCookies
({
access_token
:
data
.
access_token
,
authorities
:
[
ROLE_CLIENT
]},
data
.
exp
);
// console.log('Logout', data);
saveCookies
({
access_token
:
data
.
access_token
,
authorities
:
[
ROLE_CLIENT
]},
data
.
exp
*
1000
||
new
Date
().
getTime
()
+
data
.
expires_in
*
1000
);
this
.
props
.
history
.
push
(
'
/login
'
);
});
}
...
...
src/ui/pages/login/LoginPage.tsx
View file @
1e3fe909
import
*
as
React
from
'
react
'
;
import
{
connect
}
from
'
react-redux
'
;
import
{
bindActionCreators
}
from
'
redux
'
;
import
{
saveCookies
}
from
'
utilities
'
;
import
{
connect
}
from
'
react-redux
'
;
import
{
bindActionCreators
}
from
'
redux
'
;
import
*
as
_
from
'
lodash
'
;
import
{
log
}
from
'
utilities/debug
'
;
import
{
log
}
from
'
utilities/debug
'
;
import
{
loginRequest
,
checkTokenRequest
}
from
'
actions/login
'
;
import
{
loginRequest
,
checkTokenRequest
}
from
'
actions/login
'
;
import
ContentHeader
from
'
ui/common/heading/ContentHeader
'
;
...
...
@@ -33,7 +32,6 @@ class LoginContainer extends React.Component<ILoginContainerProps, void> {
return
checkTokenRequest
(
access_token
);
})
.
then
((
data
)
=>
{
saveCookies
(
data
,
data
.
exp
);
history
.
push
(
'
/dashboard
'
);
return
false
;
}).
catch
((
e
)
=>
{
...
...
src/utilities/index.ts
View file @
1e3fe909
...
...
@@ -96,10 +96,11 @@ export function cleanFilters(filter, keysToSkip?): string {
return
result
;
}
export
function
saveCookies
(
resp
,
exp
:
number
)
{
log
(
`Saving cookies to expire after
${
exp
}
ms`
);
cookies
.
set
(
'
access_token
'
,
resp
.
access_token
,
{
path
:
'
/
'
,
expires
:
new
Date
(
new
Date
().
getTime
()
+
exp
)
});
cookies
.
set
(
'
authorities
'
,
JSON
.
stringify
(
resp
.
authorities
),
{
path
:
'
/
'
,
expires
:
new
Date
(
new
Date
().
getTime
()
+
exp
)
});
export
function
saveCookies
(
resp
,
expireOn
:
number
)
{
const
expDate
=
new
Date
(
expireOn
);
log
(
`Saving cookies to expire on
${
expDate
}
`
);
cookies
.
set
(
'
access_token
'
,
resp
.
access_token
,
{
path
:
'
/
'
,
expires
:
expDate
});
cookies
.
set
(
'
authorities
'
,
JSON
.
stringify
(
resp
.
authorities
),
{
path
:
'
/
'
,
expires
:
expDate
});
}
export
function
clearCookies
()
{
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment