我正在嘗試使用 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 回答
- 0 關注
- 270 瀏覽
添加回答
舉報
0/150
提交
取消