jwt.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. /*
  3. * This file is part of jwt-auth.
  4. *
  5. * (c) Sean Tymon <tymon148@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. return [
  11. /*
  12. |--------------------------------------------------------------------------
  13. | JWT Authentication Secret
  14. |--------------------------------------------------------------------------
  15. |
  16. | Don't forget to set this in your .env file, as it will be used to sign
  17. | your tokens. A helper command is provided for this:
  18. | `php artisan jwt:secret`
  19. |
  20. | Note: This will be used for Symmetric algorithms only (HMAC),
  21. | since RSA and ECDSA use a private/public key combo (See below).
  22. |
  23. */
  24. 'secret' => env('JWT_SECRET'),
  25. /*
  26. |--------------------------------------------------------------------------
  27. | JWT Authentication Keys
  28. |--------------------------------------------------------------------------
  29. |
  30. | The algorithm you are using, will determine whether your tokens are
  31. | signed with a random string (defined in `JWT_SECRET`) or using the
  32. | following public & private keys.
  33. |
  34. | Symmetric Algorithms:
  35. | HS256, HS384 & HS512 will use `JWT_SECRET`.
  36. |
  37. | Asymmetric Algorithms:
  38. | RS256, RS384 & RS512 / ES256, ES384 & ES512 will use the keys below.
  39. |
  40. */
  41. 'keys' => [
  42. /*
  43. |--------------------------------------------------------------------------
  44. | Public Key
  45. |--------------------------------------------------------------------------
  46. |
  47. | A path or resource to your public key.
  48. |
  49. | E.g. 'file://path/to/public/key'
  50. |
  51. */
  52. 'public' => env('JWT_PUBLIC_KEY'),
  53. /*
  54. |--------------------------------------------------------------------------
  55. | Private Key
  56. |--------------------------------------------------------------------------
  57. |
  58. | A path or resource to your private key.
  59. |
  60. | E.g. 'file://path/to/private/key'
  61. |
  62. */
  63. 'private' => env('JWT_PRIVATE_KEY'),
  64. /*
  65. |--------------------------------------------------------------------------
  66. | Passphrase
  67. |--------------------------------------------------------------------------
  68. |
  69. | The passphrase for your private key. Can be null if none set.
  70. |
  71. */
  72. 'passphrase' => env('JWT_PASSPHRASE'),
  73. ],
  74. /*
  75. |--------------------------------------------------------------------------
  76. | JWT time to live
  77. |--------------------------------------------------------------------------
  78. |
  79. | Specify the length of time (in minutes) that the token will be valid for.
  80. | Defaults to 1 hour.
  81. |
  82. | You can also set this to null, to yield a never expiring token.
  83. | Some people may want this behaviour for e.g. a mobile app.
  84. | This is not particularly recommended, so make sure you have appropriate
  85. | systems in place to revoke the token if necessary.
  86. | Notice: If you set this to null you should remove 'exp' element from 'required_claims' list.
  87. |
  88. */
  89. // .env 中设为和刷新时间 JWT_REFRESH_TTL 一样了
  90. 'ttl' => env('JWT_TTL', 60), //生成的 token 在多少分钟后过期,默认 60 分钟
  91. /*
  92. |--------------------------------------------------------------------------
  93. | Refresh time to live
  94. |--------------------------------------------------------------------------
  95. |
  96. | Specify the length of time (in minutes) that the token can be refreshed
  97. | within. I.E. The user can refresh their token within a 2 week window of
  98. | the original token being created until they must re-authenticate.
  99. | Defaults to 2 weeks.
  100. |
  101. | You can also set this to null, to yield an infinite refresh time.
  102. | Some may want this instead of never expiring tokens for e.g. a mobile app.
  103. | This is not particularly recommended, so make sure you have appropriate
  104. | systems in place to revoke the token if necessary.
  105. |
  106. */
  107. // 只要在这个刷新时间内,即使 token 过期了, 依然可以换取一个新的 token,以达到应用长期可用,不需要重新登录的目的。
  108. 'refresh_ttl' => env('JWT_REFRESH_TTL', 20160), //生成的 token,在多少分钟内,可以刷新获取一个新 token,默认 20160 分钟,14 天。
  109. /*
  110. |--------------------------------------------------------------------------
  111. | JWT hashing algorithm
  112. |--------------------------------------------------------------------------
  113. |
  114. | Specify the hashing algorithm that will be used to sign the token.
  115. |
  116. | See here: https://github.com/namshi/jose/tree/master/src/Namshi/JOSE/Signer/OpenSSL
  117. | for possible values.
  118. |
  119. */
  120. 'algo' => env('JWT_ALGO', 'HS256'),
  121. /*
  122. |--------------------------------------------------------------------------
  123. | Required Claims
  124. |--------------------------------------------------------------------------
  125. |
  126. | Specify the required claims that must exist in any token.
  127. | A TokenInvalidException will be thrown if any of these claims are not
  128. | present in the payload.
  129. |
  130. */
  131. 'required_claims' => [
  132. 'iss',
  133. 'iat',
  134. 'exp',
  135. 'nbf',
  136. 'sub',
  137. 'jti',
  138. ],
  139. /*
  140. |--------------------------------------------------------------------------
  141. | Persistent Claims
  142. |--------------------------------------------------------------------------
  143. |
  144. | Specify the claim keys to be persisted when refreshing a token.
  145. | `sub` and `iat` will automatically be persisted, in
  146. | addition to the these claims.
  147. |
  148. | Note: If a claim does not exist then it will be ignored.
  149. |
  150. */
  151. 'persistent_claims' => [
  152. // 'foo',
  153. // 'bar',
  154. ],
  155. /*
  156. |--------------------------------------------------------------------------
  157. | Lock Subject
  158. |--------------------------------------------------------------------------
  159. |
  160. | This will determine whether a `prv` claim is automatically added to
  161. | the token. The purpose of this is to ensure that if you have multiple
  162. | authentication models e.g. `App\User` & `App\OtherPerson`, then we
  163. | should prevent one authentication request from impersonating another,
  164. | if 2 tokens happen to have the same id across the 2 different models.
  165. |
  166. | Under specific circumstances, you may want to disable this behaviour
  167. | e.g. if you only have one authentication model, then you would save
  168. | a little on token size.
  169. |
  170. */
  171. 'lock_subject' => true,
  172. /*
  173. |--------------------------------------------------------------------------
  174. | Leeway
  175. |--------------------------------------------------------------------------
  176. |
  177. | This property gives the jwt timestamp claims some "leeway".
  178. | Meaning that if you have any unavoidable slight clock skew on
  179. | any of your servers then this will afford you some level of cushioning.
  180. |
  181. | This applies to the claims `iat`, `nbf` and `exp`.
  182. |
  183. | Specify in seconds - only if you know you need it.
  184. |
  185. */
  186. 'leeway' => env('JWT_LEEWAY', 0),
  187. /*
  188. |--------------------------------------------------------------------------
  189. | Blacklist Enabled
  190. |--------------------------------------------------------------------------
  191. |
  192. | In order to invalidate tokens, you must have the blacklist enabled.
  193. | If you do not want or need this functionality, then set this to false.
  194. |
  195. */
  196. 'blacklist_enabled' => env('JWT_BLACKLIST_ENABLED', true),
  197. /*
  198. | -------------------------------------------------------------------------
  199. | Blacklist Grace Period
  200. | -------------------------------------------------------------------------
  201. |
  202. | When multiple concurrent requests are made with the same JWT,
  203. | it is possible that some of them fail, due to token regeneration
  204. | on every request.
  205. |
  206. | Set grace period in seconds to prevent parallel request failure.
  207. |
  208. */
  209. 'blacklist_grace_period' => env('JWT_BLACKLIST_GRACE_PERIOD', 0),
  210. /*
  211. |--------------------------------------------------------------------------
  212. | Cookies encryption
  213. |--------------------------------------------------------------------------
  214. |
  215. | By default Laravel encrypt cookies for security reason.
  216. | If you decide to not decrypt cookies, you will have to configure Laravel
  217. | to not encrypt your cookie token by adding its name into the $except
  218. | array available in the middleware "EncryptCookies" provided by Laravel.
  219. | see https://laravel.com/docs/master/responses#cookies-and-encryption
  220. | for details.
  221. |
  222. | Set it to true if you want to decrypt cookies.
  223. |
  224. */
  225. 'decrypt_cookies' => false,
  226. /*
  227. |--------------------------------------------------------------------------
  228. | Providers
  229. |--------------------------------------------------------------------------
  230. |
  231. | Specify the various providers used throughout the package.
  232. |
  233. */
  234. 'providers' => [
  235. /*
  236. |--------------------------------------------------------------------------
  237. | JWT Provider
  238. |--------------------------------------------------------------------------
  239. |
  240. | Specify the provider that is used to create and decode the tokens.
  241. |
  242. */
  243. 'jwt' => Tymon\JWTAuth\Providers\JWT\Lcobucci::class,
  244. /*
  245. |--------------------------------------------------------------------------
  246. | Authentication Provider
  247. |--------------------------------------------------------------------------
  248. |
  249. | Specify the provider that is used to authenticate users.
  250. |
  251. */
  252. 'auth' => Tymon\JWTAuth\Providers\Auth\Illuminate::class,
  253. /*
  254. |--------------------------------------------------------------------------
  255. | Storage Provider
  256. |--------------------------------------------------------------------------
  257. |
  258. | Specify the provider that is used to store tokens in the blacklist.
  259. |
  260. */
  261. 'storage' => Tymon\JWTAuth\Providers\Storage\Illuminate::class,
  262. ],
  263. ];