예제 #1
0
    def decorated_function(session, *args, **kws):
        if 'authToken' not in request.headers:
            abort(401)

        try:
            shortened_token = BlockstackAuth.short_jwt(
                request.headers['authToken']
            )  # implicitly checks if its a token
            username = BlockstackAuth.get_username_from_token(shortened_token)

            user_inst: User = session.query(User).filter(
                User.usernameUser == username).one()

            # check if token matches "cached" token, if thats the case, we are done here... else:
            if shortened_token != user_inst.authToken:
                # verify token:
                if BlockstackAuth.verify_auth_response(shortened_token):
                    # token is valid, save it to DB
                    user_inst.authToken = shortened_token
                    session.commit()
                else:
                    # token invalid, abort
                    abort(401)

            else:  # token is valid
                pass
        except NoResultFound:
            # User needs to register
            abort(404)
        except (KeyError, ValueError, DecodeError):  # jwt decode errors
            abort(401)
        else:
            tmp = func(user_inst, *args, **kws)
            session.commit()  # if user_inst get's changed
            return tmp
예제 #2
0
def test_verify_invalid6():
    assert not BlockstackAuth.verify_auth_response(TOKEN_INVALID_ISS2)
예제 #3
0
def test_verify_no_token2():
    with pytest.raises(DecodeError):
        BlockstackAuth.verify_auth_response("test")
예제 #4
0
def test_verify_valid3():
    assert BlockstackAuth.verify_auth_response(TOKEN_3)