def requireAuthenticate(acceptGuest):
def requireAuth(f):
@wraps(f)
def decorated_function(*args, **kwargs):
auth = request.authorization
if auth:
if acceptGuest and request.headers['Service-Provider'] == 'Guest' and auth.username == app.config['GUEST_ID']:
if auth.password == app.config['GUEST_TOKEN']:
g.currentUser = None
g.loginWith = 'Guest'
return f(*args, **kwargs)
else:
g.loginWith = None
if request.headers['Service-Provider'] == 'Facebook':
g.facebookToken = FacebookModel.getTokenValidation(app.config['FACEBOOK_ACCESS_TOKEN'], auth.password)
if g.facebookToken['is_valid'] and g.facebookToken['user_id'] == auth.username:
g.currentUser = FacebookModel.getUser(auth.username)
g.loginWith = 'Facebook'
elif request.headers['Service-Provider'] == 'Google':
g.googleToken = GoogleModel.getTokenValidation(app.config['GOOGLE_CLIENT_ID'], auth.password)
if g.googleToken and g.googleToken['sub'] == auth.username:
g.currentUser = GoogleModel.getUser(auth.username)
g.loginWith = 'Google'
if g.loginWith and (str(request.url_rule) == '/v1/login' or g.currentUser):
if str(request.url_rule) == '/v1/login' or not g.currentUser['disabled']:
return f(*args, **kwargs)
return abort(410)
return abort(401)
return decorated_function
return requireAuth
评论列表
文章目录