def set_client_certificate(self, certificate_path): """ Add a client certificate to use for authentication. Parameters ---------- certificate_path : str path to the file of the client certificate """ cert_session = create_session() cert_session.cert = certificate_path self.set(securitymethods.CLIENT_CERTIFICATE, cert_session)
def set_cookie_jar(self, cookie_jar): """ Set the cookie jar to use for authentication. Any previous cookies or cookie jars set will be removed. Parameters ---------- cookie_jar : obj the cookie jar to use. """ cookie_session = self.credentials.setdefault(securitymethods.COOKIE, create_session()) cookie_session.cookies = cookie_jar
def set_password(self, username, password): """ Add a username / password for basic authentication. Parameters ---------- username : str username to use password : str password to use """ basic_session = create_session() basic_session.auth = (username, password) self.set(securitymethods.BASIC, basic_session)
def set_cookie(self, cookie_name, cookie_value, domain='', path='/'): """ Add a cookie to use as authentication. More than one call to set_cookie will add multiple cookies into the same cookie jar used for the request. Parameters ---------- cookie_name : str name of the cookie cookie_value : str value of the cookie domain : str restrict usage of this cookie to this domain path : str restrict usage of this cookie to this path """ cookie_session = self.credentials.setdefault(securitymethods.COOKIE, create_session()) cookie_session.cookies.set(cookie_name, cookie_value, domain=domain, path=path)
def __init__(self): self.credentials = {} self.set(securitymethods.ANONYMOUS, create_session())