Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dspace7 Angular
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
vtechworks
Dspace7 Angular
Commits
1f953b6b
Commit
1f953b6b
authored
7 years ago
by
Giuseppe Digilio
Browse files
Options
Downloads
Patches
Plain Diff
Fixes
parent
0ed1f777
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/core/auth/auth.service.ts
+25
-15
25 additions, 15 deletions
src/app/core/auth/auth.service.ts
src/app/core/auth/models/auth-token-info.model.ts
+7
-3
7 additions, 3 deletions
src/app/core/auth/models/auth-token-info.model.ts
with
32 additions
and
18 deletions
src/app/core/auth/auth.service.ts
+
25
−
15
View file @
1f953b6b
...
...
@@ -19,6 +19,7 @@ import { ResetAuthenticationMessagesAction, SetRedirectUrlAction } from './auth.
import
{
RouterReducerState
}
from
'
@ngrx/router-store
'
;
import
{
CookieAttributes
}
from
'
js-cookie
'
;
import
{
NativeWindowRef
,
NativeWindowService
}
from
'
../../shared/services/window.service
'
;
import
{
PlatformService
}
from
'
../../shared/services/platform.service
'
;
export
const
LOGIN_ROUTE
=
'
/login
'
;
...
...
@@ -38,6 +39,7 @@ export class AuthService {
constructor
(@
Inject
(
NativeWindowService
)
private
_window
:
NativeWindowRef
,
private
authRequestService
:
AuthRequestService
,
private
platform
:
PlatformService
,
private
router
:
Router
,
private
storage
:
CookieService
,
private
store
:
Store
<
AppState
>
)
{
...
...
@@ -289,8 +291,13 @@ export class AuthService {
* Redirect to the login route when token has expired
*/
public
redirectToLoginWhenTokenExpired
()
{
// Hard redirect to login page, so that all state is definitely lost
this
.
_window
.
nativeWindow
.
location
.
href
=
LOGIN_ROUTE
+
'
?expired=true
'
;
const
redirectUrl
=
LOGIN_ROUTE
+
'
?expired=true
'
;
if
(
this
.
_window
.
nativeWindow
.
location
)
{
// Hard redirect to login page, so that all state is definitely lost
this
.
_window
.
nativeWindow
.
location
.
href
=
redirectUrl
;
}
else
{
this
.
router
.
navigateByUrl
(
redirectUrl
);
}
}
/**
...
...
@@ -301,24 +308,20 @@ export class AuthService {
.
first
()
.
subscribe
((
redirectUrl
)
=>
{
if
(
isNotEmpty
(
redirectUrl
))
{
this
.
clearRedirectUrl
();
const
urlTree
:
UrlTree
=
this
.
router
.
parseUrl
(
redirectUrl
);
const
g
:
UrlSegmentGroup
=
urlTree
.
root
.
children
[
PRIMARY_OUTLET
];
const
segment
=
'
/
'
+
g
.
toString
();
const
navigationExtras
:
NavigationExtras
=
{
queryParams
:
urlTree
.
queryParams
,
queryParamsHandling
:
'
merge
'
};
this
.
router
.
navigate
([
segment
],
navigationExtras
);
}
else
{
if
(
this
.
platform
.
isBrowser
)
{
console
.
log
(
'
CLEAR REDIRECT!!!!
'
)
this
.
clearRedirectUrl
();
}
// override the route reuse strategy
this
.
router
.
routeReuseStrategy
.
shouldReuseRoute
=
()
=>
{
return
false
;
};
this
.
router
.
navigated
=
false
;
const
url
=
decodeURIComponent
(
this
.
router
.
u
rl
);
const
url
=
decodeURIComponent
(
redirectU
rl
);
this
.
router
.
navigateByUrl
(
url
);
}
else
{
this
.
router
.
navigate
([
'
/
'
]);
}
})
...
...
@@ -328,6 +331,7 @@ export class AuthService {
* Refresh route navigated
*/
public
refreshAfterLogout
()
{
this
.
router
.
navigate
([
'
/home
'
]);
// Hard redirect to home page, so that all state is definitely lost
this
.
_window
.
nativeWindow
.
location
.
href
=
'
/home
'
;
}
...
...
@@ -348,7 +352,13 @@ export class AuthService {
* Set redirect url
*/
setRedirectUrl
(
url
:
string
)
{
this
.
storage
.
set
(
REDIRECT_COOKIE
,
url
);
// Add 1 day to the current date
const
expireDate
=
Date
.
now
()
+
(
1000
*
60
*
60
*
24
*
1
);
// Set the cookie expire date
const
expires
=
new
Date
(
expireDate
);
const
options
:
CookieAttributes
=
{
expires
:
expires
};
this
.
storage
.
set
(
REDIRECT_COOKIE
,
url
,
options
);
this
.
store
.
dispatch
(
new
SetRedirectUrlAction
(
isNotUndefined
(
url
)
?
url
:
''
));
}
...
...
This diff is collapsed.
Click to expand it.
src/app/core/auth/models/auth-token-info.model.ts
+
7
−
3
View file @
1f953b6b
...
...
@@ -8,8 +8,12 @@ export class AuthTokenInfo {
constructor
(
token
:
string
)
{
this
.
accessToken
=
token
.
replace
(
'
Bearer
'
,
''
);
const
tokenClaims
=
decode
(
this
.
accessToken
);
// exp claim is in seconds, convert it se to milliseconds
this
.
expires
=
tokenClaims
.
exp
*
1000
;
try
{
const
tokenClaims
=
decode
(
this
.
accessToken
);
// exp claim is in seconds, convert it se to milliseconds
this
.
expires
=
tokenClaims
.
exp
*
1000
;
}
catch
(
err
)
{
this
.
expires
=
0
;
}
}
}
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