UNPKG

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