我正在尝试在 ValidateClientAuthentication 函数中验证客户端 ID。我正在使用 grant_type=password 流程。以下是我在身份验证 token 请求正文中传递 client_id 的方式。
Content-Type: application/x-www-form-urlencoded
grant_type=password&username=user1@test.com&password=pwduser1&client_id=B36B-07DEAC802BEA
当我尝试访问 ClientId 以验证客户端 ID 时,它始终为空。
if (context.ClientId != null)
{
//Set the client who initiated request is valid
context.Validated();
}
else
{
//reject access to application
context.Rejected();
context.SetError("Invalid client_id", "Client_id must present in the request header");
}
当 grant_type=password 时,将客户端 ID 传递到 token 端点的正确方法是什么?
感谢您的帮助。
最佳答案
如果您的 client_id
作为表单参数传递,您必须通过 context.TryGetFormCredentials(out clientId, out clientSecret);
获取它>
如果您的 client_id
作为 Authorization
header 传递,您可以通过执行 context.TryGetBasicCredentials(out clientId, out clientSecret);
从您的请求中获得client_id
后,执行context.Validated(clientId)
,这将设置您的context.ClientId
属性,此属性将始终为 null,直到您完成 context.Validated()
关于c# - client_id 在 ValidateClientAuthentication 中始终为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37119386/