Introducing exception handling in the application code
This commit is contained in:
@@ -93,7 +93,12 @@ class OAuthSignIn(metaclass=abc.ABCMeta):
|
|||||||
cls._providers = {}
|
cls._providers = {}
|
||||||
# TODO convert to the new __init_subclass__
|
# TODO convert to the new __init_subclass__
|
||||||
for provider_class in cls.__subclasses__():
|
for provider_class in cls.__subclasses__():
|
||||||
|
try:
|
||||||
provider = provider_class()
|
provider = provider_class()
|
||||||
|
except ProviderConfigurationMissing:
|
||||||
|
# TODO: log this at info level
|
||||||
|
pass
|
||||||
|
else:
|
||||||
cls._providers[provider.provider_name] = provider
|
cls._providers[provider.provider_name] = provider
|
||||||
try:
|
try:
|
||||||
return cls._providers[provider_name]
|
return cls._providers[provider_name]
|
||||||
|
@@ -15,7 +15,8 @@ from pillar.web import system_util
|
|||||||
from pillar.api.local_auth import generate_and_store_token, get_local_user
|
from pillar.api.local_auth import generate_and_store_token, get_local_user
|
||||||
from pillar.api.utils.authentication import find_user_in_db, upsert_user
|
from pillar.api.utils.authentication import find_user_in_db, upsert_user
|
||||||
from pillar.api.blender_cloud.subscription import update_subscription
|
from pillar.api.blender_cloud.subscription import update_subscription
|
||||||
from pillar.auth.oauth import OAuthSignIn
|
from pillar.auth.oauth import OAuthSignIn, ProviderConfigurationMissing, ProviderNotImplemented, \
|
||||||
|
OAuthCodeNotProvided
|
||||||
from . import forms
|
from . import forms
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@@ -31,7 +32,16 @@ def check_oauth_provider(provider):
|
|||||||
def oauth_authorize(provider):
|
def oauth_authorize(provider):
|
||||||
if not current_user.is_anonymous:
|
if not current_user.is_anonymous:
|
||||||
return redirect(url_for('main.homepage'))
|
return redirect(url_for('main.homepage'))
|
||||||
|
|
||||||
|
try:
|
||||||
oauth = OAuthSignIn.get_provider(provider)
|
oauth = OAuthSignIn.get_provider(provider)
|
||||||
|
except ProviderConfigurationMissing as e:
|
||||||
|
log.error('Login with OAuth failed: %s', e)
|
||||||
|
raise wz_exceptions.NotFound()
|
||||||
|
except ProviderNotImplemented as e:
|
||||||
|
log.error('Login with OAuth failed: %s', e)
|
||||||
|
raise wz_exceptions.NotFound()
|
||||||
|
|
||||||
return oauth.authorize()
|
return oauth.authorize()
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +50,11 @@ def oauth_callback(provider):
|
|||||||
if not current_user.is_anonymous:
|
if not current_user.is_anonymous:
|
||||||
return redirect(url_for('main.homepage'))
|
return redirect(url_for('main.homepage'))
|
||||||
oauth = OAuthSignIn.get_provider(provider)
|
oauth = OAuthSignIn.get_provider(provider)
|
||||||
|
try:
|
||||||
oauth_user = oauth.callback()
|
oauth_user = oauth.callback()
|
||||||
|
except OAuthCodeNotProvided as e:
|
||||||
|
log.error(e)
|
||||||
|
raise wz_exceptions.Forbidden()
|
||||||
if oauth_user.id is None:
|
if oauth_user.id is None:
|
||||||
log.debug('Authentication failed for user with {}'.format(provider))
|
log.debug('Authentication failed for user with {}'.format(provider))
|
||||||
return redirect(url_for('main.homepage'))
|
return redirect(url_for('main.homepage'))
|
||||||
|
Reference in New Issue
Block a user