Add Oauth2 Bearer Token support
Basic implementation of authenticating with token instead of basic auth, as the auth=(login,password) flag on requests sends junk authentication as it overrides the bearer authentication header with a base64 encoded blank string.
This commit is contained in:
		
							parent
							
								
									f64efedd96
								
							
						
					
					
						commit
						3c5ba516af
					
				
					 1 changed files with 22 additions and 11 deletions
				
			
		|  | @ -177,7 +177,7 @@ class Client(object): | |||
|             headers.extend(headers_ext) | ||||
| 
 | ||||
|         if self.webdav.token: | ||||
|             webdav_token = "Authorization: OAuth {token}".format(token=self.webdav.token) | ||||
|             webdav_token = "Authorization: Bearer {token}".format(token=self.webdav.token) | ||||
|             headers.append(webdav_token) | ||||
|         return dict([map(lambda s: s.strip(), i.split(':', 1)) for i in headers]) | ||||
| 
 | ||||
|  | @ -211,6 +211,17 @@ class Client(object): | |||
|         """ | ||||
|         if self.session.auth: | ||||
|             self.session.request(method="GET", url=self.webdav.hostname, verify=self.verify)  # (Re)Authenticates against the proxy | ||||
|         if all([self.webdav.login, self.webdav.password]) is False: | ||||
|             response = self.session.request( | ||||
|                 method=self.requests[action], | ||||
|                 url=self.get_url(path), | ||||
|                 headers=self.get_headers(action, headers_ext), | ||||
|                 timeout=self.timeout, | ||||
|                 data=data, | ||||
|                 stream=True, | ||||
|                 verify=self.verify | ||||
|             ) | ||||
|         else: | ||||
|             response = self.session.request( | ||||
|                 method=self.requests[action], | ||||
|                 url=self.get_url(path), | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue