我正在嘗試使用 OpenID Connect 構(gòu)建 SSO(.net core) 服務(wù),這將是 Webforms 應(yīng)用程序和服務(wù)提供者之間的一個(gè)層。我創(chuàng)建了一些端點(diǎn)來檢查用戶是否通過身份驗(yàn)證并從服務(wù)中獲取用戶聲明。當(dāng)我從瀏覽器調(diào)用這些端點(diǎn)時(shí),我能夠獲得正確的結(jié)果。但是,當(dāng)我從網(wǎng)站(使用 HttpWebRequest)調(diào)用它們時(shí)。User.Identity總是空的。我用來檢查用戶是否通過身份驗(yàn)證的端點(diǎn)如下所示:[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);}我的啟動(dòng) 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;});為了啟動(dòng)中間件,我使用了 ChallengeResult 對(duì)象。我是 OpenID Connect 和中間件架構(gòu)的初學(xué)者,所以我不確定我缺少什么,或者我的架構(gòu)是否正確。
- 1 回答
- 0 關(guān)注
- 259 瀏覽
添加回答
舉報(bào)
0/150
提交
取消