mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +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() {
|
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
|
_davserver $DAV_SERVER
|
||||||
if [ "$TRAVIS" = "true" ]; then
|
if [ "$TRAVIS" = "true" ]; then
|
||||||
export CFLAGS=-O0 # speed up builds of packages which don't have wheels
|
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]
|
[storage bob_contacts_remote]
|
||||||
type = carddav
|
type = carddav
|
||||||
url = https://owncloud.example.com/remote.php/carddav/addressbooks/bob/
|
url = https://owncloud.example.com/remote.php/carddav/addressbooks/bob/
|
||||||
# There are two different authentication types: `basic` or `digest`
|
# Auth types. If you know yours, set it explicitly for performance.
|
||||||
#auth = basic
|
# - basic
|
||||||
# For http auth, if empty, no auth will be used
|
# - digest
|
||||||
|
# - guess (default)
|
||||||
|
#auth = guess
|
||||||
#username =
|
#username =
|
||||||
# The password can also be fetched from the system password storage or netrc
|
# The password can also be fetched from the system password storage or netrc
|
||||||
#password =
|
#password =
|
||||||
|
|
@ -85,7 +87,7 @@ fileext = .ics
|
||||||
[storage bob_calendar_remote]
|
[storage bob_calendar_remote]
|
||||||
type = caldav
|
type = caldav
|
||||||
url = https://owncloud.example.com/remote.php/caldav/calendars/bob/
|
url = https://owncloud.example.com/remote.php/caldav/calendars/bob/
|
||||||
#auth = basic
|
#auth = guess
|
||||||
#username =
|
#username =
|
||||||
#password =
|
#password =
|
||||||
#verify = True
|
#verify = True
|
||||||
|
|
|
||||||
|
|
@ -66,8 +66,7 @@ def do_the_radicale_dance(tmpdir):
|
||||||
import radicale.auth.http
|
import radicale.auth.http
|
||||||
|
|
||||||
def is_authenticated(user, password):
|
def is_authenticated(user, password):
|
||||||
assert user == 'bob' and password == 'bob'
|
return user == 'bob' and password == 'bob'
|
||||||
return True
|
|
||||||
radicale.auth.http.is_authenticated = is_authenticated
|
radicale.auth.http.is_authenticated = is_authenticated
|
||||||
|
|
||||||
if storage_backend == 'filesystem':
|
if storage_backend == 'filesystem':
|
||||||
|
|
|
||||||
|
|
@ -16,17 +16,25 @@ USERAGENT = 'vdirsyncer'
|
||||||
|
|
||||||
|
|
||||||
def prepare_auth(auth, username, password):
|
def prepare_auth(auth, username, password):
|
||||||
|
if username and password:
|
||||||
if auth == 'basic':
|
if auth == 'basic':
|
||||||
return (username, password)
|
return (username, password)
|
||||||
elif auth == 'digest':
|
elif auth == 'digest':
|
||||||
from requests.auth import HTTPDigestAuth
|
from requests.auth import HTTPDigestAuth
|
||||||
return HTTPDigestAuth(username, password)
|
return HTTPDigestAuth(username, password)
|
||||||
elif auth is None:
|
elif auth == 'guess' or auth is None:
|
||||||
if username and password:
|
import requests_toolbelt
|
||||||
return (username, password)
|
if not hasattr(requests_toolbelt, 'GuessAuth'):
|
||||||
return None
|
raise RuntimeError('Your version of requests_toolbelt is too '
|
||||||
|
'old.')
|
||||||
|
return requests_toolbelt.GuessAuth(username, password)
|
||||||
else:
|
else:
|
||||||
raise ValueError('Unknown authentication method: {}'.format(auth))
|
raise ValueError('Unknown authentication method: {}'.format(auth))
|
||||||
|
elif auth:
|
||||||
|
raise ValueError('For {} authentication, you need to specify username '
|
||||||
|
'and password.'.format(auth))
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def prepare_verify(verify):
|
def prepare_verify(verify):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue