|
def authenticate(self,hostname, client_id, client_secret, username, password): |
|
uri_path = '/oauth/token' |
|
headers = {'Content-Type':'application/x-www-form-urlencoded'} |
|
params = {'grant_type':'password', 'client_id':client_id, 'client_secret':client_secret, |
|
'username':username, 'password':password} |
|
|
|
http = httplib.HTTPSConnection(hostname) |
|
http.request('POST', uri_path, urllib.parse.urlencode(params), headers=headers) |
|
response = http.getresponse() |
|
|
|
token = None |
|
if response.status == 200: |
|
token = json.loads(response.read()) |
|
|
|
http.close() |
|
return token |
|
|
|
def get_authorization_header(self,token): |
|
return {'Authorization':'Bearer %s'%(token['access_token'])} |
|
|
|
def get_hostname(self,token): |
|
return '%s.sf-api.com'%(token['subdomain']) |
|
|
|
def get_config_data(self): |
|
# If you are using any other framework or just python you can set values of this variable directly or create new file for config. |
|
|
|
hostname = "myaccount.sharefile.com" |
|
username = "[email protected]" |
|
password = "mypassword" |
|
client_id = 'myclientid' |
|
client_secret = 'myclientsecret' |
|
|
|
# For Odoo |
|
config_obj = self.env['ir.config_parameter'] |
|
hostname = config_obj.sudo().get_param('sharefile.sharefile_hostname') |
|
username = config_obj.sudo().get_param('sharefile.sharefile_username') |
|
password = config_obj.sudo().get_param('sharefile.sharefile_password') |
|
client_id = config_obj.sudo().get_param('sharefile.sharefile_client_id') |
|
client_secret = config_obj.sudo().get_param('sharefile.sharefile_client_secret') |
|
|
|
return hostname, username, password, client_id, client_secret |