gpt4 book ai didi

authentication - Paypal OAuth 登录示例未按预期工作

转载 作者:太空宇宙 更新时间:2023-11-03 15:49:12 25 4
gpt4 key购买 nike

我正在关注 this interactive login example来自 Paypal 的网站。

  public ActionResult PaypalResponse(string scope, string code)
{
Dictionary<string, string> configurationMap = new Dictionary<string, string>();
configurationMap.Add("mode", "sandbox");

APIContext apiContext = new APIContext();
apiContext.Config = configurationMap;

CreateFromAuthorizationCodeParameters param = new CreateFromAuthorizationCodeParameters();
param.setClientId(clientId);
param.setClientSecret(clientSecret);
param.SetCode(code);

// Exception here:
Tokeninfo info = Tokeninfo.CreateFromAuthorizationCode(apiContext, param);

return null;
}

方法 CreateFromAuthorizationCode 导致此(不正确)调用。注意 client ID 和 client secret 是如何丢失的

POST https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice HTTP/1.1
Content-Type: application/x-www-form-urlencoded
User-Agent: PayPalSDK/ ;lang=DOTNET;v=4.0.30319.18051;bit=64;os=Microsoft Windows 8 Enterprise 6.2.9200.0;
Host: api.sandbox.paypal.com
Content-Length: 211
Expect: 100-continue
Connection: Keep-Alive

grant_type=authorization_code&code=d2mSEzm9xvE_l9Ibho0g6FNBVrC7wHZchJWqJfY...redacted...

Fiddler 的输出是

HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
Cache-Control: no-store
Pragma: no-cache
Content-Type: application/json
Vary: Accept-Encoding
Content-Length: 76
DC: origin1-api.sandbox.paypal.com
Date: Mon, 14 Oct 2013 01:30:05 GMT
Connection: close
Set-Cookie: DC=origin1-api.sandbox.paypal.com; secure

{"error_description":"client id or secret is null","error":"invalid_client"}

最佳答案

我遇到了完全相同的问题,并通过更改调用方法解决了

string postcontents = string.Format("client_id={0}&client_secret={1}&grant_type=authorization_code&redirect_uri={2}&code={3}"
, System.Web.HttpUtility.UrlEncode(clientId)
, System.Web.HttpUtility.UrlEncode(secret)
, System.Web.HttpUtility.UrlEncode(url)
, System.Web.HttpUtility.UrlEncode(code));


HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice");
request.Credentials = new NetworkCredential(clientId, secret);
request.Method = "POST";
byte[] postcontentsArray = System.Text.Encoding.UTF8.GetBytes(postcontents);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postcontentsArray.Length;
//OAuth.
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(postcontentsArray, 0, postcontentsArray.Length);
requestStream.Close();
WebResponse response = request.GetResponse();
using (Stream responseStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
{
string responseFromServer = reader.ReadToEnd();
reader.Close();
responseStream.Close();
response.Close();
// return SerializeToken(responseFromServer);
dynamic dynObj = JsonConvert.DeserializeObject(responseFromServer);
string token = dynObj["access_token"];
//token = ser.Deserialize<ImportContacts._Default.GoogleOAuthToken>(responseFromServer);
}
}

希望对你有帮助

关于authentication - Paypal OAuth 登录示例未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19352330/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com