Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
catalog.genesys-pgr.org
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Catalog
catalog.genesys-pgr.org
Commits
d39b8158
Commit
d39b8158
authored
Oct 22, 2018
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix: SSR cookie token check and cookie handling
parent
e2e67b03
Pipeline
#7140
passed with stages
in 7 minutes and 11 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
13 deletions
+15
-13
server/middleware/checkAuthToken.ts
server/middleware/checkAuthToken.ts
+6
-4
src/actions/login.ts
src/actions/login.ts
+3
-3
src/ui/layout/Header/index.tsx
src/ui/layout/Header/index.tsx
+1
-1
src/ui/pages/login/LoginPage.tsx
src/ui/pages/login/LoginPage.tsx
+1
-1
src/utilities/index.ts
src/utilities/index.ts
+4
-4
No files found.
server/middleware/checkAuthToken.ts
View file @
d39b8158
...
...
@@ -23,15 +23,17 @@ export default function checkAuthToken(req, res, dispatch) {
console
.
log
(
'
Init checkAuthToken method
'
);
return
checkAuthTokenRequest
(
req
,
dispatch
)
.
then
((
data
)
=>
{
console
.
log
(
'
Setting cookie
'
,
data
.
access_token
);
res
.
cookie
(
'
access_token
'
,
data
.
access_token
,
{
path
:
'
/
'
});
console
.
log
(
`Setting cookie to expire in
${
data
.
exp
}
ms from`
,
data
);
res
.
cookie
(
'
access_token
'
,
data
.
access_token
,
{
path
:
'
/
'
,
maxAge
:
data
.
exp
});
if
(
data
.
authorities
)
{
res
.
cookie
(
'
authorities
'
,
JSON
.
stringify
(
data
.
authorities
),
{
path
:
'
/
'
});
res
.
cookie
(
'
authorities
'
,
JSON
.
stringify
(
data
.
authorities
),
{
path
:
'
/
'
,
maxAge
:
data
.
exp
});
}
else
{
res
.
clearCookie
(
'
authorities
'
);
}
return
data
;
}).
catch
((
x
)
=>
{
console
.
log
(
'
Failed checkAuthToken
'
,
x
);
console
.
log
(
'
Failed checkAuthToken, clearing cookies
'
,
x
);
res
.
clearCookie
(
'
access_token
'
);
res
.
clearCookie
(
'
authorities
'
);
});
}
src/actions/login.ts
View file @
d39b8158
...
...
@@ -12,7 +12,7 @@ export function checkAccessTokens(dispatch) {
const
applicationLogin
=
()
=>
LoginService
.
loginApp
()
.
then
((
data
)
=>
{
saveCookies
({
access_token
:
data
.
access_token
,
authorities
:
[
ROLE_CLIENT
]});
saveCookies
({
access_token
:
data
.
access_token
,
authorities
:
[
ROLE_CLIENT
]}
,
data
.
exp
);
dispatch
(
loginApp
(
data
));
})
.
catch
((
error
)
=>
{
...
...
@@ -75,7 +75,7 @@ export const loginRequest = (username, password) => (dispatch) => {
return
LoginService
.
login
(
username
,
password
)
.
then
((
data
)
=>
{
saveCookies
(
data
);
saveCookies
(
data
,
data
.
exp
);
return
dispatch
(
loginUser
(
data
));
});
};
...
...
@@ -103,7 +103,7 @@ export const verifyGoogleTokenRequest = (accessToken) => (dispatch, getState) =>
return
LoginService
.
verifyGoogleToken
(
token
,
accessToken
)
.
then
((
data
)
=>
{
saveCookies
(
data
);
saveCookies
(
data
,
data
.
exp
);
return
dispatch
(
loginApp
(
data
));
});
};
...
...
src/ui/layout/Header/index.tsx
View file @
d39b8158
...
...
@@ -124,7 +124,7 @@ 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
]});
saveCookies
({
access_token
:
data
.
access_token
,
authorities
:
[
ROLE_CLIENT
]}
,
data
.
exp
);
this
.
props
.
history
.
push
(
'
/login
'
);
});
}
...
...
src/ui/pages/login/LoginPage.tsx
View file @
d39b8158
...
...
@@ -33,7 +33,7 @@ class LoginContainer extends React.Component<ILoginContainerProps, void> {
return
checkTokenRequest
(
access_token
);
})
.
then
((
data
)
=>
{
saveCookies
(
data
);
saveCookies
(
data
,
data
.
exp
);
history
.
push
(
'
/dashboard
'
);
return
false
;
}).
catch
((
e
)
=>
{
...
...
src/utilities/index.ts
View file @
d39b8158
...
...
@@ -96,10 +96,10 @@ export function cleanFilters(filter, keysToSkip?): string {
return
result
;
}
export
function
saveCookies
(
resp
)
{
log
(
'
Saving cookies
'
);
cookies
.
set
(
'
access_token
'
,
resp
.
access_token
,
{
path
:
'
/
'
});
cookies
.
set
(
'
authorities
'
,
JSON
.
stringify
(
resp
.
authorities
),
{
path
:
'
/
'
});
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
clearCookies
()
{
...
...
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