|
@@ -0,0 +1,44 @@
|
|
|
+from SampleApp import config
|
|
|
+import requests
|
|
|
+
|
|
|
+authorization_url = config.OpenID_SERVER + config.OpenID_AUTHORIZATION_URL
|
|
|
+token_url = config.OpenID_SERVER + config.OpenID_TOKEN_URL
|
|
|
+userinfo_url = config.OpenID_SERVER + config.OpenID_RESOURCE_URL
|
|
|
+
|
|
|
+class OpenID_CLIENT(object):
|
|
|
+ """docstring for OpenID_CLIENT"""
|
|
|
+ def __init__(self, *arg):
|
|
|
+ super(OpenID_CLIENT, self).__init__()
|
|
|
+
|
|
|
+ # def get_code(self):
|
|
|
+ # auth_url = authorization_url + "?client_id="+ config.OpenID_CLIENT_ID+"&response_type=code&redirect_uri="+config.OpenID_CALLBACK_URL
|
|
|
+ # response = requests.get(auth_url)
|
|
|
+ # import pdb;pdb.set_trace()
|
|
|
+ # return code
|
|
|
+
|
|
|
+ def get_access_token(self, code):
|
|
|
+ request_data = {
|
|
|
+ 'client_id' : config.OpenID_CLIENT_ID,
|
|
|
+ 'client_secret' : config.OpenID_CLIENT_SECRET,
|
|
|
+ 'redirect_uri' : config.OpenID_CALLBACK_URL,
|
|
|
+ 'grant_type' : 'authorization_code',
|
|
|
+ 'code' : code
|
|
|
+ }
|
|
|
+ response = requests.post(token_url, data = request_data)
|
|
|
+ return response.json()
|
|
|
+
|
|
|
+ def get_refresh_token(self, refresh_token):
|
|
|
+ request_data = {
|
|
|
+ 'client_id' : config.OpenID_CLIENT_ID,
|
|
|
+ 'client_secret' : config.OpenID_CLIENT_SECRET,
|
|
|
+ 'redirect_uri' : config.OpenID_CALLBACK_URL,
|
|
|
+ 'grant_type' : 'authorization_code',
|
|
|
+ 'refresh_token' : refresh_token
|
|
|
+ }
|
|
|
+ response = requests.post(token_url, data = request_data)
|
|
|
+ return response.json()
|
|
|
+
|
|
|
+
|
|
|
+ def get_userinfo(self, access_token):
|
|
|
+ response = requests.get(userinfo_url+"?access_token=%s"%access_token)
|
|
|
+ return response
|