|
|
@@ -96,6 +96,8 @@ class PaypalOauthClient(object):
|
|
|
This methods obtain new access token when current access_token expires.
|
|
|
'''
|
|
|
|
|
|
+ link = 'https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice'
|
|
|
+
|
|
|
headers = {
|
|
|
'Accept': 'application/json',
|
|
|
'Accept-Language': 'en_US',
|
|
|
@@ -104,7 +106,7 @@ class PaypalOauthClient(object):
|
|
|
data = { 'grant_type': 'refresh_token',
|
|
|
'refresh_token': refresh_token}
|
|
|
|
|
|
- req = requests.post(access_token_url, data=data, headers=headers, auth=(self.client_id, self.client_secret))
|
|
|
+ req = requests.post(link, data=data, headers=headers, auth=(self.client_id, self.client_secret))
|
|
|
|
|
|
if req.status_code != 200:
|
|
|
raise Exception("Invalid response %s." % req.status_code)
|
|
|
@@ -112,28 +114,20 @@ class PaypalOauthClient(object):
|
|
|
content = unicodedata.normalize('NFKD', req.text).encode('ascii','ignore')
|
|
|
jsonlist = json2.loads(content)
|
|
|
|
|
|
- print jsonlist
|
|
|
+ #print jsonlist
|
|
|
self.access_token = jsonlist['access_token']
|
|
|
self.token_type = jsonlist['token_type']
|
|
|
return self.access_token
|
|
|
|
|
|
|
|
|
+ def userinfo(self):
|
|
|
+ link = 'https://api.sandbox.paypal.com/v1/identity/openidconnect/userinfo/?schema=openid'
|
|
|
+ headers = { 'Content-Type':'application/json',
|
|
|
+ 'Authorization': self.token_type + ' '+ self.access_token,
|
|
|
+ 'Accept-Language': 'en_US',
|
|
|
+ 'content-type': 'application/x-www-form-urlencoded'
|
|
|
+ }
|
|
|
+ req = requests.get(link, headers=headers)
|
|
|
+ #print req.content
|
|
|
|
|
|
-
|
|
|
- def test(self):
|
|
|
- #link ='https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/identity/openidconnect/userinfo' #/?schema=openid'
|
|
|
- link = 'https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice'
|
|
|
- header = { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type':'application/json'}
|
|
|
- body = { 'schema':'openid', 'access_token': self.access_token}
|
|
|
-
|
|
|
- #req = requests.post(link, headers={'Content-Type':'application/json', 'Authorization': self.token_type+' '+self.access_token})
|
|
|
- req = requests.post(link, headers=header, data=body)
|
|
|
-
|
|
|
- if req.status_code != 200:
|
|
|
- raise Exception("Invalid response %s." % req.status_code)
|
|
|
-
|
|
|
- content = unicodedata.normalize('NFKD', req.text).encode('ascii','ignore')
|
|
|
- print content
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|