I\'m following this interactive login example from Paypal\'s site.
public ActionResult PaypalResponse(string scope, string code)
{
Dictionary&l
updated based on @pollirrata answer, and this is how it worked for me. Hope it will help someone.
//code is what you get from LoginWithPayPal login page in return (query string)
public .... GetRefreshAccessToken(string code)
{
var oAuthClientId = "clientid from paypal developer site";
var oAuthClientSecret = "client secret from paypal developer site";
var oAuthUrl = "https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice";
var authHeader = string.Format("Basic {0}",
Convert.ToBase64String(
Encoding.UTF8.GetBytes(Uri.EscapeDataString(oAuthClientId) + ":" +
Uri.EscapeDataString((oAuthClientSecret)))
));
//passing code here
var postBody = string.Format("grant_type=authorization_code&code={0}", code);
var authRequest = (HttpWebRequest)WebRequest.Create(oAuthUrl);
authRequest.Headers.Add("Authorization", authHeader);
authRequest.Method = "POST";
byte[] postcontentsArray = Encoding.UTF8.GetBytes(postBody);
authRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
authRequest.ContentLength = postcontentsArray.Length;
try
{
using (Stream stream = authRequest.GetRequestStream())
{
stream.Write(postcontentsArray, 0, postcontentsArray.Length);
stream.Close();
WebResponse response = authRequest.GetResponse();
using (Stream responseStream = response.GetResponseStream())
if (responseStream != null)
{
using (var reader = new StreamReader(responseStream))
{
string responseFromServer = reader.ReadToEnd();
reader.Close();
responseStream.Close();
response.Close();
//this will return you access token which you can use to get user information
var responseResult =
JsonConvert.DeserializeObject(responseFromServer);
}
}
}
}
catch (Exception e)
{
//log error
}
}
After this you can call GET method with new token for user information, uri: https://api.sandbox.paypal.com/v1/identity/openidconnect/userinfo/?schema=openid
Refer to: https://developer.paypal.com/webapps/developer/docs/integration/direct/identity/log-in-with-paypal/