ASP.NET标识-令牌

本文关键字:令牌 标识 NET ASP | 更新日期: 2024-10-18 11:26:29

我正在使用ASP.NET Identity。

我可以很容易地发布令牌,但现在我想添加额外的安全性,要求我的客户端发送client_idclient_secret

所以我正在覆盖OAuthAutorizationProvider

public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
    {
        string clientId;
        string clientSecret;
        if (context.TryGetBasicCredentials(out clientId, out clientSecret))
        {
            //My code here
        }
        context.Validated();
    }

问题是我无法从TryGetBasicCredentials中获取clientId和ClientSecret——结果总是false

也许我错过了什么。。。

POST http://localhost:1323/token
Host: localhost:1673
Content-Length: 102
Content-Type: x-www-form-urlencoded
grant_type=password&username=foo&password=123456&client_id=123&client_secret=guess

ASP.NET标识-令牌

问题与您在Form.中发送客户端ID有关

如果使用TryGetFormCredentials而不是TryGetBasicCredentials,则会得到结果。

但是,您希望使用TryGetBasicCredentials在请求标头中发送您的客户端ID。Seeehttps://en.wikipedia.org/wiki/Basic_access_authentication#Client_side