伐木问题 - 销售人员C#

发布于 2025-01-28 05:33:33 字数 1491 浏览 4 评论 0原文

这是代码片段 错误:{“ error”:“ invalid_client_id”,“ error_description”:“客户端标识符无效”} 连接通过正确的客户端,客户端,用户名,密码 传递安全风口空的

运气我们无需SecurityToken即可连接

    public void Login()
    {
        String jsonResponse;
        try
        {
            using (var client = new HttpClient())
            {
                var request = new FormUrlEncodedContent(new Dictionary<string, string>
                {
                    { "grant_type","password"},
                    { "client_id", ClientId},
                    { "client_secret", ClientSecret},
                    { "username", Username},
                    { "password", Password + Token}

                });
                request.Headers.Add("X-PreetyPrint", "1");
                var response = client.PostAsync(LOGIN_ENDPOINT, 
                                 request).Result;//client.SendAsync(request);//
                jsonResponse = response.Content.ReadAsStringAsync().Result;// 
                                 Content.ReadAsStringAsync();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }


        var values = JsonConvert.DeserializeObject<Dictionary<string, string>> 
                     (jsonResponse);
        AuthToken = values["access_token"];
        InstanceUrl = values["instance_url"];
        Console.WriteLine("Auth Token = " + AuthToken);
        Console.WriteLine("Instance Url = " + InstanceUrl);

    }

Here is the code snippet
Error: {"error":"invalid_client_id","error_description":"client identifier invalid"}
connecting passing correct clientid, clientsecret, username, password
passing securityToken empty

Any luck can we connect without securityToken

    public void Login()
    {
        String jsonResponse;
        try
        {
            using (var client = new HttpClient())
            {
                var request = new FormUrlEncodedContent(new Dictionary<string, string>
                {
                    { "grant_type","password"},
                    { "client_id", ClientId},
                    { "client_secret", ClientSecret},
                    { "username", Username},
                    { "password", Password + Token}

                });
                request.Headers.Add("X-PreetyPrint", "1");
                var response = client.PostAsync(LOGIN_ENDPOINT, 
                                 request).Result;//client.SendAsync(request);//
                jsonResponse = response.Content.ReadAsStringAsync().Result;// 
                                 Content.ReadAsStringAsync();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }


        var values = JsonConvert.DeserializeObject<Dictionary<string, string>> 
                     (jsonResponse);
        AuthToken = values["access_token"];
        InstanceUrl = values["instance_url"];
        Console.WriteLine("Auth Token = " + AuthToken);
        Console.WriteLine("Instance Url = " + InstanceUrl);

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪意 2025-02-04 05:33:33

要登录而无需安全令牌,您需要在受信任的网络上。例如,如果您的Office / VPN /应用程序服务器具有静态IP-您的Salesforce管理员可以将其添加到设置中 - &gt;网络访问。更多信息: https://https://help.salesforce.com/sarticleview.com/sarticleview ?

​密码。阅读有关JWT和(无耻的插件): https://stackoverflow.com/a/a/72119994/313628 href =“ https://stackoverflow.com/a/63897503/313628”> https://stackoverflow.com/a/63897503/313628

To login without security token you need to be on trusted network. For example if your office / VPN / application server has static IP - your Salesforce admin can add it to Setup -> Network Access. More info: https://help.salesforce.com/s/articleView?id=000333031&type=1

If the IP is not static and this has to be done completely server-side (withotu human logging in in the browser and authorising your app)... you could try to login without password. Read up about JWT and (shameless plug): https://stackoverflow.com/a/72119994/313628, https://stackoverflow.com/a/63897503/313628

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文