def wrapper(*args, **kwargs): if 'Authorization' in request.headers: tok = request.headers.get('Authorization')[7:] else: return INVALID_ACCESS_TOKEN() uid, expires = Token.load_access_token(g.rds, tok) uid = int(uid) if uid else 0 expires = int(expires) if expires else 0 if not uid: return INVALID_ACCESS_TOKEN() if time.time() > expires: logging.debug("access token expire") return EXPIRE_ACCESS_TOKEN() request.uid = uid return f(*args, **kwargs)
def decorated(*args, **kwargs): auth = web.ctx.env['HTTP_AUTHORIZATION'] if 'HTTP_AUTHORIZATION' in web.ctx.env else None unauth = True uid = 0 if len(auth) > 7 and auth[:7] == "Bearer ": tok = auth[7:] uid, expires = Token.load_access_token(rds, tok) uid = int(uid) if uid else 0 expires = int(expires) if expires else 0 if uid and time.time() < expires: unauth = False if unauth : web.ctx.status = '401 Unauthorized' return Unauthorized() web.ctx.uid = uid return f(*args, **kwargs)