IdentityServer4提供错过格式的受支持范围

问题描述

问题是我有一个具有.net core 3.1和reactjs的项目,名为tv-participants-lookup,在实现和配置serveridentity4之后,当尝试注册登录时它返回Invalid Scope错误,因此问题如下所示在.well-kNown / openid-configuration中,如下所示:

{
    "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从哪里得到那个范围-“电视参与者lookupAPI”-从?并有一种方法可以删除或更改scopes_supported吗?

解决方法

想通了,因为我不得不更改项目名称并删除空格。一旦 .csproj 被命名为 TV_Participants_lookupAPI,问题就解决了。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...