UNPKG

4.13 kBTypeScriptView Raw
1import { HttpClient } from '@angular/common/http';
2import { ActivatedRoute } from '@angular/router';
3import { Observable } from 'rxjs';
4import { NbAuthStrategy } from '../auth-strategy';
5import { NbAuthRefreshableToken, NbAuthToken } from '../../services/token/token';
6import { NbAuthResult } from '../../services/auth-result';
7import { NbOAuth2AuthStrategyOptions } from './oauth2-strategy.options';
8import { NbAuthStrategyClass } from '../../auth.options';
9/**
10 * OAuth2 authentication strategy.
11 *
12 * Strategy settings:
13 *
14 * ```ts
15 * export enum NbOAuth2ResponseType {
16 * CODE = 'code',
17 * TOKEN = 'token',
18 * }
19 *
20 * export enum NbOAuth2GrantType {
21 * AUTHORIZATION_CODE = 'authorization_code',
22 * PASSWORD = 'password',
23 * REFRESH_TOKEN = 'refresh_token',
24 * }
25 *
26 * export class NbOAuth2AuthStrategyOptions {
27 * name: string;
28 * baseEndpoint?: string = '';
29 * clientId: string = '';
30 * clientSecret: string = '';
31 * clientAuthMethod: string = NbOAuth2ClientAuthMethod.NONE;
32 * redirect?: { success?: string; failure?: string } = {
33 * success: '/',
34 * failure: null,
35 * };
36 * defaultErrors?: any[] = ['Something went wrong, please try again.'];
37 * defaultMessages?: any[] = ['You have been successfully authenticated.'];
38 * authorize?: {
39 * endpoint?: string;
40 * redirectUri?: string;
41 * responseType?: string;
42 * requireValidToken: true,
43 * scope?: string;
44 * state?: string;
45 * params?: { [key: string]: string };
46 * } = {
47 * endpoint: 'authorize',
48 * responseType: NbOAuth2ResponseType.CODE,
49 * };
50 * token?: {
51 * endpoint?: string;
52 * grantType?: string;
53 * requireValidToken: true,
54 * redirectUri?: string;
55 * scope?: string;
56 * class: NbAuthTokenClass,
57 * } = {
58 * endpoint: 'token',
59 * grantType: NbOAuth2GrantType.AUTHORIZATION_CODE,
60 * class: NbAuthOAuth2Token,
61 * };
62 * refresh?: {
63 * endpoint?: string;
64 * grantType?: string;
65 * scope?: string;
66 * requireValidToken: true,
67 * } = {
68 * endpoint: 'token',
69 * grantType: NbOAuth2GrantType.REFRESH_TOKEN,
70 * };
71 * }
72 * ```
73 *
74 */
75export declare class NbOAuth2AuthStrategy extends NbAuthStrategy {
76 protected http: HttpClient;
77 protected route: ActivatedRoute;
78 protected window: any;
79 static setup(options: NbOAuth2AuthStrategyOptions): [NbAuthStrategyClass, NbOAuth2AuthStrategyOptions];
80 get responseType(): any;
81 get clientAuthMethod(): any;
82 protected redirectResultHandlers: {
83 [key: string]: Function;
84 };
85 protected redirectResults: {
86 [key: string]: Function;
87 };
88 protected defaultOptions: NbOAuth2AuthStrategyOptions;
89 constructor(http: HttpClient, route: ActivatedRoute, window: any);
90 authenticate(data?: any): Observable<NbAuthResult>;
91 getAuthorizationResult(): Observable<any>;
92 refreshToken(token: NbAuthRefreshableToken): Observable<NbAuthResult>;
93 passwordToken(username: string, password: string): Observable<NbAuthResult>;
94 protected authorizeRedirect(): void;
95 protected isRedirectResult(): Observable<boolean>;
96 protected requestToken(code: string): Observable<NbAuthResult>;
97 protected buildCodeRequestData(code: string): any;
98 protected buildRefreshRequestData(token: NbAuthRefreshableToken): any;
99 protected buildPasswordRequestData(username: string, password: string): string;
100 protected buildAuthHeader(): any;
101 protected cleanParams(params: any): any;
102 protected addCredentialsToParams(params: any): any;
103 protected handleResponseError(res: any): Observable<NbAuthResult>;
104 protected buildRedirectUrl(): string;
105 protected parseHashAsQueryParams(hash: string): {
106 [key: string]: string;
107 };
108 protected urlEncodeParameters(params: any): string;
109 protected createRefreshedToken(res: any, existingToken: NbAuthRefreshableToken, requireValidToken: boolean): NbAuthToken;
110 register(data?: any): Observable<NbAuthResult>;
111 requestPassword(data?: any): Observable<NbAuthResult>;
112 resetPassword(data?: any): Observable<NbAuthResult>;
113 logout(): Observable<NbAuthResult>;
114}