1 |
|
2 | import { SignOptions, Secret, VerifyOptions } from 'jsonwebtoken';
|
3 | import { Application, Params } from '@feathersjs/feathers';
|
4 | import { IncomingMessage, ServerResponse } from 'http';
|
5 | export interface AuthenticationResult {
|
6 | [key: string]: any;
|
7 | }
|
8 | export interface AuthenticationRequest {
|
9 | strategy?: string;
|
10 | [key: string]: any;
|
11 | }
|
12 | export declare type ConnectionEvent = 'login' | 'logout' | 'disconnect';
|
13 | export interface AuthenticationStrategy {
|
14 | |
15 |
|
16 |
|
17 |
|
18 | setAuthentication?(auth: AuthenticationBase): void;
|
19 | |
20 |
|
21 |
|
22 |
|
23 | setApplication?(app: Application): void;
|
24 | |
25 |
|
26 |
|
27 |
|
28 | setName?(name: string): void;
|
29 | |
30 |
|
31 |
|
32 |
|
33 | verifyConfiguration?(): void;
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | authenticate?(authentication: AuthenticationRequest, params: Params): Promise<AuthenticationResult>;
|
41 | |
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | handleConnection?(event: ConnectionEvent, connection: any, authResult?: AuthenticationResult): Promise<void>;
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 | parse?(req: IncomingMessage, res: ServerResponse): Promise<AuthenticationRequest | null>;
|
54 | }
|
55 | export interface JwtVerifyOptions extends VerifyOptions {
|
56 | algorithm?: string | string[];
|
57 | }
|
58 |
|
59 |
|
60 |
|
61 | export declare class AuthenticationBase {
|
62 | app: Application;
|
63 | configKey: string;
|
64 | strategies: {
|
65 | [key: string]: AuthenticationStrategy;
|
66 | };
|
67 | |
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | constructor(app: Application, configKey?: string, options?: {});
|
74 | /**
|
75 | * Return the current configuration from the application
|
76 | */
|
77 | get configuration(): any;
|
78 | /**
|
79 | * A list of all registered strategy names
|
80 | */
|
81 | get strategyNames(): string[];
|
82 | /**
|
83 | * Register a new authentication strategy under a given name.
|
84 | * @param name The name to register the strategy under
|
85 | * @param strategy The authentication strategy instance
|
86 | */
|
87 | register(name: string, strategy: AuthenticationStrategy): void;
|
88 | /**
|
89 | * Get the registered authentication strategies for a list of names.
|
90 | * @param names The list or strategy names
|
91 | */
|
92 | getStrategies(...names: string[]): AuthenticationStrategy[];
|
93 | /**
|
94 | * Create a new access token with payload and options.
|
95 | * @param payload The JWT payload
|
96 | * @param optsOverride The options to extend the defaults (`configuration.jwtOptions`) with
|
97 | * @param secretOverride Use a different secret instead
|
98 | */
|
99 | createAccessToken(payload: string | Buffer | object, optsOverride?: SignOptions, secretOverride?: Secret): Promise<string>;
|
100 | /**
|
101 | * Verifies an access token.
|
102 | * @param accessToken The token to verify
|
103 | * @param optsOverride The options to extend the defaults (`configuration.jwtOptions`) with
|
104 | * @param secretOverride Use a different secret instead
|
105 | */
|
106 | verifyAccessToken(accessToken: string, optsOverride?: JwtVerifyOptions, secretOverride?: Secret): Promise<any>;
|
107 | /**
|
108 | * Authenticate a given authentication request against a list of strategies.
|
109 | * @param authentication The authentication request
|
110 | * @param params Service call parameters
|
111 | * @param allowed A list of allowed strategy names
|
112 | */
|
113 | authenticate(authentication: AuthenticationRequest, params: Params, ...allowed: string[]): Promise<AuthenticationResult>;
|
114 | handleConnection(event: ConnectionEvent, connection: any, authResult?: AuthenticationResult): Promise<void>;
|
115 | /**
|
116 | * Parse an HTTP request and response for authentication request information.
|
117 | * @param req The HTTP request
|
118 | * @param res The HTTP response
|
119 | * @param names A list of strategies to use
|
120 | */
|
121 | parse(req: IncomingMessage, res: ServerResponse, ...names: string[]): Promise<AuthenticationRequest>;
|
122 | }
|