Refactor auth code to be cleaner and more extensible

We move all the auth handling, serialization and deserialization into a new AuthContext interface, and then standardize a registration model for handling of specific auth context types (user, robot, token, etc).
This commit is contained in:
Joseph Schorr 2018-01-05 16:27:03 -05:00
parent 8ba2e71fb1
commit e220b50543
31 changed files with 822 additions and 436 deletions

View file

@ -6,8 +6,7 @@ from flask import abort, request, make_response
import features
from app import app
from auth.auth_context import (
get_validated_oauth_token, get_authenticated_user, get_validated_token, get_grant_context)
from auth.auth_context import get_authenticated_context
from util.names import parse_namespace_repository
@ -73,8 +72,7 @@ def check_anon_protection(func):
return func(*args, **kwargs)
# Check for validated context. If none exists, fail with a 401.
if (get_authenticated_user() or get_validated_oauth_token() or get_validated_token() or
get_grant_context()):
if get_authenticated_context() and not get_authenticated_context().is_anonymous:
return func(*args, **kwargs)
abort(401)