我的 ASP.NET 项目设置了有效的 Okta 身份验证,但我需要允许用户通过另一个服务进行身份验证,该服务也使用 JWT。这样做的最佳做法是什么? Okta 身份验证是使用 this guid 设置的,所以 Startap.cs 有这个方法:
public void Configuration(IAppBuilder app)
{
app.UseOktaWebApi(new OktaWebApiOptions()
{
OktaDomain = ConfigurationManager.AppSettings["okta:OktaDomain"],
});
}
我已经尝试使用 this guid , 但无法使它工作,因为它出错了
Error CS1061 'AuthenticationBuilder' does not contain a definition for 'AddOpenIdConnect' and no accessible extension method 'AddOpenIdConnect' accepting a first argument of type 'AuthenticationBuilder' could be found (are you missing a using directive or an assembly reference?)
代码
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "OpenIdConnect";
})
.AddCookie()
.AddOpenIdConnect(options =>{}); // error is thrown here
最佳答案
经过大量谷歌搜索并试图找到解决方案后,我创建了一个 AuthorizeAttribute 并覆盖了 IsAuthorized 方法:
public class MyAuthorizeAttribute : AuthorizeAttribute
{
protected override bool IsAuthorized(HttpActionContext actionContext)
{
// here we can check if default (in my case Okta) authorization allowed access for request
if (base.IsAuthorized(actionContext))
{
return true;
}
// add some logic and return true or false depending on if access is allowed or not
return false;
}
}
关于asp.net - 如何将身份验证方法添加到现有的 Okta 到 ASP.NET 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59542022/