UNPKG

3.36 kBTypeScriptView Raw
1import { Http, Request, RequestOptions, RequestOptionsArgs, Response } from "@angular/http";
2import { Provider, ModuleWithProviders } from "@angular/core";
3import { Observable } from "rxjs/Observable";
4import "rxjs/add/observable/fromPromise";
5import "rxjs/add/observable/defer";
6import "rxjs/add/operator/mergeMap";
7export interface IAuthConfig {
8 globalHeaders: Array<Object>;
9 headerName: string;
10 headerPrefix: string;
11 noJwtError: boolean;
12 noClientCheck: boolean;
13 noTokenScheme?: boolean;
14 tokenGetter: () => string | Promise<string>;
15 tokenName: string;
16}
17export interface IAuthConfigOptional {
18 headerName?: string;
19 headerPrefix?: string;
20 tokenName?: string;
21 tokenGetter?: () => string | Promise<string>;
22 noJwtError?: boolean;
23 noClientCheck?: boolean;
24 globalHeaders?: Array<Object>;
25 noTokenScheme?: boolean;
26}
27export declare class AuthConfigConsts {
28 static DEFAULT_TOKEN_NAME: string;
29 static DEFAULT_HEADER_NAME: string;
30 static HEADER_PREFIX_BEARER: string;
31}
32/**
33 * Sets up the authentication configuration.
34 */
35export declare class AuthConfig {
36 private _config;
37 constructor(config?: IAuthConfigOptional);
38 getConfig(): IAuthConfig;
39}
40export declare class AuthHttpError extends Error {
41}
42/**
43 * Allows for explicit authenticated HTTP requests.
44 */
45export declare class AuthHttp {
46 private http;
47 private defOpts;
48 private config;
49 tokenStream: Observable<string>;
50 constructor(options: AuthConfig, http: Http, defOpts?: RequestOptions);
51 private mergeOptions(providedOpts, defaultOpts?);
52 private requestHelper(requestArgs, additionalOptions?);
53 requestWithToken(req: Request, token: string): Observable<Response>;
54 setGlobalHeaders(headers: Array<Object>, request: Request | RequestOptionsArgs): void;
55 request(url: string | Request, options?: RequestOptionsArgs): Observable<Response>;
56 get(url: string, options?: RequestOptionsArgs): Observable<Response>;
57 post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;
58 put(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;
59 delete(url: string, options?: RequestOptionsArgs): Observable<Response>;
60 patch(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;
61 head(url: string, options?: RequestOptionsArgs): Observable<Response>;
62 options(url: string, options?: RequestOptionsArgs): Observable<Response>;
63}
64/**
65 * Helper class to decode and find JWT expiration.
66 */
67export declare class JwtHelper {
68 urlBase64Decode(str: string): string;
69 private b64decode(str);
70 private b64DecodeUnicode(str);
71 decodeToken(token: string): any;
72 getTokenExpirationDate(token: string): Date;
73 isTokenExpired(token: string, offsetSeconds?: number): boolean;
74}
75/**
76 * Checks for presence of token and that token hasn't expired.
77 * For use with the @CanActivate router decorator and NgIf
78 */
79export declare function tokenNotExpired(tokenName?: string, jwt?: string): boolean;
80export declare const AUTH_PROVIDERS: Provider[];
81export declare function provideAuth(config?: IAuthConfigOptional): Provider[];
82/**
83 * Module for angular2-jwt
84 * @experimental
85 */
86export declare class AuthModule {
87 constructor(parentModule: AuthModule);
88 static forRoot(config: AuthConfig): ModuleWithProviders;
89}