问题描述
pitch / sizeof(datatype)
AzureADDefaults.AuthenticationScheme 和 AzureADDefaults.OpenIdScheme 现在已过时,消息“改用 Microsoft.Identity.Web。请参阅 https://aka.ms/ms-identity-web."。但是我找不到任何明确的文档如何升级以下代码以使用 Identity.Web而不是那些过时的常量。
解决方法
此 blog 向您展示了 Identity Platform
和 Identity.Web
之间的区别。
对于 Identity.Web,我们使用 Microsoft.Identity.Web
和 Microsoft.Identity.Web.UI
。尝试查看此 sample,它使用 AddMicrosoftIdentityWebAppAuthentication 来登录用户。
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.Unspecified;
// Handling SameSite cookie according to https://docs.microsoft.com/en-us/aspnet/core/security/samesite?view=aspnetcore-3.1
options.HandleSameSiteCookieCompatibility();
});
// Sign-in users with the Microsoft identity platform
services.AddMicrosoftIdentityWebAppAuthentication(Configuration);
services.AddControllersWithViews(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
}).AddMicrosoftIdentityUI();
services.AddRazorPages();
}