Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) </br>
[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
Expand Down
11 changes: 7 additions & 4 deletions webdav/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
13 changes: 8 additions & 5 deletions webdav/connection.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

from webdav.exceptions import *
from webdav.urn import Urn
from os.path import exists


class ConnectionSettings:

def is_valid(self):
Expand All @@ -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):

Expand Down Expand Up @@ -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'}
Expand Down