显示 OAuth 2 新令牌(仅用于测试)

问题描述 投票:0回答:1

我有这个代码似乎可以工作(没有错误),但我希望能够以某种方式显示新令牌(Console.WriteLine 等)

private static bool CertificateValidationCallBack(HttpRequestMessage arg1, X509Certificate2 arg2, X509Chain arg3, SslPolicyErrors arg4)
            {
                throw new NotImplementedException();
            }

            private static async Task<Token> GetElibilityToken(HttpClient client)
            {
                
                string baseAddress = @"https://label.xxxx.dot.net/myToken/api/auth/token";

                string grant_type = "password";
                string client_id = "goldline";
                string Username = "xyz";
                string client_secret = "myPassword";

                var form = new Dictionary<string, string>
                {
                    {"grant_type", grant_type},
                    {"client_id", client_id},
                    {"Username" , Username },
                    {"client_secret", client_secret},
                };
                {

                    HttpResponseMessage tokenResponse = await client.PostAsync(baseAddress, new FormUrlEncodedContent(form));
                    var jsonContent = await tokenResponse.Content.ReadAsStringAsync();
                    Token tok = JsonConvert.DeserializeObject<Token>(jsonContent);
                    return tok;

c# oauth-2.0 access-token
1个回答
0
投票

如果这是应用程序的一部分,您可以添加

Trace.TraceInformation($"GetElibilityToken: the token being returned is {jsonContent}")
并检查日志记录。

或者您可以在 Linqpad 中重新创建此代码片段,设置您自己的 HttpClient 并使用您在

form
对象中设置的正确凭据发送该调用。然后转储()结果。

© www.soinside.com 2019 - 2024. All rights reserved.