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)
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(), })