Example #1
0
def res_code(request, vender, action, mode):
    """
    """
    authres = AuthRes.from_url(request.get_full_path())
    valid_state = authres.state == request.session["state"]
    if not valid_state:
        raise Exception("Invalid State")

    signon = None
    errors = None
    try:
        signon = SignOn.objects.get(state=authres.state)
        signon.response_object = authres
        signon.save()

        if authres.error:
            raise Exception("authres error")

        id_token = request_token(request, signon, vender)

        save_signon(request, signon)
        return bind(request, signon)

    except Exception, ex:
        errors = traceback.format_exc()
        if signon:
            signon.errors = errors
            signon.save()
Example #2
0
    def test_response(self):
        '''
        python manage.py test connect.venders.self.tests.TestSiop.test_response
        '''
        # TODO: this test only works when the AuthReq has been created..
        
        auth_res_path = None
        with open(os.path.join(FIXTURES, "res.txt")) as data:
            auth_res_path = data.read().rstrip('\r\n')

        self.assertIsNotNone(auth_res_path)

        authres = AuthRes.from_url(auth_res_path)

        session = self.client.session
        session['state'] = authres.state
        session.save()
       
        res = self.client.get(auth_res_path)
Example #3
0
def res_implicit(request, vender, action, mode):
    """
    """
    authres = AuthRes.from_url(request.get_full_path())
    valid_state = authres.state == request.session["state"]
    if not valid_state:
        raise Exception("Invalid State")

    if not authres.id_token:
        raise Exception("No ID Token")

    signon = None
    errors = None
    try:
        signon = SignOn.objects.get(state=authres.state)

        # Save AuthRes
        signon.response_object = authres

        # Save Id Token
        id_token_string = signon.get_id_token_string()
        if id_token_string:
            id_token = IdToken.parse_siop_token(id_token_string)
            signon.verified = id_token.verified
            signon.id_token_object = id_token
            signon.subject = id_token.sub

        signon.save()

        if authres.error:
            raise Exception("authres error")

        save_signon(request, signon)
        return bind(request, signon)

    except Exception, ex:
        errors = traceback.format_exc()
        if signon:
            signon.errors = errors
            signon.save()