mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
Add GuessAuth to authentication methods
This commit is contained in:
parent
b23298ff71
commit
c66a074f36
4 changed files with 30 additions and 16 deletions
7
build.sh
7
build.sh
|
|
@ -12,7 +12,12 @@ _davserver() {
|
|||
}
|
||||
|
||||
install_build_tests() {
|
||||
$PIP_INSTALL coverage pytest pytest-xprocess git+https://github.com/geier/leif
|
||||
$PIP_INSTALL \
|
||||
coverage \
|
||||
pytest \
|
||||
pytest-xprocess \
|
||||
git+https://github.com/geier/leif \
|
||||
git+https://github.com/sigmavirus24/requests-toolbelt
|
||||
_davserver $DAV_SERVER
|
||||
if [ "$TRAVIS" = "true" ]; then
|
||||
export CFLAGS=-O0 # speed up builds of packages which don't have wheels
|
||||
|
|
|
|||
10
example.cfg
10
example.cfg
|
|
@ -57,9 +57,11 @@ fileext = .vcf
|
|||
[storage bob_contacts_remote]
|
||||
type = carddav
|
||||
url = https://owncloud.example.com/remote.php/carddav/addressbooks/bob/
|
||||
# There are two different authentication types: `basic` or `digest`
|
||||
#auth = basic
|
||||
# For http auth, if empty, no auth will be used
|
||||
# Auth types. If you know yours, set it explicitly for performance.
|
||||
# - basic
|
||||
# - digest
|
||||
# - guess (default)
|
||||
#auth = guess
|
||||
#username =
|
||||
# The password can also be fetched from the system password storage or netrc
|
||||
#password =
|
||||
|
|
@ -85,7 +87,7 @@ fileext = .ics
|
|||
[storage bob_calendar_remote]
|
||||
type = caldav
|
||||
url = https://owncloud.example.com/remote.php/caldav/calendars/bob/
|
||||
#auth = basic
|
||||
#auth = guess
|
||||
#username =
|
||||
#password =
|
||||
#verify = True
|
||||
|
|
|
|||
|
|
@ -66,8 +66,7 @@ def do_the_radicale_dance(tmpdir):
|
|||
import radicale.auth.http
|
||||
|
||||
def is_authenticated(user, password):
|
||||
assert user == 'bob' and password == 'bob'
|
||||
return True
|
||||
return user == 'bob' and password == 'bob'
|
||||
radicale.auth.http.is_authenticated = is_authenticated
|
||||
|
||||
if storage_backend == 'filesystem':
|
||||
|
|
|
|||
|
|
@ -16,17 +16,25 @@ USERAGENT = 'vdirsyncer'
|
|||
|
||||
|
||||
def prepare_auth(auth, username, password):
|
||||
if auth == 'basic':
|
||||
return (username, password)
|
||||
elif auth == 'digest':
|
||||
from requests.auth import HTTPDigestAuth
|
||||
return HTTPDigestAuth(username, password)
|
||||
elif auth is None:
|
||||
if username and password:
|
||||
if username and password:
|
||||
if auth == 'basic':
|
||||
return (username, password)
|
||||
return None
|
||||
elif auth == 'digest':
|
||||
from requests.auth import HTTPDigestAuth
|
||||
return HTTPDigestAuth(username, password)
|
||||
elif auth == 'guess' or auth is None:
|
||||
import requests_toolbelt
|
||||
if not hasattr(requests_toolbelt, 'GuessAuth'):
|
||||
raise RuntimeError('Your version of requests_toolbelt is too '
|
||||
'old.')
|
||||
return requests_toolbelt.GuessAuth(username, password)
|
||||
else:
|
||||
raise ValueError('Unknown authentication method: {}'.format(auth))
|
||||
elif auth:
|
||||
raise ValueError('For {} authentication, you need to specify username '
|
||||
'and password.'.format(auth))
|
||||
else:
|
||||
raise ValueError('Unknown authentication method: {}'.format(auth))
|
||||
return None
|
||||
|
||||
|
||||
def prepare_verify(verify):
|
||||
|
|
|
|||
Loading…
Reference in a new issue