asp.net-core-webapi - asp.net core IdentityServer 4没有持久授权Safari
问题描述
我有一个使用身份 4 进行身份验证的 asp.net core blazor wasm 应用程序。它根据 Visual Studio 进行设置并部署到 Azure 应用服务。当我通过 Edge 在 Windows 上使用它时,它按预期工作,我可以登录并在表 PersistedGrants 中看到一个新条目,并且我可以使用多台计算机登录而不会出现问题。
当我知道从 Mac 上的 Safari 或 iOS 设备上的任何浏览器登录时(因为它们都使用相同的浏览器引擎),整个 PersistedGrants 表将被删除。据我所知,如果我使用已经获得授权的同一个用户或另一个用户登录并不重要,所有条目都将被删除。登录过程在所有情况下都返回成功。
在包方面,我使用 Microsoft.AspNetCore.ApiAuthorization.IdentityServer 3.1.4 和 Blazor 的发布版本。
我的启动:
...
services.AddDbContext<ISupportToolContext, SupportToolContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddRoles<ApplicationIdentityRole>()
.AddEntityFrameworkStores<SupportToolContext>();
Log.Information($"Identity Server Key Type loaded: {Configuration.GetSection("IdentityServer:Key")["Type"]}");
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, SupportToolContext>();
services.AddAuthentication()
.AddIdentityServerJwt();
services.Configure<IdentityOptions>(options =>
{
// Password settings
options.Password.RequireDigit = false;
options.Password.RequiredLength = MIN_PASSWORD_LENGTH;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.Password.RequireLowercase = false;
// Lockout settings
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(LOCKOUT_DURATION);
options.Lockout.MaxFailedAccessAttempts = MAX_TRIES_BEFORE_LOCKOUT;
options.Lockout.AllowedForNewUsers = true;
// Email Settings
options.User.RequireUniqueEmail = true;
options.SignIn.RequireConfirmedEmail = true;
});
// Configure LifeSpan of Identity email tokens
services.Configure<DataProtectionTokenProviderOptions>(options =>
{
options.TokenLifespan = TimeSpan.FromDays(IDENTITY_TOKEN_DURATION);
});
services.ConfigureApplicationCookie(options =>
{
options.Cookie.HttpOnly = false;
options.Events = new CookieAuthenticationEvents
{
OnRedirectToLogin = context =>
{
context.Response.StatusCode = UNAUTHORIZED_STATUS_CODE;
return Task.CompletedTask;
}
};
});
...
和客户端 Programm.cs:
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddBlazoredModal();
builder.Services.AddI18nText();
builder.Services.AddAuthorizationCore();
// Service registration
...
builder.Services.AddHttpClient("ApplySupportTool.ServerAPI", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
// Supply HttpClient instances that include access tokens when making requests to the server project
builder.Services.AddTransient(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("ApplySupportTool.ServerAPI"));
builder.Services.AddApiAuthorization();
builder.Services.AddOptions();
await builder.Build().RunAsync();
在 index.html 中:
<script src="_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>
<script src="_framework/blazor.webassembly.js"></script>
谁能指出我可能是什么或如何找到更多信息?
解决方案
推荐阅读
- javascript - 缩略图未显示在相关博主上
- cookies - 使用 blazor 设置 httponly cookie
- python - 如何获取给定位置的相应 pytz 时区名称?
- c++ - 递归计算给定目录的文件和所有目录
- javascript - indesign 段落的段落前导到底是什么
- machine-learning - 我需要一个生成句子的服务,包括一组单词
- php - PHP - 在保存图像之前检测图像文件大小
- azure - Azure Search 搜索带有图像的文章
- power-automate - 微软流程返回 JSON 格式错误
- php - 我收到如下错误警告:include_once(C:/xampp/htdocs/timetable/header.php):无法打开流:没有这样的文件或目录