簡體   English   中英

從.NET 4.5訪問IdentityServer4內省

[英]Accessing IdentityServer4 Introspection from .NET 4.5

我正在嘗試從較舊的客戶端應用程序訪問Id4服務器。 我可以得到一個令牌,但是當我嘗試驗證令牌時,調用client.SendAsync時出現415 - 'Unsupported Media Type' client.SendAsync 415 - 'Unsupported Media Type'錯誤。 關於我缺少什么設置的任何想法? 這些值適用於郵遞員。

public bool IsTokenValid(string token)
    {
        bool isTokenValid = false;

        HttpClient client = new HttpClient();

        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));            
        client.DefaultRequestHeaders.Add("Authorization", "Basic UHJvZml0U2FnZUFwaTpnR2VTZ0luRW9r");

        HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, _url + "/connect/introspect");
        request.Content = new StringContent("token=" + token);

        try
        {
            HttpResponseMessage response = client.SendAsync(request).Result; 
        }
        catch (Exception ex)
        {               
            Error = ex;
        }

        client.Dispose();

        return isTokenValid;

    }

嘗試添加值為“ application / x-www-form-urlencoded”或“ multipart / form-data”的“ Content-Type”標頭,我認為這應該可以解決您的問題。

這是因為當請求沒有表單內容類型時,內省端點將返回不受支持的媒體類型響應代碼: https : //github.com/IdentityServer/IdentityServer4/blob/63a50d7838af25896fbf836ea4e4f37b5e179cd8/src/Endpoints/IntrospectionEndpoint.cs

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM