UNPKG

3.96 kBTypeScriptView Raw
1import { Observable } from 'rxjs';
2import { NbAuthStrategy } from '../strategies/auth-strategy';
3import { NbAuthResult } from './auth-result';
4import { NbTokenService } from './token/token.service';
5import { NbAuthToken } from './token/token';
6import * as i0 from "@angular/core";
7/**
8 * Common authentication service.
9 * Should be used to as an interlayer between UI Components and Auth Strategy.
10 */
11export declare class NbAuthService {
12 protected tokenService: NbTokenService;
13 protected strategies: any;
14 constructor(tokenService: NbTokenService, strategies: any);
15 /**
16 * Retrieves current authenticated token stored
17 * @returns {Observable<any>}
18 */
19 getToken(): Observable<NbAuthToken>;
20 /**
21 * Returns true if auth token is present in the token storage
22 * @returns {Observable<boolean>}
23 */
24 isAuthenticated(): Observable<boolean>;
25 /**
26 * Returns true if valid auth token is present in the token storage.
27 * If not, calls the strategy refreshToken, and returns isAuthenticated() if success, false otherwise
28 * @returns {Observable<boolean>}
29 */
30 isAuthenticatedOrRefresh(): Observable<boolean>;
31 /**
32 * Returns tokens stream
33 * @returns {Observable<NbAuthSimpleToken>}
34 */
35 onTokenChange(): Observable<NbAuthToken>;
36 /**
37 * Returns authentication status stream
38 * @returns {Observable<boolean>}
39 */
40 onAuthenticationChange(): Observable<boolean>;
41 /**
42 * Authenticates with the selected strategy
43 * Stores received token in the token storage
44 *
45 * Example:
46 * authenticate('email', {email: 'email@example.com', password: 'test'})
47 *
48 * @param strategyName
49 * @param data
50 * @returns {Observable<NbAuthResult>}
51 */
52 authenticate(strategyName: string, data?: any): Observable<NbAuthResult>;
53 /**
54 * Registers with the selected strategy
55 * Stores received token in the token storage
56 *
57 * Example:
58 * register('email', {email: 'email@example.com', name: 'Some Name', password: 'test'})
59 *
60 * @param strategyName
61 * @param data
62 * @returns {Observable<NbAuthResult>}
63 */
64 register(strategyName: string, data?: any): Observable<NbAuthResult>;
65 /**
66 * Sign outs with the selected strategy
67 * Removes token from the token storage
68 *
69 * Example:
70 * logout('email')
71 *
72 * @param strategyName
73 * @returns {Observable<NbAuthResult>}
74 */
75 logout(strategyName: string): Observable<NbAuthResult>;
76 /**
77 * Sends forgot password request to the selected strategy
78 *
79 * Example:
80 * requestPassword('email', {email: 'email@example.com'})
81 *
82 * @param strategyName
83 * @param data
84 * @returns {Observable<NbAuthResult>}
85 */
86 requestPassword(strategyName: string, data?: any): Observable<NbAuthResult>;
87 /**
88 * Tries to reset password with the selected strategy
89 *
90 * Example:
91 * resetPassword('email', {newPassword: 'test'})
92 *
93 * @param strategyName
94 * @param data
95 * @returns {Observable<NbAuthResult>}
96 */
97 resetPassword(strategyName: string, data?: any): Observable<NbAuthResult>;
98 /**
99 * Sends a refresh token request
100 * Stores received token in the token storage
101 *
102 * Example:
103 * refreshToken('email', {token: token})
104 *
105 * @param {string} strategyName
106 * @param data
107 * @returns {Observable<NbAuthResult>}
108 */
109 refreshToken(strategyName: string, data?: any): Observable<NbAuthResult>;
110 /**
111 * Get registered strategy by name
112 *
113 * Example:
114 * getStrategy('email')
115 *
116 * @param {string} provider
117 * @returns {NbAbstractAuthProvider}
118 */
119 protected getStrategy(strategyName: string): NbAuthStrategy;
120 private processResultToken;
121 static ɵfac: i0.ɵɵFactoryDeclaration<NbAuthService, never>;
122 static ɵprov: i0.ɵɵInjectableDeclaration<NbAuthService>;
123}