小编mTr*_*lby的帖子

使用Bearer令牌访问IdentityServer4上受保护的API

我试图搜索该问题的解决方案,但没有找到正确的搜索文本。

我的问题是,如何配置我的IdentityServer,使其也可以接受/授权带有BearerTokens的Api请求?

我已配置并正在运行IdentityServer4。我还在我的IdentityServer上配置了测试API,如下所示:

[Authorize]
[HttpGet]
public IActionResult Get()
{
    return new JsonResult(from c in User.Claims select new { c.Type, c.Value });
}
Run Code Online (Sandbox Code Playgroud)

在我的startup.cs中,ConfigureServices()如下:

public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        ...
        // configure identity server with stores, keys, clients and scopes
        services.AddIdentityServer()
            .AddCertificateFromStore(Configuration.GetSection("AuthorizationSettings"), loggerFactory.CreateLogger("Startup.ConfigureServices.AddCertificateFromStore"))

            // this adds the config data from DB (clients, resources)
            .AddConfigurationStore(options =>
            {
                options.DefaultSchema = "auth";
                options.ConfigureDbContext = builder =>
                {
                    builder.UseSqlServer(databaseSettings.MsSqlConnString,
                        sql => sql.MigrationsAssembly(migrationsAssembly));
                };
            })

            // this adds the operational data from DB (codes, tokens, consents) …
Run Code Online (Sandbox Code Playgroud)

c# jwt bearer-token asp.net-core identityserver4

4
推荐指数
1
解决办法
3110
查看次数

标签 统计

asp.net-core ×1

bearer-token ×1

c# ×1

identityserver4 ×1

jwt ×1