1 | import type { HttpContext } from '@adonisjs/core/http';
|
2 | import type { GuardFactory } from './types.js';
|
3 | /**
|
4 | * Authenticator is used to authenticate incoming HTTP requests
|
5 | * using one or more known guards.
|
6 | */
|
7 | export declare class Authenticator<KnownGuards extends Record<string, GuardFactory>> {
|
8 | #private;
|
9 | /**
|
10 | * Name of the default guard
|
11 | */
|
12 | get defaultGuard(): keyof KnownGuards;
|
13 | /**
|
14 | * Reference to the guard using which the current
|
15 | * request has been authenticated.
|
16 | */
|
17 | get authenticatedViaGuard(): keyof KnownGuards | undefined;
|
18 | /**
|
19 | * A boolean to know if the current request has been authenticated. The
|
20 | * property returns false when "authenticate" or "authenticateUsing"
|
21 | * methods are not used.
|
22 | */
|
23 | get isAuthenticated(): boolean;
|
24 | /**
|
25 | * Reference to the currently authenticated user. The property returns
|
26 | * undefined when "authenticate" or "authenticateUsing" methods are
|
27 | * not used.
|
28 | */
|
29 | get user(): {
|
30 | [K in keyof KnownGuards]: ReturnType<KnownGuards[K]>['user'];
|
31 | }[keyof KnownGuards];
|
32 | /**
|
33 | * Whether or not the authentication has been attempted during
|
34 | * the current request. The property returns false when the
|
35 | * "authenticate" or "authenticateUsing" methods are not
|
36 | * used.
|
37 | */
|
38 | get authenticationAttempted(): boolean;
|
39 | constructor(ctx: HttpContext, config: {
|
40 | default: keyof KnownGuards;
|
41 | guards: KnownGuards;
|
42 | });
|
43 | /**
|
44 | * Returns an instance of the logged-in user or throws an
|
45 | * exception
|
46 | */
|
47 | getUserOrFail(): {
|
48 | [K in keyof KnownGuards]: ReturnType<ReturnType<KnownGuards[K]>['getUserOrFail']>;
|
49 | }[keyof KnownGuards];
|
50 | /**
|
51 | * Returns an instance of a known guard. Guards instances are
|
52 | * cached during the lifecycle of an HTTP request.
|
53 | */
|
54 | use<Guard extends keyof KnownGuards>(guard?: Guard): ReturnType<KnownGuards[Guard]>;
|
55 | /**
|
56 | * Authenticate current request using the default guard. Calling this
|
57 | * method multiple times triggers multiple authentication with the
|
58 | * guard.
|
59 | */
|
60 | authenticate(): Promise<{ [K in keyof KnownGuards]: ReturnType<ReturnType<KnownGuards[K]>["getUserOrFail"]>; }[keyof KnownGuards]>;
|
61 | /**
|
62 | * Silently attempt to authenticate the request using the default
|
63 | * guard. Calling this method multiple times triggers multiple
|
64 | * authentication with the guard.
|
65 | */
|
66 | check(): Promise<boolean>;
|
67 | /**
|
68 | * Authenticate the request using all of the mentioned guards
|
69 | * or the default guard.
|
70 | *
|
71 | * The authentication process will stop after any of the mentioned
|
72 | * guards is able to authenticate the request successfully.
|
73 | *
|
74 | * Otherwise, "E_UNAUTHORIZED_ACCESS" will be raised.
|
75 | */
|
76 | authenticateUsing(guards?: (keyof KnownGuards)[], options?: {
|
77 | loginRoute?: string;
|
78 | }): Promise<{
|
79 | [K in keyof KnownGuards]: ReturnType<ReturnType<KnownGuards[K]>['getUserOrFail']>;
|
80 | }[keyof KnownGuards]>;
|
81 | }
|