当我调用AddOpenIdConnect()时,出现异常:
处理请求时发生未处理的异常。 TypeLoadException:无法从程序集“ Microsoft.AspNetCore.Authentication,版本= 3.0.0.0,文化=中性,PublicKeyToken = adb9793829ddae60”中加载类型“ Microsoft.AspNetCore.Authentication.RequestPathBaseCookieBuilder”。
Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectOptions..ctor()
示例代码:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var builder = services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
})
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApis())
.AddInMemoryClients(Config.GetClients());
services.AddAuthentication()
.AddOpenIdConnect("aad", "Azure AD", options =>
{
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
options.SignOutScheme = IdentityServerConstants.SignoutScheme;
options.Authority = "https://login.windows.net/...";
options.ClientId = "client_id";
options.ResponseType = "id_token";
options.CallbackPath = new PathString("/signin-aad");
options.SignedOutCallbackPath = new PathString("/signout-callback-aad");
options.RemoteSignOutPath = new PathString("/signout-aad");
options.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "name",
RoleClaimType = "role"
};
});
}
答案 0 :(得分:1)
您需要向Microsoft.AspNetCore.Authentication.OpenIdConnect添加更新的nuget引用(现在位于3.3.1)。
此DLL仅以netcore为目标,因此您必须将TargetFramework从netstandard更改为netcoreapp。
哪个很烂,但是我不相信还有其他选择。
答案 1 :(得分:0)
您忘记添加Cookie Adding User Authentication with OpenID Connect
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "http://localhost:5000";
options.RequireHttpsMetadata = false;
options.ClientId = "mvc";
options.SaveTokens = true;
});