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