Skip to content

Instantly share code, notes, and snippets.

@DhruvaDave
Last active December 19, 2020 13:53
Show Gist options
  • Save DhruvaDave/c7a840d04ec8253faf052b80df7cff28 to your computer and use it in GitHub Desktop.
Save DhruvaDave/c7a840d04ec8253faf052b80df7cff28 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment