Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Tools glue
ng-ebi-authorization
Commits
37b3301b
Commit
37b3301b
authored
Feb 22, 2018
by
Eduardo Sanz García
Browse files
refactor: more suitable types and correct typos
docs: prepare-commit-msg
parent
de76015b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
24 deletions
+31
-24
CONTRIBUTING.md
CONTRIBUTING.md
+7
-0
src/app/app.component.ts
src/app/app.component.ts
+2
-2
src/app/modules/auth/auth.service.ts
src/app/modules/auth/auth.service.ts
+22
-22
No files found.
CONTRIBUTING.md
View file @
37b3301b
...
...
@@ -23,6 +23,13 @@ you set a `pre-commit` git hook in this way:
ln -s ../../githooks/pre-commit .git/hooks/pre-commit
```
Optionally, to help you to adhere to the standard commit messages in the repo
we recommend the use of the following
`prepare-commit-msg`
git hook:
```
ln -s ../../githooks/prepare-commit-msg .git/hooks/prepare-commit-msg
```
Then download the dependencies.
```
...
...
src/app/app.component.ts
View file @
37b3301b
...
...
@@ -35,7 +35,7 @@ export class AppComponent implements OnInit {
expiration
:
Observable
<
Date
|
null
>
;
constructor
(
// Public for demostration purposes
// Public for demo
n
stration purposes
public
auth
:
AuthService
,
private
jwt
:
JwtHelperService
)
{
...
...
@@ -62,7 +62,7 @@ export class AppComponent implements OnInit {
}
ngOnInit
()
{
// Demostration of register and unregister login events
// Demo
n
stration of register and unregister login events
this
.
auth
.
addLogInEventListener
(()
=>
alert
(
'
Welcome
'
));
this
.
auth
.
addLogInEventListener
(()
=>
console
.
log
(
'
Welcome
'
));
const
firstEventID
=
this
.
auth
.
addLogInEventListener
(()
=>
console
.
log
(
'
This should not be visible
'
));
...
...
src/app/modules/auth/auth.service.ts
View file @
37b3301b
...
...
@@ -43,28 +43,28 @@ export class AuthService {
private
_timeoutID
:
number
|
undefined
=
undefined
;
// Configuration
readonly
domain
:
string
;
readonly
aa
pURL
:
string
;
readonly
storageUpdater
:
(
newToken
:
any
)
=>
void
;
readonly
storageRemover
:
()
=>
void
;
private
readonly
_
domain
:
string
;
private
readonly
_ap
pURL
:
string
;
private
readonly
_
storageUpdater
:
(
newToken
:
any
)
=>
void
;
private
readonly
_
storageRemover
:
()
=>
void
;
// This two properties are used for inter-window communcation.
// It is achieve through the update of the dummy key storage 'commKeyName'
readonly
commKeyName
=
'
AngularAapAuthUpdated
'
;
readonly
commKeyUpdater
=
()
=>
localStorage
.
setItem
(
this
.
commKeyName
,
''
+
new
Date
().
getTime
());
// It is achieve through the update of the dummy key storage '
_
commKeyName'
private
readonly
_
commKeyName
=
'
AngularAapAuthUpdated
'
;
private
readonly
_
commKeyUpdater
=
()
=>
localStorage
.
setItem
(
this
.
_
commKeyName
,
''
+
new
Date
().
getTime
());
constructor
(
private
_rendererFactory
:
RendererFactory2
,
private
_tokenService
:
TokenService
,
@
Inject
(
AAP_CONFIG
)
private
config
:
AuthConfig
)
{
this
.
domain
=
encodeURIComponent
(
window
.
location
.
origin
);
this
.
aa
pURL
=
config
.
aapURL
.
replace
(
/
\/
$/
,
''
);
this
.
storageUpdater
=
config
.
tokenUpdater
;
this
.
_
domain
=
encodeURIComponent
(
window
.
location
.
origin
);
this
.
_ap
pURL
=
config
.
aapURL
.
replace
(
/
\/
$/
,
''
);
this
.
_
storageUpdater
=
config
.
tokenUpdater
;
if
(
config
.
tokenRemover
)
{
this
.
storageRemover
=
config
.
tokenRemover
;
this
.
_
storageRemover
=
config
.
tokenRemover
;
}
else
{
this
.
storageRemover
=
()
=>
config
.
tokenUpdater
(
null
);
this
.
_
storageRemover
=
()
=>
config
.
tokenUpdater
(
null
);
}
const
renderer
=
this
.
_rendererFactory
.
createRenderer
(
null
,
null
);
...
...
@@ -188,7 +188,7 @@ export class AuthService {
.
map
(
key
=>
[
key
,
options
[
key
]])
.
reduce
((
accumulator
,
keyvalue
)
=>
`
${
accumulator
}
&
${
keyvalue
[
0
]}
=
${
keyvalue
[
1
]}
`
,
''
);
}
return
`
${
this
.
aa
pURL
}
/sso?from=
${
this
.
domain
}${
extra
}
`
;
return
`
${
this
.
_ap
pURL
}
/sso?from=
${
this
.
_
domain
}${
extra
}
`
;
}
/**
...
...
@@ -228,11 +228,11 @@ export class AuthService {
* to 'this' when used in setTimeout call.
*/
public
logOut
()
{
this
.
storageRemover
();
this
.
_
storageRemover
();
this
.
_updateCredentials
();
// Triggers updating other windows
this
.
commKeyUpdater
();
this
.
_
commKeyUpdater
();
}
/**
...
...
@@ -291,26 +291,26 @@ export class AuthService {
if
(
!
this
.
messageIsAcceptable
(
event
))
{
return
;
}
this
.
storageUpdater
(
event
.
data
);
this
.
_
storageUpdater
(
event
.
data
);
event
.
source
.
close
();
this
.
_updateCredentials
();
// Triggers updating other windows
this
.
commKeyUpdater
();
this
.
_
commKeyUpdater
();
});
}
/** Listen to changes in the token from *other* windows.
*
* For inter-window communication messages are transmitted trough changes
* on a dummy storage key property: 'commKeyName'.
* on a dummy storage key property: '
_
commKeyName'.
*
* Notice that changes in the 'commKeyName' produced by this class doesn't
* Notice that changes in the '
_
commKeyName' produced by this class doesn't
* trigger this event.
*/
private
_listenChangesFromOtherWindows
(
renderer
:
Renderer2
)
{
renderer
.
listen
(
'
window
'
,
'
storage
'
,
(
event
:
StorageEvent
)
=>
{
if
(
event
.
key
===
this
.
commKeyName
)
{
if
(
event
.
key
===
this
.
_
commKeyName
)
{
this
.
_updateCredentials
();
}
});
...
...
@@ -321,7 +321,7 @@ export class AuthService {
* the SSO URL, otherwise it's iffy and shouldn't trust it.
*/
private
messageIsAcceptable
(
event
:
MessageEvent
):
boolean
{
return
event
.
origin
===
this
.
aa
pURL
;
return
event
.
origin
===
this
.
_ap
pURL
;
}
private
_updateCredentials
()
{
...
...
@@ -346,7 +346,7 @@ export class AuthService {
const
delay
=
+
expireDate
-
+
new
Date
();
this
.
_timeoutID
=
window
.
setTimeout
(()
=>
this
.
logOut
(),
delay
);
}
else
{
this
.
storageRemover
();
// Cleanup possible left behind token
this
.
_
storageRemover
();
// Cleanup possible left behind token
this
.
_credentials
.
next
(
null
);
this
.
_logoutCallbacks
.
map
(
callback
=>
callback
&&
callback
());
}
...
...
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