Место общения программистов C#
Anonymous
Добавление нескольких схем аутентификации в приложение .NET
Сообщение
Anonymous » 30 окт 2024, 11:05
В настоящее время мы используем Auth0 в качестве механизма аутентификации для бухгалтеров. Мы хотели бы добавить .Net Identity для администраторов.
Ниже приведен мой код
Код: Выделить всё
// Accountants
configurationbuilder.Services.AddAuth0WebAppAuthentication("AccountantScheme", options =>{ options.Domain = builder.Configuration["Auth0:Domain"];
options.ClientId = builder.Configuration["Auth0:ClientId"]; options.ClientSecret = builder.Configuration["Auth0:ClientSecret"]; options.Scope = "openid profile email";
options.OpenIdConnectEvents = new OpenIdConnectEvents { OnAccessDenied = context => { context.Response.Redirect("/"); context.HandleResponse(); return Task.FromResult(0); } };
options.CookieAuthenticationScheme = "AccountantCookies"; }).WithAccessToken(options =>{ options.Audience = builder.Configuration["Auth0:ManagementAudience"]; options.UseRefreshTokens = true;});
builder.Services.Configure("AccountantCookies", options =>{ options.LoginPath = "/AccountantPortal/Authentication/LogIn/Login"; options.LogoutPath = "/AccountantPortal/Authentication/LogOut/Logout";});
builder.Services.AddDbContext(opts => opts.UseNpgsql(builder.Configuration["Database:ConnectionString"]));
//Admins
builder.Services.AddIdentity() .AddEntityFrameworkStores() .AddDefaultTokenProviders();
// Configure custom Identity cookie settings for Admins
builder.Services.ConfigureApplicationCookie(options =>{ options.Cookie.Name = "AdminIdentityCookies"; options.LoginPath = "/AdminPortal/Account/Login"; options.LogoutPath = "/AdminPortal/Account/Logout"; options.AccessDeniedPath = "/AdminPortal/Account/AccessDenied";});
Когда я вхожу в систему с помощью Auth0, он использует схему идентификации по умолчанию.
Мое приложение использует .net 8
Подробнее здесь:
https://stackoverflow.com/questions/791 ... pplication
1730275557
Anonymous
В настоящее время мы используем Auth0 в качестве механизма аутентификации для бухгалтеров. Мы хотели бы добавить .Net Identity для администраторов. Ниже приведен мой код [code]// Accountants configurationbuilder.Services.AddAuth0WebAppAuthentication("AccountantScheme", options =>{ options.Domain = builder.Configuration["Auth0:Domain"]; options.ClientId = builder.Configuration["Auth0:ClientId"]; options.ClientSecret = builder.Configuration["Auth0:ClientSecret"]; options.Scope = "openid profile email"; options.OpenIdConnectEvents = new OpenIdConnectEvents { OnAccessDenied = context => { context.Response.Redirect("/"); context.HandleResponse(); return Task.FromResult(0); } }; options.CookieAuthenticationScheme = "AccountantCookies"; }).WithAccessToken(options =>{ options.Audience = builder.Configuration["Auth0:ManagementAudience"]; options.UseRefreshTokens = true;}); builder.Services.Configure("AccountantCookies", options =>{ options.LoginPath = "/AccountantPortal/Authentication/LogIn/Login"; options.LogoutPath = "/AccountantPortal/Authentication/LogOut/Logout";}); builder.Services.AddDbContext(opts => opts.UseNpgsql(builder.Configuration["Database:ConnectionString"])); //Admins builder.Services.AddIdentity() .AddEntityFrameworkStores() .AddDefaultTokenProviders(); // Configure custom Identity cookie settings for Admins builder.Services.ConfigureApplicationCookie(options =>{ options.Cookie.Name = "AdminIdentityCookies"; options.LoginPath = "/AdminPortal/Account/Login"; options.LogoutPath = "/AdminPortal/Account/Logout"; options.AccessDeniedPath = "/AdminPortal/Account/AccessDenied";}); [/code] [b]Когда я вхожу в систему с помощью Auth0, он использует схему идентификации по умолчанию.[/b] Мое приложение использует .net 8 Подробнее здесь: [url]https://stackoverflow.com/questions/79139978/adding-multiple-authentication-schemes-to-a-net-application[/url]