{"id":957,"date":"2023-08-03T17:30:18","date_gmt":"2023-08-03T17:30:18","guid":{"rendered":"http:\/\/robinluo.top\/?p=957"},"modified":"2024-01-08T17:55:48","modified_gmt":"2024-01-08T17:55:48","slug":"laravel-jwt","status":"publish","type":"post","link":"https:\/\/robinluo.top\/?p=957","title":{"rendered":"laravel  jwt"},"content":{"rendered":"\n<p>\u4e3aapi \u8c03\u7528\u63d0\u4f9b\u8eab\u4efd\u6821\u9a8c\u529f\u80fd<\/p>\n\n\n\n<p>docs     <a href=\"https:\/\/jwt-auth.readthedocs.io\/\">https:\/\/jwt-auth.readthedocs.io\/<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>install   <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>composer require tymon\/jwt-auth<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Add the service provider to the&nbsp;<code>providers<\/code>&nbsp;array in the&nbsp;<code>config\/app.php<\/code>&nbsp;config file as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>'providers' => &#91;\n\n    ...\n\n    Tymon\\JWTAuth\\Providers\\LaravelServiceProvider::class,\n]<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Run the following command to publish the package config file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan vendor:publish --provider=\"Tymon\\JWTAuth\\Providers\\LaravelServiceProvider\"\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Generate secret key<\/p>\n\n\n\n<p>This will update your&nbsp;<code>.env<\/code>&nbsp;file with something like&nbsp;<code>JWT_SECRET=XXX<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan jwt:secret\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>\u8be5\u5305 \u4fee\u6539laravel api \u8def\u5f84\u4e0b\u9ed8\u8ba4\u7684 token\u6821\u9a8c\u65b9\u5f0f \u628atoken\u6539\u4e3aJWT token  <\/p>\n\n\n\n<p>\u5176\u5b9e\u751f\u6210\u6d41\u7a0b\u548c\u6821\u9a8c\u6d41\u7a0b\u548c\u4e4b\u524d\u6ca1\u53d8\u5316<\/p>\n\n\n\n<p>login \u901a\u8fc7\u7528\u6237\u8d26\u53f7\u5bc6\u7801 \u4f5c\u4e3a credentials  \u7136\u540e\u53bb\u6570\u636e\u5e93\u83b7\u53d6\u7528\u6237\u4fe1\u606f \u8be5\u7528\u6237\u4fe1\u606f\u4f1a\u751f\u6210JWT token \u653e\u5728laravel \u9ed8\u8ba4\u7f13\u5b58\u7ba1\u7406\u5668<\/p>\n\n\n\n<p>\u540e\u7eed\u8bf7\u6c42 \u5728\u8bf7\u6c42\u5934\u5e26\u4e0a Authorazation : bear $token<\/p>\n\n\n\n<p>\u901a\u8fc7auth:api \u4e2d\u95f4\u4ef6\u6821\u9a8c<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3aapi \u8c03\u7528\u63d0\u4f9b\u8eab\u4efd\u6821\u9a8c\u529f\u80fd docs https:\/\/jwt-auth.readthedocs.io\/ install Add the service provider to the&nbsp;providers&nbsp;array in the&nbsp;config\/app.php&nbsp;config file as follows: Run the following command to publish the package config file: Generate secret key This will update your&nbsp;.env&nbsp;file with something like&nbsp;JWT_SECRET=XXX \u8be5\u5305 \u4fee\u6539laravel api \u8def\u5f84\u4e0b\u9ed8\u8ba4\u7684 token\u6821\u9a8c\u65b9\u5f0f \u628atoken\u6539\u4e3aJWT token \u5176\u5b9e\u751f\u6210\u6d41\u7a0b\u548c\u6821\u9a8c\u6d41\u7a0b\u548c\u4e4b\u524d\u6ca1\u53d8\u5316 login \u901a\u8fc7\u7528\u6237\u8d26\u53f7\u5bc6\u7801 \u4f5c\u4e3a credentials \u7136\u540e\u53bb\u6570\u636e\u5e93\u83b7\u53d6\u7528\u6237\u4fe1\u606f \u8be5\u7528\u6237\u4fe1\u606f\u4f1a\u751f\u6210JWT token \u653e\u5728laravel \u9ed8\u8ba4\u7f13\u5b58\u7ba1\u7406\u5668 \u540e\u7eed\u8bf7\u6c42 \u5728\u8bf7\u6c42\u5934\u5e26\u4e0a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/957"}],"collection":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=957"}],"version-history":[{"count":2,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/957\/revisions"}],"predecessor-version":[{"id":1012,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/957\/revisions\/1012"}],"wp:attachment":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}