Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(10)  |  Call(5)  |  Derive(0)  |  Import(5)
Check Authentication

If an authorization header contains credentials, return True, else False.

:param realm: The authentication realm.
:type  realm: str

:param users: A dict of the form: {username: password} or a callable
              returning a dict.
:type  users: dict or callable(more...)

        def check_auth(request, response, realm, users, encrypt=None):
    """Check Authentication

    If an authorization header contains credentials, return True, else False.

    :param realm: The authentication realm.
    :type  realm: str

    :param users: A dict of the form: {username: password} or a callable
                  returning a dict.
    :type  users: dict or callable

    :param encrypt: Callable used to encrypt the password returned from
                    the user-agent. if None it defaults to a md5 encryption.
    :type  encrypt: callable
    """

    if 'authorization' in request.headers:
        # make sure the provided credentials are correctly set
        ah = _httpauth.parseAuthorization(request.headers['authorization'])
        if ah is None:
            return HTTPError(request, response, 400)

        if not encrypt:
            encrypt = _httpauth.DIGEST_AUTH_ENCODERS[_httpauth.MD5]

        if isinstance(users, collections.Callable):
            try:
                # backward compatibility
                users = users()  # expect it to return a dictionary

                if not isinstance(users, dict):
                    raise ValueError("Authentication users must be a dict")

                # fetch the user password
                password = users.get(ah["username"], None)
            except TypeError:
                # returns a password (encrypted or clear text)
                password = users(ah["username"])
        else:
            if not isinstance(users, dict):
                raise ValueError("Authentication users must be a dict")

            # fetch the user password
            password = users.get(ah["username"], None)

        # validate the authorization by re-computing it here
        # and compare it with what the user-agent provided
        if _httpauth.checkResponse(ah, password, method=request.method,
                                   encrypt=encrypt, realm=realm):
            request.login = ah["username"]
            return True

        request.login = False
    return False
        


src/c/i/circuits-3.0.0.dev/examples/web/httpauth.py   circuits(Download)
#!/usr/bin/env python
 
from circuits.web import Server, Controller
from circuits.web.tools import check_auth, basic_auth
 
        encrypt = str
 
        if check_auth(self.request, self.response, realm, users, encrypt):
            return "Hello %s" % self.request.login
 

src/c/i/circuits-3.0.0.dev/examples/web/authdemo.py   circuits(Download)
from circuits import handler, Component
from circuits.web import Server, Controller
from circuits.web.tools import check_auth, basic_auth
 
 
        """
 
        if not check_auth(request, response, self.realm, self.users):
            return basic_auth(request, response, self.realm, self.users)
 

src/s/a/sahriswiki-0.8.1/sahriswiki/root.py   sahriswiki(Download)
from genshi.core import Markup
 
from circuits.web.tools import check_auth, basic_auth
from circuits.web.controllers import expose, BaseController
 
        realm = self.environ.config.get("name")
 
        if not check_auth(self.request, self.response, realm, users):
            return basic_auth(self.request, self.response, realm, users)
 

src/c/i/circuits-3.0.0.dev/tests/web/test_basicauth.py   circuits(Download)
from circuits.web import Controller
from circuits.web.tools import check_auth, basic_auth
 
from .helpers import HTTPError, HTTPBasicAuthHandler
from .helpers import urlopen, build_opener, install_opener
        encrypt = str
 
        if check_auth(self.request, self.response, realm, users, encrypt):
            return "Hello World!"
 

src/c/i/circuits-3.0.0.dev/tests/web/test_digestauth.py   circuits(Download)
 
from circuits.web import Controller
from circuits.web.tools import check_auth, digest_auth
 
from .helpers import HTTPError, HTTPDigestAuthHandler
    def index(self):
        realm = "Test"
        users = {"admin": "admin"}
 
        if check_auth(self.request, self.response, realm, users):