diff --git a/README.md b/README.md index 6e22283..02a2fc9 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,22 @@ options = { client = wc.Client(options) ``` +If you want to authorize the application with JWT Beare token or OAuth token: +You can only give the token according to which version of OAuth you work on and the http header will be generated automatically. + +[The OAuth 1.0 Authorization Framework: OAuth Token Usage](https://oauth.net/core/1.0/#auth_header)
+[The OAuth 2.0 Authorization Framework: Bearer Token Usage](https://tools.ietf.org/html/rfc6750#section-2.1) + +```python +import webdav.client as wc +options = { + 'webdav_hostname': "https://webdav.server.ru", + 'webdav_bearertoken': "bearertoken", + 'webdav_oauthtoken' : "oauthtoken" +} +client = wc.Client(options) +``` + Or you want to limit the speed or turn on verbose mode: ```python diff --git a/webdav/client.py b/webdav/client.py index a331928..9f82221 100644 --- a/webdav/client.py +++ b/webdav/client.py @@ -87,9 +87,12 @@ def get_header(self, method): else: header = list() - if self.webdav.token: - webdav_token = "Authorization: OAuth {token}".format(token=self.webdav.token) - header.append(webdav_token) + if self.webdav.bearertoken: + webdav_bearertoken = "Authorization: Bearer {token}".format(token=self.webdav.bearertoken) + header.append(webdav_bearertoken) + if self.webdav.oauthtoken: + webdav_oauthtoken = "Authorization: OAuth {token}".format(token=self.webdav.oauthtoken) + header.append(webdav_oauthtoken) return header @@ -141,7 +144,7 @@ def Request(self, options=None): 'SSLVERSION': pycurl.SSLVERSION_TLSv1, }) - if not self.webdav.token: + if not self.webdav.oauthtoken: server_token = '{login}:{password}'.format(login=self.webdav.login, password=self.webdav.password) self.default_options.update({ 'USERPWD': server_token, diff --git a/webdav/connection.py b/webdav/connection.py index d7cca2a..d0fbf05 100644 --- a/webdav/connection.py +++ b/webdav/connection.py @@ -1,8 +1,8 @@ - from webdav.exceptions import * from webdav.urn import Urn from os.path import exists + class ConnectionSettings: def is_valid(self): @@ -17,11 +17,12 @@ def valid(self): else: return True -class WebDAVSettings(ConnectionSettings): +class WebDAVSettings(ConnectionSettings): ns = "webdav:" prefix = "webdav_" - keys = {'hostname', 'login', 'password', 'token', 'root', 'cert_path', 'key_path', 'recv_speed', 'send_speed', 'verbose'} + keys = {'hostname', 'login', 'password', 'bearertoken', 'oauthtoken', 'root', 'cert_path', 'key_path', 'recv_speed', + 'send_speed', 'verbose'} def __init__(self, options): @@ -52,12 +53,14 @@ def is_valid(self): if self.password and not self.login: raise OptionNotValid(name="login", value=self.login, ns=self.ns) - if not self.token and not self.login: + if not self.bearertoken and not self.login: raise OptionNotValid(name="login", value=self.login, ns=self.ns) + if not self.oauthtoken and not self.login: + raise OptionNotValid(name="login", value=self.login, ns=self.ns) -class ProxySettings(ConnectionSettings): +class ProxySettings(ConnectionSettings): ns = "proxy:" prefix = "proxy_" keys = {'hostname', 'login', 'password'}