Сбой проверки запроса Identity Server 4 из-за недопустимых областей - PullRequest
1 голос
/ 26 января 2020

здесь впервые обращаюсь за помощью, поэтому я надеюсь, что я объясню свою проблему надлежащим образом.

У меня есть приложение. NET Core 3.0 MVC, запущенное и работающее, и я пытался добавить Identity Сервер 4 аутентификации к нему. Я часами борюсь со следующей проблемой.

Sorry, there was an error : invalid_scope
Invalid scope

В журнале я получил это сообщение

[ERR] Неверная область действия: профиль

[ ERR] Ошибка проверки запроса

Строка ниже, что в информационном журнале при проверке областей я обнаружил JSON объекты и не вижу, в чем здесь проблема.

"scope": "openid profile",

"RequestedScopes": "openid profile"

Вот файл config.cs сервера идентификации. проект

 public static IEnumerable<IdentityResource> Ids =>
            new IdentityResource[]
            {
                new IdentityResources.OpenId()
            };

        public static IEnumerable<ApiResource> Apis =>
            new ApiResource[]
            { };

        public static IEnumerable<Client> Clients =>
            new Client[]
            {
                new Client
                {
                    ClientId = "mvc",
                    ClientName = "Festival MVC",
                    AllowedGrantTypes = GrantTypes.Implicit,
                    RedirectUris = { "https://127.0.0.1:44330/signin-oidc" },
                    PostLogoutRedirectUris = { "https://127.0.0.1:44330/signout-callback-oidc" },
                    AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId }
                }
            };
    }

Startup.cs

public void ConfigureServices(IServiceCollection services)
        {
            // uncomment, if you want to add an MVC-based UI
            services.AddControllersWithViews();

            var builder = services.AddIdentityServer()
                .AddTestUsers(TestUsers.Users)
                .AddInMemoryIdentityResources(Config.Ids)
                .AddInMemoryApiResources(Config.Apis)
                .AddInMemoryClients(Config.Clients);

            // not recommended for production - you need to store your key material somewhere secure
            builder.AddDeveloperSigningCredential();
        }

        public void Configure(IApplicationBuilder app)
        {
            if (Environment.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // uncomment if you want to add MVC
            app.UseStaticFiles();
            app.UseRouting();

            app.UseIdentityServer();

            // uncomment, if you want to add MVC
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapDefaultControllerRoute();
            });
        }

На. NET Core MVC проекте Я настроил следующее в Startup.cs

 public void ConfigureServices(IServiceCollection services)
        {
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

            services.AddAuthentication(options =>
            {
                options.DefaultScheme = "Cookies";
                options.DefaultChallengeScheme = "oidc";
            })
            .AddCookie("Cookies")
            .AddOpenIdConnect("oidc", options =>
           {
               options.SignInScheme = "Cookies";
               options.Authority = "http://localhost:5000"; // Auth Server  
               options.RequireHttpsMetadata = false; // only for development   
               options.ClientId = "mvc"; // client setup in Auth Server
               options.SaveTokens = true;

           });
            services.AddControllersWithViews();
            services.AddDbContext<FestivalContext>();
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }

Если вам нужна любая другая информация или фрагмент кода, не стесняйтесь писать. Заранее спасибо и привет, Анес!

...