我如何在asp.net核心中使用授权服务的jwt?

时间:2017-02-15 12:07:31

标签: c# asp.net-core-mvc jwt

我正在尝试创建授权服务。 我有一个使用JWT承载认证的API服务

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<JwtIssuerOptions>(options =>
    {
        options.Issuer = jwtAppSettingOptions[nameof(JwtIssuerOptions.Issuer)];
        options.Audience = jwtAppSettingOptions[nameof(JwtIssuerOptions.Audience)];
        options.SigningCredentials = new SigningCredentials(_signingKey, SecurityAlgorithms.HmacSha256);
    });
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    //...

    app.UseJwtBearerAuthentication(new JwtBearerOptions
    {
        AutomaticAuthenticate = true,
        AutomaticChallenge = true,
        TokenValidationParameters = tokenValidationParameters
    });

    //...
}

使用返回令牌的操作。我想在主应用程序中使用此令牌进行身份验证。现在它使用cookies和:

HttpContext.Authentication.SignInAsync("Cookies", new ClaimsPrincipal(claimsIdentity)). 

我如何将此令牌注入我的应用程序以及它需要什么配置?

0 个答案:

没有答案