相关疑难解决方法(0)

使用多个JWT承载认证

是否有可能在ASP.NET Core 2中支持多个JWT令牌发行者?我想为外部服务提供API,我需要使用两个JWT令牌源 - Firebase和自定义JWT令牌发行者.在ASP.NET核心中,我可以为Bearer身份验证方案设置JWT身份验证,但仅限于一个权限:

  services
        .AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
        .AddJwtBearer(options =>
        {
            options.Authority = "https://securetoken.google.com/my-firebase-project"
            options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer = true,
                    ValidIssuer = "my-firebase-project"
                    ValidateAudience = true,
                    ValidAudience = "my-firebase-project"
                    ValidateLifetime = true
                };
        }
Run Code Online (Sandbox Code Playgroud)

我可以有多个发行人和受众,但我不能设置多个权限.

jwt asp.net-core-mvc firebase-authentication asp.net-core-2.0

46
推荐指数
2
解决办法
1万
查看次数

ASP.NET Core 2.0将Cookie和承载授权结合在一起,用于同一端点

我在VS17中使用"Web应用程序(模型 - 视图 - 控制器)"模板和".Net Framework"+"ASP.NET Core 2"作为配置创建了一个新的ASP.NET核心Web应用程序项目.身份验证配置设置为"个人用户帐户".

我有以下示例端点:

[Produces("application/json")]
[Route("api/price")]
[Authorize(Roles = "PriceViwer", AuthenticationSchemes = "Cookies,Bearer")]
public class PriceController : Controller
{

    public IActionResult Get()
    {
        return Ok(new Dictionary<string, string> { {"Galleon/Pound",
                                                   "999.999" } );
    }
}
Run Code Online (Sandbox Code Playgroud)

"Cookies,Bearer"是通过连接CookieAuthenticationDefaults.AuthenticationScheme和派生而得到的JwtBearerDefaults.AuthenticationScheme.

目标是能够为端点配置授权,以便可以使用令牌和cookie身份验证方法访问它.

以下是我在Startup.cs中进行身份验证的设置:

    services.AddAuthentication()
        .AddCookie(cfg => { cfg.SlidingExpiration = true;})
        .AddJwtBearer(cfg => {
            cfg.RequireHttpsMetadata = false;
            cfg.SaveToken = true;
            cfg.TokenValidationParameters = new TokenValidationParameters() {
                                                    ValidIssuer = Configuration["Tokens:Issuer"],
                                                    ValidAudience = Configuration["Tokens:Issuer"],
                                                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Tokens:Key"]))
                                                };
        });
Run Code Online (Sandbox Code Playgroud)

因此,当我尝试使用浏览器访问端点时,我得到了一个带有空白html页面的401响应. …

.net c# asp.net authentication asp.net-core-2.0

19
推荐指数
3
解决办法
7761
查看次数

为asp.net-core 2中的每个角色实现不同的登录页面

我想根据每个用户在 asp net core 中的角色实现不同的登录页面。我可以设置登录路径,但它对于任何角色都是静态的。

   services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
        .AddCookie(options =>
        {
            options.LoginPath = "Account/Login/";
            options.AccessDeniedPath = "Account/Forbidden/";
        }); 
Run Code Online (Sandbox Code Playgroud)

因此,当我调用授权(role =“Admin”)的操作时,重定向到管理员登录页面。当调用 Authorize(role="User") 重定向到用户登录页面的操作时

httpcookie asp.net-core asp.net-core-2.0

0
推荐指数
1
解决办法
2893
查看次数