Ejemplo n.º 1
0
def verify(assertion, audience=None):
    """Verify the given BrowserID assertion.

    This function uses the "best" verification method available in order to
    verify the given BrowserID assertion and return a dict of user data.  The
    best method currently involves POSTing to the hosted verifier service on
    persona.org; eventually it will do local verification.
    """
    global _DEFAULT_VERIFIER
    if _DEFAULT_VERIFIER is None:
        _DEFAULT_VERIFIER = LocalVerifier()
    return _DEFAULT_VERIFIER.verify(assertion, audience)
def verify(assertion, audience=None):
    """Verify the given BrowserID assertion.

    This function uses the "best" verification method available in order to
    verify the given BrowserID assertion and return a dict of user data.  The
    best method currently involves POSTing to the hosted verifier service on
    persona.org; eventually it will do local verification.
    """
    global _DEFAULT_VERIFIER
    if _DEFAULT_VERIFIER is None:
        _DEFAULT_VERIFIER = LocalVerifier()
    return _DEFAULT_VERIFIER.verify(assertion, audience)
Ejemplo n.º 3
0
    class LocalVerifier(object):
        """
        Verifies BrowserID assertions locally instead of using the remote
        verification service.
        """
        def __init__(self, *args, **kwargs):
            super(LocalVerifier, self).__init__(*args, **kwargs)
            self.pybid_verifier = PyBrowserIDLocalVerifier()

        def verify(self, assertion, audience, **kwargs):
            """
            Verify an assertion locally.

            :param assertion:
                BrowserID assertion to verify.

            :param audience:
                The protocol, hostname and port of your website. Used to confirm that the assertion was
                meant for your site and not for another site.

            :returns:
                :class:`.VerificationResult`
            """
            try:
                result = self.pybid_verifier.verify(assertion, audience)
            except PyBrowserIDError as error:
                return VerificationResult({
                    'status': 'failure',
                    'reason': error
                })

            return VerificationResult(result)
Ejemplo n.º 4
0
    class LocalVerifier(object):
        """
        Verifies BrowserID assertions locally instead of using the remote
        verification service.
        """
        def __init__(self, *args, **kwargs):
            super(LocalVerifier, self).__init__(*args, **kwargs)
            self.pybid_verifier = PyBrowserIDLocalVerifier()

        def verify(self, assertion, audience, **kwargs):
            """
            Verify an assertion locally.

            :param assertion:
                BrowserID assertion to verify.

            :param audience:
                The protocol, hostname and port of your website. Used to confirm that the assertion was
                meant for your site and not for another site.

            :returns:
                :class:`.VerificationResult`
            """
            try:
                result = self.pybid_verifier.verify(assertion, audience)
            except PyBrowserIDError as error:
                return VerificationResult({
                    'status': 'failure',
                    'reason': error
                })

            return VerificationResult(result)
 def __init__(self, num_procs=None, verifier=None):
     # Try to choose a sensible number of processes by default.
     if num_procs is None:
         try:
             num_procs = multiprocessing.cpu_count()
         except NotImplementedError:
             num_procs = 2
     # Use LocalVerifier by default, but allow overriding.
     if verifier is None:
         verifier = LocalVerifier()
     self.num_procs = num_procs
     self.verifier = verifier
     # Create the various communication channels.
     # Yes, this duplicates a lot of the logic from multprocessing.Pool.
     # I don't want to have to constantly pickle the verifier object
     # to send it into the subprocesses, and the Pool class doesn't lend
     # itself to subclases in a way that would avoid this.  So here we are.
     # We have:
     # 1) a queue from which the workers read jobs
     self._work_queue = multiprocessing.Queue()
     # 2) a queue into which the workers push results
     self._result_queue = multiprocessing.Queue()
     # 3) a thread that dispatches results to other waiting threads,
     #    by signalling on a condition object.
     self._lock = threading.Lock()
     self._waiting_conds = {}
     self._spare_conds = []
     # Now we can start the required processes and threads.
     self._result_thread = threading.Thread(target=self._run_result_thread)
     self._result_thread.start()
     self._processes = []
     for n in xrange(num_procs):
         proc = multiprocessing.Process(target=self._run_worker)
         self._processes.append(proc)
         proc.start()
Ejemplo n.º 6
0
 def __init__(self, *args, **kwargs):
     super(LocalVerifier, self).__init__(*args, **kwargs)
     self.pybid_verifier = PyBrowserIDLocalVerifier()
Ejemplo n.º 7
0
 def __init__(self, *args, **kwargs):
     super(LocalVerifier, self).__init__(*args, **kwargs)
     self.pybid_verifier = PyBrowserIDLocalVerifier()