c# - IdSrv4 - 访问 token 验证器端点

标签 c# asp.net-core identityserver4

我设置了一个 Identity Server 4 服务器。在身份服务器 3 中,我们有可用的端点,因此我们可以执行以下操作:

POST /connect/accesstokenvalidation

token=<token>

我认为它在身份服务器 4 上是相同的,但我得到了 404 NOT FOUND。然后我输入:http://my-endpoint.com/.well-known/openid-configuration 并且端点不存在。

我是否应该设置一些东西以使其在身份服务器 4 上可用?

最佳答案

Introspection Endpoint .

POST /connect/introspect
Authorization: Basic xxxyyy

token=<token>

要自动授权,请使用 HTTP 基本授权流程:结合 <scope>:<scope_secret>配对并将其转换为 Base64 编码的字符串(上例中的 xxxyyy)。 scope_secret可以在 ApiResource 定义中指定值:

new ApiResource("myapi, "My API")
{
    Scopes = {new Scope("post-myapi")},
    ApiSecrets = new List<Secret> {new Secret("any_string_you_like".Sha256())},
}

然后,上面的 POST 请求应该返回类似于以下的响应:

{
    "nbf": 1491850954,
    "exp": 1491854554,
    "iss": "api-auth",
    "aud": [
        "api-auth/resources",
        "myapi"
    ],
    "client_id": "foo",
    "scope": "post-myapi",
    "active": true
}

完整请求(从 Postman 复制):

POST /connect/introspect HTTP/1.1
Host: localhost:6000
Authorization: Basic YXBpLWlzc3VlczpzY29wZVNlY3JldA==
Content-Type: application/x-www-form-urlencoded

token=.......

关于c# - IdSrv4 - 访问 token 验证器端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43322826/

相关文章:

c# - 使用 Autofac 和 EF Core 3.1 的内存泄漏(从 2.2 迁移后)

c# - 无法在 Visual Studio 2017 中复制文件 .exe

c# - Azure 上 IdentityServer 的部署问题

c# - Task.WhenAny - 任务被取消

c# - 405 方法不允许 Web API

c# - Webclient 本地对象会在文件下载前收集 .Net 垃圾吗?

C# 和 Excel 文件

iis - 使用 exe 在 IIS 上部署 ASP.NET Core

angular - 身份服务器 4 : Invalid grant type for client: authorization_code

redux - Identityserver4 与 redux -oidc 客户端请求访问 token - 但客户端未配置为通过浏览器接收访问 token