亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

從外部訪問 User.Identity 和 Claims

從外部訪問 User.Identity 和 Claims

C#
達令說 2021-07-27 21:08:53
我正在嘗試使用 OpenID Connect 構建 SSO(.net core) 服務,這將是 Webforms 應用程序和服務提供者之間的一個層。我創建了一些端點來檢查用戶是否通過身份驗證并從服務中獲取用戶聲明。當我從瀏覽器調用這些端點時,我能夠獲得正確的結果。但是,當我從網站(使用 HttpWebRequest)調用它們時。User.Identity總是空的。我用來檢查用戶是否通過身份驗證的端點如下所示:[HttpGet][Route("IsAuthenticated")]public IActionResult IsAuthenticated(){    return Json(User.Identity.IsAuthenticated);}或者獲取訪問令牌:[HttpGet][Route("access_token")]public async Task<IActionResult> AccessToken(){    var tokenResult = await HttpContext.GetTokenAsync("access_token");    return Json(tokenResult);}我的啟動 ConfigureServices 看起來像這樣:var OIDCConfiguration = new OIDCSettings(){    Authority = Configuration["OIDCSettings:Authority"],    ClientId = Configuration["OIDCSettings:ClientId"],    ClientSecret = Configuration["OIDCSettings:ClientSecret"],    CallbackPath = Configuration["OIDCSettings:CallbackPath"],    UserInfoEndpoint = Configuration["OIDCSettings:UserInfoEndpoint"]};services.AddAuthentication(options => {    options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;    options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;    options.DefaultChallengeScheme = "oidc";}).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme).AddOpenIdConnect("oidc", options => {    options.Authority = OIDCConfiguration.Authority;    options.ClientId = OIDCConfiguration.ClientId;    options.ClientSecret = OIDCConfiguration.ClientSecret;    options.CallbackPath = new PathString(OIDCConfiguration.CallbackPath);    options.ResponseType = OpenIdConnectResponseType.Code;    options.GetClaimsFromUserInfoEndpoint = true;    options.Scope.Add("openid emailAddress");    options.AuthenticationMethod = OpenIdConnectRedirectBehavior.RedirectGet;    options.SaveTokens = true;});為了啟動中間件,我使用了 ChallengeResult 對象。我是 OpenID Connect 和中間件架構的初學者,所以我不確定我缺少什么,或者我的架構是否正確。
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 270 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號