{"id":2349,"date":"2021-10-02T06:03:25","date_gmt":"2021-10-01T22:03:25","guid":{"rendered":"https:\/\/www.develop-note.com\/blog\/?p=2349"},"modified":"2022-02-16T17:33:08","modified_gmt":"2022-02-16T09:33:08","slug":"jwt-authentication-authorization","status":"publish","type":"post","link":"https:\/\/www.develop-note.com\/blog\/2021\/10\/02\/jwt-authentication-authorization\/","title":{"rendered":"D-13-\u6388\u6b0a jwt ? authentication ? authorization"},"content":{"rendered":"<h1>\u7121\u72c0\u614b\u7684HttpRequest\u600e\u9ebc\u505a\u8eab\u5206\u9a57\u8b49<\/h1>\n<p>\u76f4\u5230\u6628\u5929\u5c07\u7db2\u9801\u7684\u57fa\u790e\u77e5\u8b58\u4ecb\u7d39\u5b8c\u4e86\uff0c\u6240\u4ee5\u4eca\u5929\u958b\u59cb\u6703\u4ecb\u7d39\u4e00\u4e9b\u958b\u767c\u4e0a\u6703\u5e38\u6703\u9047\u5230\u7684\u9700\u6c42\u4ee5\u53ca\u5982\u4f55\u89e3\u6c7a\u9019\u500b\u9700\u6c42\u7684\u5957\u4ef6\uff0c\u6240\u4ee5\u5404\u4f4d\u8acb\u7e7c\u7e8c\u770b\u4e0b\u53bb\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u7db2\u9801\u4f3a\u670d\u5668\u5982\u4f55\u8eab\u5206\u9a57\u8b49<\/h2>\n<p>\u300c\u524d\u8f29\uff0c\u6211\u5011\u516c\u53f8\u7684\u7db2\u7ad9\u8981\u52a0\u4e0a\u8eab\u5206\u9a57\u8b49\u7684\u529f\u80fd\uff0c\u9019\u8a72\u600e\u9ebc\u505a\u5462\u3002\u300d<br \/>\n\u4e00\u5927\u65e9\u5c0f\u5149\u5c31\u807d\u5230\u5927\u982d\u8ddf\u8001K\u8a62\u554f\u9700\u6c42\u958b\u767c\u7684\u554f\u984c\uff0c\u9019\u6642\u4ed6\u5c31\u6e4a\u904e\u53bb\u60f3\u8981\u4e86\u89e3\u4e00\u4e0b\u4ed6\u5011\u9047\u5230\u7684\u554f\u984c\u4ee5\u53ca\u89e3\u6c7a\u7684\u65b9\u6cd5\u3002<br \/>\n\u300c\u6069\uff0c\u4e0d\u5916\u4e4e\u5c31\u662f\u4f7f\u7528\u8005\u8f38\u5165\u5e33\u5bc6\u5f8c\u767b\u5165\uff0c\u5728\u767b\u5165\u6642\u5b58\u653e\u767b\u5165\u7684\u8cc7\u6599\uff0c\u4e4b\u5f8c\u518d\u8acb\u6c42\u662f\u6aa2\u67e5\u662f\u5426\u6709\u767b\u5165\u4e86\u3002\u300d<br \/>\n\u300c\u597d\u5594\u3002\u300d<br \/>\n\u807d\u5230\u8001K\u8aaa\u7684\u5efa\u8b70\u5f8c\u5927\u982d\u8f49\u8eab\u4e26\u4e14\u958b\u59cb\u6372\u8d77\u8896\u5b50\u6e96\u5099\u5927\u986f\u8eab\u624b\uff0c\u9019\u6642\u8001K\u770b\u5230\u4ed6\u7684\u6a23\u5b50\u8d95\u7dca\u963b\u6b62\u4ed6\u3002<br \/>\n\u300c\u7b49\u7b49&#8230;\u4f60\u4e0d\u6703\u8981\u6e96\u5099\u81ea\u5df1\u641e\u4e00\u5957\u5427\u3002\u300d<br \/>\n\u9019\u6642\u5927\u982d\u807d\u5230\u8001K\u7684\u8a71\u4e4b\u5f8c\uff0c\u7528\u7591\u60d1\u7684\u773c\u795e\u770b\u8457\u4ed6\u3002<br \/>\n\u300c\u4f86\u4f86\u4f86\uff0c\u6211\u544a\u8a34\u4f60\u9019\u6771\u897f\u5df2\u7d93\u6709\u4eba\u505a\u4e86\uff0c\u5225\u518d\u81ea\u5df1\u641e\u4e00\u5957\u4e86\u3002\u300d<br \/>\n\u9019\u6642\u8001K\u5c31\u8ddf\u5927\u982d\u9084\u6709\u5c0f\u5149\u4ecb\u7d39\u5982\u4f55\u8655\u7406\u8eab\u5206\u9a57\u8b49\u7684\u9700\u6c42\u3002<\/p>\n<h3>\u9a57\u8b49\u8207\u6388\u6b0a<\/h3>\n<p>\u57fa\u65bc<a href=\"https:\/\/zh.wikipedia.org\/wiki\/%E5%85%B3%E6%B3%A8%E7%82%B9%E5%88%86%E7%A6%BB\" title=\"\u95dc\u6ce8\u9ede\u5206\u96e2\" rel=\"nofollow noopener\" target=\"_blank\">\u95dc\u6ce8\u9ede\u5206\u96e2<\/a>\u7684\u6982\u5ff5\u5728\u958b\u767c\u7db2\u9801\u7a0b\u5f0f\u7684\u6642\u5019\u8981\u5c08\u6ce8\u5730\u662f\u5728\u5546\u696d\u908f\u8f2f\u7684\u958b\u767c\u4e0a\u9762\uff0c\u56e0\u6b64\u5c0d\u65bc<a href=\"https:\/\/docs.microsoft.com\/zh-tw\/aspnet\/core\/security\/authentication\" title=\"\u9a57\u8b49\" rel=\"nofollow noopener\" target=\"_blank\">\u9a57\u8b49<\/a>\u8207<a href=\"https:\/\/docs.microsoft.com\/zh-tw\/aspnet\/core\/security\/authorization\/introduction\" title=\"\u6388\u6b0a\" rel=\"nofollow noopener\" target=\"_blank\">\u6388\u6b0a<\/a>\u9019\u7a2e\u9700\u6c42\u5982\u679c\u53ef\u4ee5\u8ddf\u5546\u696d\u908f\u8f2f\u5207\u5206\u51fa\u4f86\u958b\u767c\uff0c\u6240\u4ee5\u91dd\u5c0ddotnetcore\u5c0d\u65bc\u589e\u52a0\u4f7f\u7528\u8005\u7684\u6703\u628a\u4ed6\u79fb\u81f3\u4e2d\u4ecb\u8edf\u9ad4\u4f86\u8655\u7406\u5c31\u5982\u540c<a href=\"https:\/\/www.c-sharpcorner.com\/article\/authentication-and-authorization-in-asp-net-core-web-api-with-json-web-tokens\/\" title=\"\u9a57\u8b49\u8207\u6388\u6b0a\" rel=\"nofollow noopener\" target=\"_blank\">\u9a57\u8b49\u8207\u6388\u6b0a<\/a>\u6240\u793a\uff0c\u63a5\u4e0b\u4f86\u7d30\u7bc0\u90e8\u5206\u53ef\u4ee5\u770b\u4e00\u4e0b\u4e0b\u5217\u7bc4\u4f8b\u3002<\/p>\n<p>\u9996\u5148\u5728Startup.Configure\u52a0\u5165\u4ee5\u4e0b\u5167\u5bb9\u3002<\/p>\n<pre><code class=\"language-cs\">.\napp.UseAuthentication();  \napp.UseAuthorization();  \n.<\/code><\/pre>\n<p>\u76f8\u4fe1\u5927\u5bb6\u5728\u4e2d\u4ecb\u8edf\u9ad4\u90a3\u90e8\u5206\u6709\u770b\u904e\u9019\u5169\u500b\u6771\u897f\uff0c\u9019\u90e8\u5206\u662fdotnetcore\u5167\u5efa\u7684\u4e2d\u4ecb\u8edf\u9ad4\uff0c\u7136\u5f8c\u9019\u90e8\u5206\u8981\u5c0f\u5fc3\u4e2d\u4ecb\u5c64\u8edf\u9ad4\u7684\u524d\u5f8c\u9806\u5e8f\uff0c\u6240\u4ee5\u63a5\u4e0b\u4f86\u91dd\u5c0d\u8981\u9a57\u8b49\u7684Action\u53ef\u4ee5\u52a0\u4e0aAttribute\u4e0a\u53bb\u5982\u4e0b\u5217\u7bc4\u4f8b\u3002<\/p>\n<pre><code class=\"language-cs\">[Authorize]\n[ApiController]\n[Route(&quot;[controller]&quot;)]\npublic class WeatherForecastController : ControllerBase\n{\n    .\n}<\/code><\/pre>\n<p>\u5982\u679c\u8981\u91dd\u5c0d\u7279\u5b9aAction\u9a57\u8b49\u7279\u5b9aAction\u53ef\u4ee5\u628a<code>[Authorize]<\/code>\u639b\u5728Action\u4e0a\uff0c\u5982\u679c\u9700\u8981\u7279\u5b9a\u6b0a\u9650\u624d\u53ef\u4ee5\u4f7f\u7528\u8a72Action\u5247\u5c07\u8a72Attribute\u8f38\u5165\u53c3\u6578\u5373\u53ef\uff0c\u5c31\u5982\u540c<code>[Authorize(Roles = &quot;Admin&quot;)]<\/code>\u3002\u63a5\u4e0b\u4f86\u518d\u4ecb\u7d39\u5982\u4f55\u5728dotnetcore\u4f7f\u7528jwt Token\u7684\u65b9\u5f0f\u4f86\u9032\u884c\u6388\u6b0a\u8ddf\u8a8d\u8b49\u3002<\/p>\n<h3>jwt<\/h3>\n<p>\u5982\u679c\u4ed4\u7d30\u770b\u4e0a\u8ff0\u7684<a href=\"https:\/\/www.c-sharpcorner.com\/article\/authentication-and-authorization-in-asp-net-core-web-api-with-json-web-tokens\/\" title=\"\u9a57\u8b49\u8207\u6388\u6b0a\" rel=\"nofollow noopener\" target=\"_blank\">\u9a57\u8b49\u8207\u6388\u6b0a<\/a>\u4e4b\u5f8c\u61c9\u8a72\u5df2\u7d93\u77e5\u9053\u8a72\u5982\u4f55\u5728dotnetcore\u5167\u4f7f\u7528jwt Token\u7684\u65b9\u5f0f\u4f86\u9032\u884c\u6388\u6b0a\u8ddf\u8a8d\u8b49\uff0c\u5982\u679c\u5c0d\u65bc\u770b\u82f1\u6587\u5167\u5bb9\u7684\u6587\u7ae0\u6709\u56f0\u64fe\u7684\u8a71\u53ef\u4ee5\u518d\u53c3\u8003\u4fdd\u54e5\u7684<a href=\"https:\/\/blog.miniasp.com\/post\/2019\/12\/16\/How-to-use-JWT-token-based-auth-in-aspnet-core-31\" title=\"\u4fdd\u54e5 - \u5982\u4f55\u5728 ASP.NET Core 3 \u4f7f\u7528 Token-based \u8eab\u5206\u9a57\u8b49\u8207\u6388\u6b0a (JWT)\" rel=\"nofollow noopener\" target=\"_blank\">\u5982\u4f55\u5728 ASP.NET Core 3 \u4f7f\u7528 Token-based \u8eab\u5206\u9a57\u8b49\u8207\u6388\u6b0a (JWT)<\/a>\u9019\u7bc7\u6587\u7ae0\uff0c\u800c\u672c\u7bc7\u5c31\u91dd\u5c0d\u91cd\u9ede\u5f0f\u7684\u4ecb\u7d39\u3002<\/p>\n<h4>\u4ec0\u9ebc\u662fjwt<\/h4>\n<table>\n<thead>\n<tr>\n<th>\u5728\u8aaa\u660e\u600e\u9ebc\u8655\u7406\u4e4b\u524d\u8981\u5148\u4e86\u89e3\u4e00\u4e0b\u4ec0\u9ebc\u662f<a href=\"https:\/\/jwt.io\/introduction\" title=\"jwt\" rel=\"nofollow noopener\" target=\"_blank\">jwt<\/a>\uff0c\u4ed6\u7684\u5168\u540d\u662f<a href=\"https:\/\/en.wikipedia.org\/wiki\/JSON_Web_Token\" title=\"JSON Web Token\" rel=\"nofollow noopener\" target=\"_blank\">JSON Web Token<\/a>\uff0c\u7c21\u55ae\u8aaa\u660e\u5c31\u662f\u4ed6\u5c07Token\u5206\u6210\u4e09\u90e8\u5206\u3002<\/th>\n<th><\/th>\n<th><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Header<\/td>\n<td>\u8868\u982d\uff0c\u8aaa\u660e\u6b64Token\u7684\u985e\u5225\u4ee5\u53ca\u52a0\u5bc6\u65b9\u5f0f\u3002<\/td>\n<\/tr>\n<tr>\n<td>Payload<\/td>\n<td>\u4f7f\u7528\u8005\u8cc7\u6599\uff0c\u4f46\u4e0d\u5efa\u8b70\u653e\u6a5f\u5bc6\u5167\u5bb9\u3002\u9664\u6b64\u4e4b\u5916\u9084\u6709\u903e\u671f\u6642\u9593    \b<\/td>\n<\/tr>\n<tr>\n<td>Signature<\/td>\n<td>\u7c3d\u7ae0\u5167\u5bb9\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e4b\u5f8c\u6709\u6c92\u6709\u7d93\u904e\u6388\u6b0a\u5c31\u662f\u9019\u500bToken\u7684\u5167\u5bb9\uff0c\u56e0\u70ba\u525b\u6709\u63d0\u5230\u903e\u671f\u6642\u9593\uff0c\u6240\u4ee5\u7576\u6642\u9593\u8d85\u904e\u662f\u9019\u500bToken\u5c31\u6703\u5931\u6548\u8981\u53e6\u5916\u5728\u53d6\u5f97\u4e00\u500bToken\u3002\u63a5\u4e0b\u4f86\u7576\u6536\u5230\u6b64Token\u6642\u53ef\u4ee5\u4e0d\u7528\u518d\u8ddf\u8cc7\u6599\u5eab\u67e5\u8a62\u5c31\u6709\u4e9b\u8cc7\u6599\u4ee5\u5b58\u653e\u5728Token\u4e2d\uff0c\u6240\u4ee5\u53ef\u4ee5\u6e1b\u5c11\u5c0d\u8cc7\u6599\u5eab\u7684\u5b58\u53d6\u3002\u4ee5\u4e0a\u5c31\u662fjwt\u7684\u5167\u5bb9\u3002\u6240\u4ee5\u63a5\u4e0b\u4f86\u8aaa\u660e\u600e\u9ebc\u5728dotnetcore\u5167\u4f7f\u7528jwt\u3002<\/p>\n<h4>\u4f7f\u7528 jwt<\/h4>\n<p>\u9019\u90e8\u5206\u8aaa\u660e\u5982\u4f55\u5728dotnetcore\u5167\u4f7f\u7528jwt\uff0c\u9019\u90e8\u5206\u53ef\u4ee5\u5206\u6210\u5169\u6b65\u9a5f\uff0c\u7531\u65bc\u8a8d\u8b49\u90e8\u5206\u5df2\u7d93\u662f\u900f\u904eAttribute\u7684\u90e8\u5206\u4f86\u8655\u7406\u4e86\uff0c\u6240\u4ee5\u63a5\u4e0b\u4f86\u91dd\u5c0d\u8a2d\u5b9aToken\u7522\u751f\u7684\u65b9\u5f0f\u4ee5\u53ca\u5982\u4f55\u767b\u5165\u6838\u767cToken\u5169\u90e8\u4efd\u4f86\u8aaa\u660e\u3002<\/p>\n<p>\u4e0d\u904e\u5728\u8aaa\u660e\u4e4b\u524d\u8acb\u5148\u5b89\u88dd\u5957\u4ef6\uff0c\u56e0\u70ba\u5f8c\u7e8c\u5f88\u591a\u8a9e\u6cd5\u90fd\u662f\u900f\u904e\u5957\u4ef6\u4f86\u64cd\u4f5c\u3002\u6240\u4ee5\u5728\u547d\u5217\u5148\u8f38\u5165\u4ee5\u4e0b\u6307\u4ee4\u3002<\/p>\n<pre><code class=\"language-bash\">dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer<\/code><\/pre>\n<h5>Token\u7522\u751f\u7684\u8a2d\u5b9a<\/h5>\n<p>\u9019\u90e8\u5206\u9700\u8981\u5728<code>Startup.ConfigureServices<\/code>\u52a0\u5165\u4ee5\u4e0b\u5167\u5bb9\u3002<\/p>\n<pre><code class=\"language-cs\">\/\/ Adding Authentication  \nservices.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)  \n\/\/ Adding Jwt Bearer  \n.AddJwtBearer(options =&gt;  \n{  \n    options.TokenValidationParameters = new TokenValidationParameters()  \n    {  \n        ValidateIssuer = true,  \n        ValidateAudience = true,  \n        ValidAudience = Configuration[&quot;JWT:ValidAudience&quot;], \/\/ \u8a2d\u5b9a\u6a94\u5167Audience\u8cc7\u6599\n        ValidIssuer = Configuration[&quot;JWT:ValidIssuer&quot;],  \/\/ \u8a2d\u5b9a\u6a94\u5167Issuer\u8cc7\u6599\n        IssuerSigningKey = new SymmetricSecurityKey(Encoding\n            .UTF8.GetBytes(Configuration[&quot;JWT:Secret&quot;]))  \/\/ \u7c3d\u7ae0\u5bc6\u9470\u81ea\u884c\u8a2d\u5b9a\n    };  \n}); <\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\u8aaa\u660e\u4e00\u4e0b\u5982\u4f55\u6838\u767cToken\u3002<\/p>\n<h5>Token\u7684\u6838\u767c<\/h5>\n<p>\u9019\u90e8\u5206\u53ef\u4ee5\u4f7f\u7528\u4fdd\u54e5\u90a3\u7bc7\u6587\u7ae0\u5beb\u597d\u7684Helper\u4f86\u6838\u767c\u5373\u53ef\uff0c\u9019\u908a\u4e5f\u662f\u91cd\u9ede\u5f0f\u8aaa\u660e\uff0c\u6240\u4ee5\u6838\u767c\u7684\u7bc4\u4f8b\u5982\u4e0b\u3002<\/p>\n<pre><code class=\"language-cs\">var issuer = &quot;JwtSettings:Issuer&quot;; \/\/ \u8a2d\u5b9a\u6a94\u5167Issuer\u8cc7\u6599\nvar signKey = &quot;JwtSettings:SignKey&quot;; \/\/ \u7c3d\u7ae0\u5bc6\u9470\u81ea\u884c\u8a2d\u5b9a\n\/\/ \u8a2d\u5b9a\u8981\u52a0\u5165\u5230 JWT Token \u4e2d\u7684\u8072\u660e\u8cc7\u8a0a(Claims)\nvar claims = new List&lt;Claim&gt;();\n\nclaims.Add(new Claim(JwtRegisteredClaimNames.Sub, userName)); \/\/ User.Identity.Name\nclaims.Add(new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())); \/\/ JWT ID\n\n\/\/ \u4f60\u53ef\u4ee5\u81ea\u884c\u64f4\u5145 &quot;roles&quot; \u52a0\u5165\u767b\u5165\u8005\u8a72\u6709\u7684\u89d2\u8272\nclaims.Add(new Claim(&quot;roles&quot;, &quot;Admin&quot;));\nclaims.Add(new Claim(&quot;roles&quot;, &quot;Users&quot;));\nvar userClaimsIdentity = new ClaimsIdentity(claims);\n\/\/ \u5efa\u7acb\u4e00\u7d44\u5c0d\u7a31\u5f0f\u52a0\u5bc6\u7684\u91d1\u9470\uff0c\u4e3b\u8981\u7528\u65bc JWT \u7c3d\u7ae0\u4e4b\u7528\nvar securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(signKey));\n\/\/ HmacSha256 \u6709\u8981\u6c42\u5fc5\u9808\u8981\u5927\u65bc 128 bits\uff0c\u6240\u4ee5 key \u4e0d\u80fd\u592a\u77ed\uff0c\u81f3\u5c11\u8981 16 \u5b57\u5143\u4ee5\u4e0a\n\/\/ https:\/\/stackoverflow.com\/questions\/47279947\/idx10603-the-algorithm-hs256-requires-the-securitykey-keysize-to-be-greater\nvar signingCredentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature);\n\/\/ \u5efa\u7acb SecurityTokenDescriptor\nvar tokenDescriptor = new SecurityTokenDescriptor\n{\n    Issuer = issuer,\n    Subject = userClaimsIdentity,\n    Expires = DateTime.Now.AddMinutes(expireMinutes),\n    SigningCredentials = signingCredentials\n};\n\/\/ \u7522\u51fa\u6240\u9700\u8981\u7684 JWT securityToken \u7269\u4ef6\uff0c\u4e26\u53d6\u5f97\u5e8f\u5217\u5316\u5f8c\u7684 Token \u7d50\u679c(\u5b57\u4e32\u683c\u5f0f)\nvar tokenHandler = new JwtSecurityTokenHandler();\nvar securityToken = tokenHandler.CreateToken(tokenDescriptor);\nvar serializeToken = tokenHandler.WriteToken(securityToken);\nreturn serializeToken;<\/code><\/pre>\n<p>\u6240\u4ee5\u7d93\u904e\u9019\u65b9\u6cd5\u53ef\u4ee5\u5f97\u5230\u4e00\u7d44string\u7684Token\uff0c\u6240\u4ee5\u5728\u9019\u4e4b\u524d\u53ef\u4ee5\u5148\u9a57\u8b49\u8cc7\u6599\u5eab\u5e33\u5bc6\u662f\u5426\u7b26\u5408\uff0c\u4e26\u4e14\u53ef\u4ee5\u7531\u8cc7\u6599\u5eab\u4e2d\u53d6\u7684\u6b0a\u9650\u7684\u8cc7\u6599\u65bc\u4e0a\u8ff0\u4f8b\u5b50\u4e2d\u653e\u9032\u53bbToken\u4e4b\u4e2d\uff0c\u6700\u5f8c\u518d\u5c07\u9019\u7d44Token\u8fd4\u9084\u7d66\u4f7f\u7528\u8005\u4fdd\u5b58\u5373\u53ef\u3002<\/p>\n<h5>Token\u7684\u4f7f\u7528<\/h5>\n<p>\u524d\u9762\u8aaa\u660e\u904e\u5982\u4f55\u5728\u4f3a\u670d\u5668\u7aef\u9a57\u8b49\u8acb\u6c42\u662f\u5426\u7d93\u904e\u6388\u6b0a\uff0c\u6240\u4ee5\u9019\u908a\u5148\u8aaa\u660e\u5728\u5ba2\u6236\u7aef\u5982\u4f55\u4f7f\u7528Token\uff0c\u7c21\u55ae\u8aaa\u660e\u5c31\u662f\u5728\u767c\u51fa\u8acb\u6c42\u524d\u5148\u628aToken\u653e\u5728\u8acb\u6c42\u7684Header\u5167\u5373\u53ef\uff0c\u653eToken\u7684\u65b9\u5f0f\u5982\u4e0b\u3002<\/p>\n<pre><code>Authorization: Bearer eyJhbGci...&lt;snip&gt;...yu5CSpyHI<\/code><\/pre>\n<p>\u800c\u4f3a\u670d\u5668\u7aef\u7576\u6536\u5230Token\u53ef\u4ee5\u900f\u904e\u4e0b\u5217\u65b9\u5f0f\u53d6\u5f97\u5b58\u653e\u5728Token\u5167\u7684\u8cc7\u6599\u3002<\/p>\n<pre><code class=\"language-cs\">User.Identity.Name; \/\/ \u4f7f\u7528\u8005\u540d\u7a31\nUser.Claims; \/\/ \u5176\u4ed6\u5b58\u653e\u5728Token\u7684\u8cc7\u8a0a<\/code><\/pre>\n<h2>\u5f8c\u8a18<\/h2>\n<p>\u7d93\u904e\u4eca\u5929\u7684\u5167\u5bb9\u8ddf\u5927\u5bb6\u4ecb\u7d39\u5982\u4f55\u5728\u7db2\u9801\u7a0b\u5f0f\u4e2d\u52a0\u5165\u8eab\u5206\u9a57\u8b49\uff0c\u4ee5\u53ca\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528jwt token\u4f86\u8655\u7406\u6388\u6b0a\u554f\u984c\uff0c\u5e0c\u671b\u80fd\u5920\u5e6b\u52a9\u5927\u5bb6\u5c08\u5fc3\u5728\u672c\u8cea\u5546\u696d\u908f\u8f2f\u7684\u958b\u767c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7121\u72c0\u614b\u7684HttpRequest\u600e\u9ebc\u505a\u8eab\u5206\u9a57\u8b49 \u76f4\u5230\u6628\u5929\u5c07\u7db2\u9801\u7684\u57fa\u790e\u77e5\u8b58\u4ecb\u7d39\u5b8c\u4e86\uff0c\u6240\u4ee5\u4eca\u5929\u958b\u59cb\u6703\u4ecb\u7d39\u4e00\u4e9b\u958b\u767c\u4e0a\u6703 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.develop-note.com\/blog\/2021\/10\/02\/jwt-authentication-authorization\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008D-13-\u6388\u6b0a jwt ? authentication ? authorization\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[90,124,122,92,120],"class_list":["post-2349","post","type-post","status-publish","format-standard","hentry","category-develop","tag-2021ironman","tag-authentication","tag-authorization","tag-dotnetcore","tag-jwt"],"_links":{"self":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/2349","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/comments?post=2349"}],"version-history":[{"count":32,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/2349\/revisions"}],"predecessor-version":[{"id":2936,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/2349\/revisions\/2936"}],"wp:attachment":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/media?parent=2349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/categories?post=2349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/tags?post=2349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}