From 21721c42e1fdbff8d1196bd4dfe7933bf6ddbff0 Mon Sep 17 00:00:00 2001 From: Berkay TURK Date: Fri, 21 Feb 2020 15:56:16 +0100 Subject: [PATCH 1/2] OAuth 2.0 Authentication with Bearer(JWT) Token has been implemented. --- README.md | 16 ++++++++++++++++ webdav/client.py | 11 +++++++---- webdav/connection.py | 13 ++++++++----- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6e22283..8ce4ef4 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,22 @@ options = { client = wc.Client(options) ``` +If you want to use 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'} From 307815c833b96d4dd990af9c817c7149b9158230 Mon Sep 17 00:00:00 2001 From: Berkay TURK Date: Mon, 24 Feb 2020 09:17:16 +0100 Subject: [PATCH 2/2] Updated Readme.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8ce4ef4..02a2fc9 100644 --- a/README.md +++ b/README.md @@ -89,10 +89,10 @@ options = { client = wc.Client(options) ``` -If you want to use authorize the application with JWT Beare token or OAuth token: +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 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