首页 > 解决方案 > 如何使用 Identity Server 4 撤销或使令牌无效?

问题描述

我读了这个文档:http ://docs.identityserver.io/en/release/endpoints/revocation.html

然后我试试这段代码:

AuthHelper.cs

public class AuthHelper
{
    private string URL = "http://localhost:50847/connect/revocation";


    public bool revocarToken(string token)
    {
        try
        {
            HttpClient client = new HttpClient();
            string uri = URL;
            StringContent contenido = new StringContent("token="+token+"&token_type_hint=access_token", System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");
            HttpResponseMessage response = client.PostAsync(uri, contenido).Result;

            if (response.IsSuccessStatusCode)
                return true;
            return false;
        }
        catch (Exception ex)
        {
            throw;
        }
    }
}

但是,我得到这个错误:

在此处输入图像描述

我收到错误 400(错误请求)。提前致谢。

标签: c#asp.net-coreidentityserver4

解决方案


您没有将所需的凭据发送到吊销端点。IdentityServer 希望您提供客户端 ID 和密码。请阅读https://www.rfc-editor.org/rfc/rfc7009#section-2.1规范以更好地理解。

我建议您使用IdentityModel2包来发出撤销请求(以及其他与 OIDC 相关的请求)。


推荐阅读