auth.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * Config source: https://git.io/JY0mp
  3. *
  4. * Feel free to let us know via PR, if you find something broken in this config
  5. * file.
  6. */
  7. import type { AuthConfig } from '@ioc:Adonis/Addons/Auth'
  8. /*
  9. |--------------------------------------------------------------------------
  10. | Authentication Mapping
  11. |--------------------------------------------------------------------------
  12. |
  13. | List of available authentication mapping. You must first define them
  14. | inside the `contracts/auth.ts` file before mentioning them here.
  15. |
  16. */
  17. const authConfig: AuthConfig = {
  18. guard: 'api',
  19. guards: {
  20. /*
  21. |--------------------------------------------------------------------------
  22. | Web Guard
  23. |--------------------------------------------------------------------------
  24. |
  25. | Web guard uses classic old school sessions for authenticating users.
  26. | If you are building a standard web application, it is recommended to
  27. | use web guard with session driver
  28. |
  29. */
  30. web: {
  31. driver: 'session',
  32. provider: {
  33. /*
  34. |--------------------------------------------------------------------------
  35. | Driver
  36. |--------------------------------------------------------------------------
  37. |
  38. | Name of the driver
  39. |
  40. */
  41. driver: 'lucid',
  42. /*
  43. |--------------------------------------------------------------------------
  44. | Identifier key
  45. |--------------------------------------------------------------------------
  46. |
  47. | The identifier key is the unique key on the model. In most cases specifying
  48. | the primary key is the right choice.
  49. |
  50. */
  51. identifierKey: 'id',
  52. /*
  53. |--------------------------------------------------------------------------
  54. | Uids
  55. |--------------------------------------------------------------------------
  56. |
  57. | Uids are used to search a user against one of the mentioned columns. During
  58. | login, the auth module will search the user mentioned value against one
  59. | of the mentioned columns to find their user record.
  60. |
  61. */
  62. uids: ['username', 'phone'],
  63. /*
  64. |--------------------------------------------------------------------------
  65. | Model
  66. |--------------------------------------------------------------------------
  67. |
  68. | The model to use for fetching or finding users. The model is imported
  69. | lazily since the config files are read way earlier in the lifecycle
  70. | of booting the app and the models may not be in a usable state at
  71. | that time.
  72. |
  73. */
  74. model: () => import('App/Models/User')
  75. }
  76. },
  77. /*
  78. |--------------------------------------------------------------------------
  79. | OAT Guard
  80. |--------------------------------------------------------------------------
  81. |
  82. | OAT (Opaque access tokens) guard uses database backed tokens to authenticate
  83. | HTTP request. This guard DOES NOT rely on sessions or cookies and uses
  84. | Authorization header value for authentication.
  85. |
  86. | Use this guard to authenticate mobile apps or web clients that cannot rely
  87. | on cookies/sessions.
  88. |
  89. */
  90. api: {
  91. driver: 'oat',
  92. /*
  93. |--------------------------------------------------------------------------
  94. | Tokens provider
  95. |--------------------------------------------------------------------------
  96. |
  97. | Uses SQL database for managing tokens. Use the "database" driver, when
  98. | tokens are the secondary mode of authentication.
  99. | For example: The Github personal tokens
  100. |
  101. | The foreignKey column is used to make the relationship between the user
  102. | and the token. You are free to use any column name here.
  103. |
  104. */
  105. tokenProvider: {
  106. type: 'api',
  107. driver: 'database',
  108. table: 'api_tokens',
  109. foreignKey: 'user_id'
  110. },
  111. provider: {
  112. /*
  113. |--------------------------------------------------------------------------
  114. | Driver
  115. |--------------------------------------------------------------------------
  116. |
  117. | Name of the driver
  118. |
  119. */
  120. driver: 'lucid',
  121. /*
  122. |--------------------------------------------------------------------------
  123. | Identifier key
  124. |--------------------------------------------------------------------------
  125. |
  126. | The identifier key is the unique key on the model. In most cases specifying
  127. | the primary key is the right choice.
  128. |
  129. */
  130. identifierKey: 'id',
  131. /*
  132. |--------------------------------------------------------------------------
  133. | Uids
  134. |--------------------------------------------------------------------------
  135. |
  136. | Uids are used to search a user against one of the mentioned columns. During
  137. | login, the auth module will search the user mentioned value against one
  138. | of the mentioned columns to find their user record.
  139. |
  140. */
  141. uids: ['username', 'phone'],
  142. /*
  143. |--------------------------------------------------------------------------
  144. | Model
  145. |--------------------------------------------------------------------------
  146. |
  147. | The model to use for fetching or finding users. The model is imported
  148. | lazily since the config files are read way earlier in the lifecycle
  149. | of booting the app and the models may not be in a usable state at
  150. | that time.
  151. |
  152. */
  153. model: () => import('App/Models/User')
  154. }
  155. }
  156. }
  157. }
  158. export default authConfig