def setup_auth(self, request, redirect_uri, cinfo, cookie, acr=None,
                   **kwargs):
        """

        :param request: The authorization/authentication request
        :param redirect_uri:
        :param cinfo: client info
        :param cookie:
        :param acr: Default ACR, if nothing else is specified
        :param kwargs:
        :return:
        """

        res = self.pick_authn_method(request, redirect_uri, acr, **kwargs)

        authn = res['method']
        authn_class_ref = res['acr']

        try:
            try:
                _auth_info = kwargs["authn"]
            except KeyError:
                _auth_info = ""

            if "upm_answer" in request and request["upm_answer"] == "true":
                _max_age = 0
            else:
                _max_age = max_age(request)

            identity, _ts = authn.authenticated_as(
                cookie, authorization=_auth_info, max_age=_max_age)
        except (NoSuchAuthentication, TamperAllert):
            identity = None
            _ts = 0
        except ToOld:
            logger.info("Too old authentication")
            identity = None
            _ts = 0
        else:
            if identity:
                try:  # If identity['uid'] is in fact a base64 encoded JSON string
                    _id = b64d(as_bytes(identity['uid']))
                except BadSyntax:
                    pass
                else:
                    identity = json.loads(as_unicode(_id))

                    try:
                        session = self.endpoint_context.sdb[identity['sid']]
                    except KeyError:
                        identity = None
                    else:
                        if session is None:
                            identity = None
                        elif 'revoked' in session:
                            identity = None

        authn_args = authn_args_gather(request, authn_class_ref, cinfo,
                                       **kwargs)

        # To authenticate or Not
        if identity is None:  # No!
            logger.info("No active authentication")
            if "prompt" in request and "none" in request["prompt"]:
                # Need to authenticate but not allowed
                return {
                    'error': "login_required", 'return_uri': redirect_uri,
                    'return_type': request["response_type"]
                }
            else:
                return {'function': authn, 'args': authn_args}
        else:
            logger.info("Active authentication")
            if re_authenticate(request, authn):
                # demand re-authentication
                return {'function': authn, 'args': authn_args}
            else:
                # I get back a dictionary
                user = identity["uid"]
                if "req_user" in kwargs:
                    sids = self.endpoint_context.sdb.get_sids_by_sub(
                        kwargs["req_user"])
                    if sids and user != \
                            self.endpoint_context.sdb.get_authentication_event(
                                sids[-1]).uid:
                        logger.debug("Wanted to be someone else!")
                        if "prompt" in request and "none" in request["prompt"]:
                            # Need to authenticate but not allowed
                            return {
                                'error': "login_required",
                                'return_uri': redirect_uri
                            }
                        else:
                            return {'function': authn, 'args': authn_args}

        authn_event = create_authn_event(identity["uid"],
                                         identity.get('salt', ''),
                                         authn_info=authn_class_ref,
                                         time_stamp=_ts)
        try:
            authn_event['valid_until'] = time.time() + authn.kwargs['expires_in']
        except KeyError:
            pass

        return {"authn_event": authn_event, "identity": identity, "user": user}
def setup_auth ( self , request , redirect_uri , cinfo , cookie , acr = None , ** kwargs ) : res = self . pick_authn_method ( request , redirect_uri , acr , ** kwargs ) authn = res [ 'method' ] authn_class_ref = res [ 'acr' ] try : try : _auth_info = kwargs [ "authn" ] except KeyError : _auth_info = "" if "upm_answer" in request and request [ "upm_answer" ] == "true" : _max_age = 0 else : _max_age = max_age ( request ) identity , _ts = authn . authenticated_as ( cookie , authorization = _auth_info , max_age = _max_age ) except ( NoSuchAuthentication , TamperAllert ) : identity = None _ts = 0 except ToOld : logger . info ( "Too old authentication" ) identity = None _ts = 0 else : if identity : try : _id = b64d ( as_bytes ( identity [ 'uid' ] ) ) except BadSyntax : pass else : identity = json . loads ( as_unicode ( _id ) ) try : session = self . endpoint_context . sdb [ identity [ 'sid' ] ] except KeyError : identity = None else : if session is None : identity = None elif 'revoked' in session : identity = None authn_args = authn_args_gather ( request , authn_class_ref , cinfo , ** kwargs ) if identity is None : logger . info ( "No active authentication" ) if "prompt" in request and "none" in request [ "prompt" ] : return { 'error' : "login_required" , 'return_uri' : redirect_uri , 'return_type' : request [ "response_type" ] } else : return { 'function' : authn , 'args' : authn_args } else : logger . info ( "Active authentication" ) if re_authenticate ( request , authn ) : return { 'function' : authn , 'args' : authn_args } else : user = identity [ "uid" ] if "req_user" in kwargs : sids = self . endpoint_context . sdb . get_sids_by_sub ( kwargs [ "req_user" ] ) if sids and user != self . endpoint_context . sdb . get_authentication_event ( sids [ - 1 ] ) . uid : logger . debug ( "Wanted to be someone else!" ) if "prompt" in request and "none" in request [ "prompt" ] : return { 'error' : "login_required" , 'return_uri' : redirect_uri } else : return { 'function' : authn , 'args' : authn_args } authn_event = create_authn_event ( identity [ "uid" ] , identity . get ( 'salt' , '' ) , authn_info = authn_class_ref , time_stamp = _ts ) try : authn_event [ 'valid_until' ] = time . time ( ) + authn . kwargs [ 'expires_in' ] except KeyError : pass return { "authn_event" : authn_event , "identity" : identity , "user" : user }
:param request: The authorization/authentication request
        :param redirect_uri:
        :param cinfo: client info
        :param cookie:
        :param acr: Default ACR, if nothing else is specified
        :param kwargs:
        :return: