首页 > 解决方案 > 使用 RestClient 从 Google Cloud OAuth 提供程序检索访问令牌

问题描述

我一直在尝试使用 RestClient 使用下面的代码(我已经替换了 clientid 和密钥)从 Google Cloud OAuth 中检索访问令牌,但在花费了很多小时后没有运气。由于某些原因,我无法使用 Google 库。在 Google 云中,我在创建 OAuth Api 时创建了桌面应用程序类型。

            var client = new RestClient("https://accounts.google.com/o/oauth2/auth");
            var request = new RestRequest(Method.POST);
            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("content-type", "application/x-www-form-urlencoded");
            request.AddParameter("application/x-www-form-urlencoded", "client_id=[123].apps.googleusercontent.com&client_secret=[xyz]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

我收到授权错误,400:invalid_request

请指导我在这里做错了什么......

标签: c#authenticationoauth-2.0

解决方案


推荐阅读