dotnet核心IdentityModel不会内省令牌

问题描述 投票:2回答:1

我正在将我的一个API应用程序移植到dotnet core(v2),可能这个升级中最重要的部分是让我的身份验证正常工作。

为此,我已将Thinkteture的IdentityModel包添加到我的项目中。

我的API如何工作是它从来电者那里以持有人令牌的形式接收一个身份验证头。然后我Introspect该令牌验证它是否可以接受当前任务,并继续主逻辑。

但是,我似乎只是在代码的初始设置中遗漏了一些绝对基本的东西,因为我根本无法进行内省。

接下来,我有一些来自我的Startup.cs和一个控制器的片段。

Startup.cs

   public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
        services.AddAuthentication(OAuth2IntrospectionDefaults.AuthenticationScheme)
            .AddOAuth2Introspection(options =>
            {
                options.IntrospectionEndpoint = "#REDACTED#";

                options.ClientId = "#REDACTED#";
                options.ClientSecret = "#REDACTED#";

            });
        var x = 1;

    }

ItemsController.cs

    [HttpGet]
    public IEnumerable<string> Get()
    {
       return new string[] { "isAuthenticated", $"{User.Identity.IsAuthenticated}" };
    }

此端点(GET api / items)始终返回false,我的OIDC服务器应用程序从不记录任何与之通信的尝试。在services.AddAuthentication()代码上设置的断点捕获,所以我知道基本的设置部分已到位。

我尝试过的其他一些事情:

  • Authorize装饰放在方法上(并没有真正期望这个工作..但它没有)
  • 使用Authority选项,并允许发现内省端点(我想也许我的OIDC服务器可能不支持发现,这导致了问题,但提供内省端点没有任何区别)

我确定我错过了一些完全无足轻重的东西,但是经过几个小时的探索,搜索和尝试各种各样的东西,我意识到我必须忽略它。

c# .net-core thinktecture-ident-model
1个回答
2
投票

即使这个答案来得晚,我也想问你是否尝试过将SkipTokensWithDots设置为false

对我有用的是:

services.AddAuthentication(OAuth2IntrospectionDefaults.AuthenticationScheme)
    .AddOAuth2Introspection(options =>
    {
        options.IntrospectionEndpoint = "#REDACTED#";

        options.ClientId = "#REDACTED#";
        options.ClientSecret = "#REDACTED#";

        // We are using introspection for JWTs so we need to override the default
        options.SkipTokensWithDots = false;
    });
© www.soinside.com 2019 - 2024. All rights reserved.