ASP.NETCore3.1+OpenIDConnect+AD无法将idtoken保持在User.Identity中。
创始人
2024-09-17 09:00:52
0

在ConfigureServices方法中添加:

services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; }) .AddCookie() .AddOpenIdConnect(options => { options.Authority = Configuration["Authentication:Authority"]; options.ClientId = Configuration["Authentication:ClientId"]; options.ClientSecret = Configuration["Authentication:ClientSecret"]; options.ResponseType = OpenIdConnectResponseType.IdToken; options.CallbackPath = "/signin-oidc"; options.SignedOutCallbackPath = "/signout-callback-oidc"; options.UsePkce = false; options.SaveTokens = true; options.GetClaimsFromUserInfoEndpoint = true; options.TokenValidationParameters = new TokenValidationParameters { NameClaimType = "name", RoleClaimType = "role" }; });

在Configure方法中添加:

app.UseAuthentication();

然后在控制器中使用以下代码:

if (User.Identity.IsAuthenticated) { string idToken = await HttpContext.GetTokenAsync("id_token"); // 使用id token }

这将从缓存中获取id_token以供后续使用。

相关内容

热门资讯

透视肯定(wepoke确实有挂... 透视肯定(wepoke确实有挂)fishpoker大菠萝外挂(详细辅助透明教程)原本有挂1)wepo...
微扑克ai机器人!wepoke... 微扑克ai机器人!wepoke软件透明挂,(wepOke)从来存在有挂(详细透视wpk教程)是一款可...
透视智能ai(wepokeai... 透视智能ai(wepokeai机器人)微扑克有挂(详细辅助扑克教程)都是是真的有挂,您好,wepok...
wepoke一定有挂!wepo... wepoke一定有挂!wepoke辅助机器人,(AAPoKER)一直有挂(详细透视辅助教程)科技教程...
透视好友房(wepoke真的有... 透视好友房(wepoke真的有挂)德扑ai智能机器人线上代打(详细辅助科技教程)好像是有挂是一款可以...
透视代打(微扑克游戏辅助器)w... 透视代打(微扑克游戏辅助器)wpk ai(详细辅助力荐教程)真是真的是有挂是一款可以让一直输的玩家,...
wepoke辅助技巧!德州之星... wepoke辅助技巧!德州之星辅助透视,(aapokEr)果然真的是有挂(详细辅助实用技巧);《WP...
透视模拟器(WePoKe透明挂... 透视模拟器(WePoKe透明挂)微扑克辅助钻石(详细辅助2025新版总结)总是是有挂1)WePoKe...
微扑克全自动机器人!wepok... 微扑克全自动机器人!wepoke ai,(wEPOKE)本然是有挂(详细透视插件教程)1、点击下载安...
透视透视挂(aapoker辅助... 透视透视挂(aapoker辅助工具存在)aapoker软件有猫腻吗(详细辅助wpk教程)一贯是有挂a...