예제 #1
0
    def wrapper(*args, **kwargs):
        if request.authorization is None:
            raise Unauthorized([{
                'detail': 'You must provide basic authorization headers',
                'where': 'request.authorization',
            }])

        identifier = request.authorization['username']
        token = request.authorization['password']

        user = User.get_by('identifier', identifier)
        token = Token.get_by('token', token)

        if (
            user is None or token is None or
            token.proxy.user.get().id != user.id
        ):
            raise Unauthorized([{
                'detail': 'Your credentials are invalid, sorry',
                'where': 'request.authorization',
            }])

        g.user = user

        return view(*args, **kwargs)
예제 #2
0
파일: auth.py 프로젝트: tracsa/cacahuate
def whoami():
    identifier = flask.request.authorization['username']
    token = flask.request.authorization['password']

    user = User.get_by('identifier', identifier)
    token = Token.get_by('token', token)

    if user is None or \
       token is None or \
       token.user.get().id != user.id:
        raise Unauthorized([{
            'detail': 'Your credentials are invalid, sorry',
            'where': 'request.authorization',
        }])

    return flask.jsonify({
        'data': user.to_json(),
    })