client_id 在 ValidateClientAuthentication 中始终为 null
client_id is always null in ValidateClientAuthentication
我正在尝试在 ValidateClientAuthentication 函数中验证客户端 ID。我正在使用 grant_type=密码流。这是我在身份验证令牌请求正文中传递 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=密码时,将客户端 ID 传递给令牌端点的正确方法是什么?
感谢您的帮助。
如果您的 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
属性,此 属性 将始终在你完成 context.Validated()
之前为空
我正在尝试在 ValidateClientAuthentication 函数中验证客户端 ID。我正在使用 grant_type=密码流。这是我在身份验证令牌请求正文中传递 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=密码时,将客户端 ID 传递给令牌端点的正确方法是什么?
感谢您的帮助。
如果您的 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
属性,此 属性 将始终在你完成 context.Validated()