reactjs - IdentityServer4 提供未格式化的支持范围
问题描述
问题是我有一个名为 tv-participants-lookup 的 .net core 3.1 和 reactjs 项目,在实施和配置 serveridentity4 之后,当尝试注册或登录时,它返回 Invalid Scope 错误,因此问题如下所示.well-known/openid 配置:
{
"issuer": "https://localhost:5001",
"jwks_uri": "https://localhost:5001/.well-known/openid-configuration/jwks",
"authorization_endpoint": "https://localhost:5001/connect/authorize",
"token_endpoint": "https://localhost:5001/connect/token",
"userinfo_endpoint": "https://localhost:5001/connect/userinfo",
"end_session_endpoint": "https://localhost:5001/connect/endsession",
"check_session_iframe": "https://localhost:5001/connect/checksession",
"revocation_endpoint": "https://localhost:5001/connect/revocation",
"introspection_endpoint": "https://localhost:5001/connect/introspect",
"device_authorization_endpoint": "https://localhost:5001/connect/deviceauthorization",
"frontchannel_logout_supported": true,
"frontchannel_logout_session_supported": true,
"backchannel_logout_supported": true,
"backchannel_logout_session_supported": true,
"scopes_supported": [
"openid",
"profile",
"API.ClientId",
"TV Participants lookupAPI", **<=======** you may notice the space between the words causing it to appear like three scopes when validating the scopes
"offline_access"
],
这是我的 appsettings.json:
"IdentityServer": {
"Clients": {
"client1": {
"Profile": "IdentityServerSPA",
"AlowedScopes":"openid profile"
}
},
"Resources": {
"API.ClientId": {
"Profile": "API"
}
}
},
startup.cs 如下:
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString(("DefaultConnection"))));
services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddRoles<IdentityRole>()
.AddRoleManager<RoleManager<IdentityRole>>()
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
services.AddAuthorization();
services.Configure<IdentityOptions>(options =>
{
options.ClaimsIdentity.RoleClaimType = JwtClaimTypes.Role;
});
services.AddAuthentication()
.AddIdentityServerJwt();
services.AddTransient<IProfileService, ProfileService>();
services.AddControllersWithViews();
services.AddRazorPages();
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/build";
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseIdentityServer();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
});
}
所以问题是 openid-connect 从哪里得到这个范围 - “TV Participants lookupAPI” - 从?有没有办法删除或更改 scopes_supported ?
解决方案
想通了,因为我必须更改项目名称并删除空格。一旦.csproj
命名TV_Participants_lookupAPI
,问题就解决了。
推荐阅读
- php - cron 命令在共享主机中无法与 DirectAdmin 一起使用
- javascript - 如何在修改交互期间显示当前区域?
- python - Selenium 地理定位测试
- python - CNN模型第二次运行时如何解决cuDNN错误
- android - 当应用程序进入后台时,Jetpack Compose rememberSaveable() 导致崩溃
- javascript - 如何从 basse64 字符串下载 PDF
- xml - Powerpoint 中的自定义 SuperTheme XML
- javascript - 通过Node js中的href标签向猫鼬查询提供输入时无法从数据库中获取数据
- javascript - 是否可以捕获服务器内部对服务进行的 Http 调用
- automation - 空手道 DSL:支持 Apache Thrift