第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在.net Core 2.2中實現(xiàn)JWT令牌

如何在.net Core 2.2中實現(xiàn)JWT令牌

C#
炎炎設(shè)計 2023-07-09 17:51:34
我已經(jīng)為此奮斗了幾個小時,似乎無法找出為什么我對[Authorize]啟用的端點的所有調(diào)用都失敗并出現(xiàn) 401。在我的 .Net Core 2.2 Web API 項目的 Startup.cs 中,我設(shè)置了身份驗證:public void ConfigureServices(IServiceCollection services)        {            var jwtSettings = new JwtSettings();            Configuration.Bind(nameof(jwtSettings), jwtSettings);            services.AddSingleton(jwtSettings);            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);            // Add the JWT Bearer token configuration            services.AddAuthentication(x =>            {                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;                x.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;                x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;            })            .AddJwtBearer(x =>            {                x.SaveToken = true;                x.TokenValidationParameters = new TokenValidationParameters                {                    ValidateIssuerSigningKey = true,                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("craigcraigcraigcraigcraigcraig")),//jwtSettings.Secret)),                    ValidateIssuer = false,                    ValidateAudience = false,                    RequireExpirationTime = false,                    ValidateLifetime = true                };            });            services.AddSwaggerGen(x =>            {                x.SwaggerDoc("v1", new Info { Title = "My Backend", Version = "v1" });                var security = new Dictionary<string, IEnumerable<string>>                {                    {"Bearer", new string[0]}                };            });        }請注意,我對我的密鑰進行了硬編碼,因為我不確定這是否是問題所在。該令牌返回到我的 Swagger 前端,看起來不錯。
查看完整描述

1 回答

?
江戶川亂折騰

TA貢獻1851條經(jīng)驗 獲得超5個贊

你已經(jīng)在那里了,但是curl有一個拼寫錯誤,更改AuthorisationAuthorization

curl -X GET“ https://localhost:44370/api/accounts ”-H“接受:application/json”-H“授權(quán):Bearer eyJ.....


查看完整回答
反對 回復(fù) 2023-07-09
  • 1 回答
  • 0 關(guān)注
  • 143 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號