diff options
Diffstat (limited to 'contracts/auth.ts')
-rw-r--r-- | contracts/auth.ts | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/contracts/auth.ts b/contracts/auth.ts new file mode 100644 index 0000000..1625116 --- /dev/null +++ b/contracts/auth.ts | |||
@@ -0,0 +1,103 @@ | |||
1 | /** | ||
2 | * Contract source: https://git.io/JOdz5 | ||
3 | * | ||
4 | * Feel free to let us know via PR, if you find something broken in this | ||
5 | * file. | ||
6 | */ | ||
7 | |||
8 | import User from 'App/Models/User'; | ||
9 | import { JWTGuardConfig, JWTGuardContract } from '@ioc:Adonis/Addons/Jwt'; | ||
10 | |||
11 | declare module '@ioc:Adonis/Addons/Auth' { | ||
12 | /* | ||
13 | |-------------------------------------------------------------------------- | ||
14 | | Providers | ||
15 | |-------------------------------------------------------------------------- | ||
16 | | | ||
17 | | The providers are used to fetch users. The Auth module comes pre-bundled | ||
18 | | with two providers that are `Lucid` and `Database`. Both uses database | ||
19 | | to fetch user details. | ||
20 | | | ||
21 | | You can also create and register your own custom providers. | ||
22 | | | ||
23 | */ | ||
24 | interface ProvidersList { | ||
25 | /* | ||
26 | |-------------------------------------------------------------------------- | ||
27 | | User Provider | ||
28 | |-------------------------------------------------------------------------- | ||
29 | | | ||
30 | | The following provider uses Lucid models as a driver for fetching user | ||
31 | | details from the database for authentication. | ||
32 | | | ||
33 | | You can create multiple providers using the same underlying driver with | ||
34 | | different Lucid models. | ||
35 | | | ||
36 | */ | ||
37 | user: { | ||
38 | implementation: LucidProviderContract<typeof User>; | ||
39 | config: LucidProviderConfig<typeof User>; | ||
40 | }; | ||
41 | } | ||
42 | |||
43 | /* | ||
44 | |-------------------------------------------------------------------------- | ||
45 | | Guards | ||
46 | |-------------------------------------------------------------------------- | ||
47 | | | ||
48 | | The guards are used for authenticating users using different drivers. | ||
49 | | The auth module comes with 3 different guards. | ||
50 | | | ||
51 | | - SessionGuardContract | ||
52 | | - BasicAuthGuardContract | ||
53 | | - OATGuardContract ( Opaque access token ) | ||
54 | | | ||
55 | | Every guard needs a provider for looking up users from the database. | ||
56 | | | ||
57 | */ | ||
58 | interface GuardsList { | ||
59 | /* | ||
60 | |-------------------------------------------------------------------------- | ||
61 | | Web Guard | ||
62 | |-------------------------------------------------------------------------- | ||
63 | | | ||
64 | | The web guard uses sessions for maintaining user login state. It uses | ||
65 | | the `user` provider for fetching user details. | ||
66 | | | ||
67 | */ | ||
68 | web: { | ||
69 | implementation: SessionGuardContract<'user', 'web'>; | ||
70 | config: SessionGuardConfig<'user'>; | ||
71 | }; | ||
72 | /* | ||
73 | |-------------------------------------------------------------------------- | ||
74 | | OAT Guard | ||
75 | |-------------------------------------------------------------------------- | ||
76 | | | ||
77 | | OAT, stands for (Opaque access tokens) guard uses database backed tokens | ||
78 | | to authenticate requests. | ||
79 | | | ||
80 | */ | ||
81 | api: { | ||
82 | implementation: OATGuardContract<'user', 'api'>; | ||
83 | config: OATGuardConfig<'user'>; | ||
84 | }; | ||
85 | /* | ||
86 | |-------------------------------------------------------------------------- | ||
87 | | Basic Auth Guard | ||
88 | |-------------------------------------------------------------------------- | ||
89 | | | ||
90 | | The basic guard uses basic auth for maintaining user login state. It uses | ||
91 | | the `user` provider for fetching user details. | ||
92 | | | ||
93 | */ | ||
94 | basic: { | ||
95 | implementation: BasicAuthGuardContract<'user', 'basic'>; | ||
96 | config: BasicAuthGuardConfig<'user'>; | ||
97 | }; | ||
98 | jwt: { | ||
99 | implementation: JWTGuardContract<'user', 'api'>; | ||
100 | config: JWTGuardConfig<'user'>; | ||
101 | }; | ||
102 | } | ||
103 | } | ||