auth.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. import User from 'App/Models/User'
  8. declare module '@ioc:Adonis/Addons/Auth' {
  9. /*
  10. |--------------------------------------------------------------------------
  11. | Providers
  12. |--------------------------------------------------------------------------
  13. |
  14. | The providers are used to fetch users. The Auth module comes pre-bundled
  15. | with two providers that are `Lucid` and `Database`. Both uses database
  16. | to fetch user details.
  17. |
  18. | You can also create and register your own custom providers.
  19. |
  20. */
  21. interface ProvidersList {
  22. /*
  23. |--------------------------------------------------------------------------
  24. | User Provider
  25. |--------------------------------------------------------------------------
  26. |
  27. | The following provider uses Lucid models as a driver for fetching user
  28. | details from the database for authentication.
  29. |
  30. | You can create multiple providers using the same underlying driver with
  31. | different Lucid models.
  32. |
  33. */
  34. user: {
  35. implementation: LucidProviderContract<typeof User>
  36. config: LucidProviderConfig<typeof User>
  37. }
  38. }
  39. /*
  40. |--------------------------------------------------------------------------
  41. | Guards
  42. |--------------------------------------------------------------------------
  43. |
  44. | The guards are used for authenticating users using different drivers.
  45. | The auth module comes with 3 different guards.
  46. |
  47. | - SessionGuardContract
  48. | - BasicAuthGuardContract
  49. | - OATGuardContract ( Opaque access token )
  50. |
  51. | Every guard needs a provider for looking up users from the database.
  52. |
  53. */
  54. interface GuardsList {
  55. /*
  56. |--------------------------------------------------------------------------
  57. | Web Guard
  58. |--------------------------------------------------------------------------
  59. |
  60. | The web guard uses sessions for maintaining user login state. It uses
  61. | the `user` provider for fetching user details.
  62. |
  63. */
  64. web: {
  65. implementation: SessionGuardContract<'user', 'web'>
  66. config: SessionGuardConfig<'user'>
  67. client: SessionClientContract<'user'>
  68. }
  69. /*
  70. |--------------------------------------------------------------------------
  71. | OAT Guard
  72. |--------------------------------------------------------------------------
  73. |
  74. | OAT, stands for (Opaque access tokens) guard uses database backed tokens
  75. | to authenticate requests.
  76. |
  77. */
  78. api: {
  79. implementation: OATGuardContract<'user', 'api'>
  80. config: OATGuardConfig<'user'>
  81. client: OATClientContract<'user'>
  82. }
  83. }
  84. }