【问题标题】:#identityserver 500 error When using Authorize Attribute#identityserver 500 错误使用授权属性时
【发布时间】:2020-07-16 02:23:26
【问题描述】:

我无法调用标有任一属性的任何方法:

[Authorize(AuthenticationSchemes = "Bearer")]
[Authorize]

我已经设置了 IdentityServer 项目,并且能够从项目中获取访问令牌。

web api 项目有以下配置设置:

public void ConfigureServices(IServiceCollection services)
        {
            
             
                services.AddControllers();
                var idserver = "https://ipaddressofidntityserver";
                services.AddAuthentication("Bearer")
                    .AddJwtBearer("Bearer", options =>
                    {
                        options.Authority = idserver;

                        options.TokenValidationParameters = new TokenValidationParameters
                        {
                            ValidateAudience = false
                        };
                    });
        }
 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthentication(); 

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }

任何想法或帮助将不胜感激!

【问题讨论】:

  • 你能包含一些堆栈跟踪吗?还是日志详细信息?
  • 你的“ipaddressofidntityserver”是什么样的?只是IP地址或域名或本地主机? HTTPS 不适用于您的 IdentityServer 的 IP 地址。

标签: identityserver4


【解决方案1】:

我相信你没有在 web api 控制器中设置默认路由或使用 Route 属性。

endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");

或者在默认的 get 方法上提供 Route 属性。

[Route("/")]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-30
    • 2014-09-02
    • 2011-11-01
    • 1970-01-01
    • 2015-06-24
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多