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
ed53fa05
Commit
ed53fa05
authored
Jul 05, 2018
by
Pau Ruiz i Safont
Browse files
feature: use sub instead of email as username
Also exposed email as it can be of use for the webapps
parent
6fdc794b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
15 deletions
+51
-15
README.md
README.md
+6
-0
src/app/app.component.html
src/app/app.component.html
+2
-0
src/app/app.component.ts
src/app/app.component.ts
+2
-0
src/app/modules/auth/auth.service.spec.ts
src/app/modules/auth/auth.service.spec.ts
+13
-3
src/app/modules/auth/auth.service.ts
src/app/modules/auth/auth.service.ts
+28
-12
No files found.
README.md
View file @
ed53fa05
...
...
@@ -95,6 +95,7 @@ import {
<div *ngIf="(credentials | async) as user; else loggedOut">
<p>Real name: {{ user.realname }}</p>
<p>Username: {{ user.username }}</p>
<p>Email: {{ user.email }}</p>
<p>Token: {{ user.token }}</p>
</div>
<ng-template #loggedOut>
...
...
@@ -153,6 +154,7 @@ import {
export
class
AppComponent
implements
OnInit
{
username
:
Observable
<
string
|
null
>
;
realname
:
Observable
<
string
|
null
>
;
email
:
Observable
<
string
|
null
>
;
token
:
Observable
<
string
|
null
>
;
isAuthenticated
:
Observable
<
string
>
;
...
...
@@ -162,6 +164,7 @@ export class AppComponent implements OnInit {
)
{
this
.
username
=
auth
.
username
();
this
.
realname
=
auth
.
realname
();
this
.
email
=
auth
.
email
();
this
.
token
=
auth
.
token
();
this
.
isAuthenticated
=
auth
.
isAuthenticated
().
pipe
(
...
...
@@ -260,6 +263,7 @@ import {
<p>Real name: {{ realname|async }}</p>
<p>Username: {{ username|async }}</p>
<p>Email: {{ email|async }}</p>
<p>Expiration: {{ expiration|async }}</p>
<p>ISS: {{ iss|async }}</p>
<p>Token: {{ token|async }}</p>
...
...
@@ -268,6 +272,7 @@ import {
export
class
AppComponent
implements
OnInit
{
username
:
Observable
<
string
|
null
>
;
realname
:
Observable
<
string
|
null
>
;
email
:
Observable
<
string
|
null
>
;
token
:
Observable
<
string
|
null
>
;
// How to obtain other claims
...
...
@@ -281,6 +286,7 @@ export class AppComponent implements OnInit {
)
{
this
.
username
=
auth
.
username
();
this
.
realname
=
auth
.
realname
();
this
.
email
=
auth
.
email
();
this
.
token
=
auth
.
token
();
this
.
expiration
=
this
.
token
.
pipe
(
...
...
src/app/app.component.html
View file @
ed53fa05
...
...
@@ -12,6 +12,7 @@
<div
*ngIf=
"(credentials | async) as user; else loggedOut"
>
<p>
Real name: {{ user.realname }}
</p>
<p>
Username: {{ user.username }}
</p>
<p>
Email: {{ user.email }}
</p>
<p>
Token: {{ user.token }}
</p>
</div>
<ng-template
#loggedOut
>
...
...
@@ -23,6 +24,7 @@
<p>
Authenticated: {{ isAuthenticated|async }}
</p>
<p>
Real name: {{ realname|async }}
</p>
<p>
Username: {{ username|async }}
</p>
<p>
Email: {{ email|async }}
</p>
<p>
Expiration: {{ expiration|async }}
</p>
<p>
Token: {{ token|async }}
</p>
</div>
src/app/app.component.ts
View file @
ed53fa05
...
...
@@ -28,6 +28,7 @@ export class AppComponent implements OnInit {
// More specific
username
:
Observable
<
string
|
null
>
;
realname
:
Observable
<
string
|
null
>
;
email
:
Observable
<
string
|
null
>
;
token
:
Observable
<
string
|
null
>
;
isAuthenticated
:
Observable
<
string
>
;
...
...
@@ -43,6 +44,7 @@ export class AppComponent implements OnInit {
this
.
username
=
auth
.
username
();
this
.
realname
=
auth
.
realname
();
this
.
email
=
auth
.
email
();
this
.
token
=
auth
.
token
();
this
.
isAuthenticated
=
(
auth
.
isAuthenticated
()).
pipe
(
...
...
src/app/modules/auth/auth.service.spec.ts
View file @
ed53fa05
...
...
@@ -65,7 +65,7 @@ describe('AuthService (valid token)', () => {
it
(
'
should have username
'
,
()
=>
{
const
username
=
service
.
username
();
username
.
subscribe
(
result
=>
expect
(
result
).
toEqual
(
'
test@ebi.ac.uk
'
));
username
.
subscribe
(
result
=>
expect
(
result
).
toEqual
(
'
usr-75f4b000
'
));
});
it
(
'
should have realname
'
,
()
=>
{
...
...
@@ -73,6 +73,11 @@ describe('AuthService (valid token)', () => {
realname
.
subscribe
(
result
=>
expect
(
result
).
toEqual
(
'
Ed Munden Gras
'
));
});
it
(
'
should have email
'
,
()
=>
{
const
email
=
service
.
email
();
email
.
subscribe
(
result
=>
expect
(
result
).
toEqual
(
'
test@ebi.ac.uk
'
));
});
it
(
'
should have token
'
,
()
=>
{
const
token
=
service
.
token
();
token
.
subscribe
(
result
=>
expect
(
result
).
toEqual
(
VALID_TOKEN
));
...
...
@@ -147,12 +152,17 @@ describe('AuthService (expired token)', () => {
username
.
subscribe
(
result
=>
expect
(
result
).
toBeNull
());
}));
it
(
'
should have realname
'
,
inject
([
AuthService
],
(
service
:
AuthService
)
=>
{
it
(
'
should
not
have realname
'
,
inject
([
AuthService
],
(
service
:
AuthService
)
=>
{
const
realname
=
service
.
realname
();
realname
.
subscribe
(
result
=>
expect
(
result
).
toBeNull
());
}));
it
(
'
should have token
'
,
inject
([
AuthService
],
(
service
:
AuthService
)
=>
{
it
(
'
should not have email
'
,
inject
([
AuthService
],
(
service
:
AuthService
)
=>
{
const
email
=
service
.
email
();
email
.
subscribe
(
result
=>
expect
(
result
).
toBeNull
());
}));
it
(
'
should not have token
'
,
inject
([
AuthService
],
(
service
:
AuthService
)
=>
{
const
token
=
service
.
token
();
token
.
subscribe
(
result
=>
expect
(
result
).
toBeNull
());
}));
...
...
src/app/modules/auth/auth.service.ts
View file @
ed53fa05
...
...
@@ -29,6 +29,7 @@ export interface LoginOptions {
export
interface
Credentials
{
realname
:
string
;
username
:
string
;
email
:
string
;
token
:
string
;
}
...
...
@@ -75,33 +76,43 @@ export class AuthService {
}
public
isAuthenticated
():
Observable
<
boolean
>
{
return
this
.
_c
redentials
.
asObservable
().
pipe
(
map
(
credentials
=>
credentials
?
true
:
false
)
return
this
.
fromC
redentials
(
credentials
=>
credentials
?
true
:
false
);
}
public
credentials
():
Observable
<
Credentials
|
null
>
{
return
this
.
_c
redentials
.
asObservable
(
);
return
this
.
fromC
redentials
(
credentials
=>
credentials
);
}
public
realname
():
Observable
<
string
|
null
>
{
return
this
.
_c
redentials
.
asObservable
().
pipe
(
map
(
credentials
=>
credentials
?
credentials
.
realname
:
null
)
return
this
.
fromC
redentials
(
credentials
=>
credentials
?
credentials
.
realname
:
null
);
}
public
username
():
Observable
<
string
|
null
>
{
return
this
.
_credentials
.
asObservable
().
pipe
(
map
(
credentials
=>
credentials
?
credentials
.
username
:
null
)
return
this
.
fromCredentials
(
credentials
=>
credentials
?
credentials
.
username
:
null
);
}
public
email
():
Observable
<
string
|
null
>
{
return
this
.
fromCredentials
(
credentials
=>
credentials
?
credentials
.
email
:
null
);
}
public
token
():
Observable
<
string
|
null
>
{
return
this
.
_c
redentials
.
asObservable
().
pipe
(
map
(
credentials
=>
credentials
?
credentials
.
token
:
null
)
return
this
.
fromC
redentials
(
credentials
=>
credentials
?
credentials
.
token
:
null
);
}
private
fromCredentials
<
T
>
(
extractor
:
(
_
:
Credentials
)
=>
T
):
Observable
<
T
>
{
return
this
.
_credentials
.
asObservable
().
pipe
(
map
(
extractor
));
}
/**
* Functions that opens a window instead of a tab.
*
...
...
@@ -335,6 +346,7 @@ export class AuthService {
this
.
_credentials
.
next
({
realname
:
<
string
>
this
.
_getRealName
(),
username
:
<
string
>
this
.
_getUserName
(),
email
:
<
string
>
this
.
_getEmail
(),
token
:
<
string
>
this
.
_getToken
()
});
...
...
@@ -365,12 +377,16 @@ export class AuthService {
return
this
.
_tokenService
.
getToken
();
}
private
_getRealName
():
string
|
null
{
return
this
.
_tokenService
.
getClaim
<
string
,
null
>
(
'
name
'
,
null
);
}
private
_getUserName
():
string
|
null
{
return
this
.
_tokenService
.
getClaim
<
string
,
null
>
(
'
email
'
,
null
);
return
this
.
_tokenService
.
getClaim
<
string
,
null
>
(
'
sub
'
,
null
);
}
private
_get
RealName
():
string
|
null
{
return
this
.
_tokenService
.
getClaim
<
string
,
null
>
(
'
name
'
,
null
);
private
_get
Email
():
string
|
null
{
return
this
.
_tokenService
.
getClaim
<
string
,
null
>
(
'
email
'
,
null
);
}
}
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