-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthentication.service.ts
53 lines (47 loc) · 1.3 KB
/
authentication.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { CredentialsService } from '@app/auth';
import { Credentials } from '@core/entities';
export interface LoginContext {
username: string;
password: string;
remember?: boolean;
isMobile?: boolean;
}
/**
* Provides a base for authentication workflow.
* The login/logout methods should be replaced with proper implementation.
*/
@Injectable({
providedIn: 'root',
})
export class AuthenticationService {
constructor(private readonly _credentialsService: CredentialsService) {}
/**
* Authenticates the user.
* @param context The login parameters.
* @return The user credentials.
*/
login(context: LoginContext): Observable<Credentials> {
const credentials: Credentials = new Credentials({
username: 'johndoe',
id: '',
token: '123456',
refreshToken: '123456',
expiresIn: 3600,
roles: ['user', 'admin'],
email: '[email protected]',
firstName: 'John',
lastName: 'Doe',
});
this._credentialsService.setCredentials(credentials, context.remember);
return of(credentials);
}
/**
* Logs out the user and clear credentials.
* @return True if the user was logged out successfully.
*/
logout(): Observable<any> {
return of(true);
}
}