Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Google OAuth admin authentication provider #802

Merged
merged 17 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions api/admin/admin_authentication_provider.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
class AdminAuthenticationProvider:
def __init__(self, integration):
self.integration = integration

def sign_in_template(self, redirect_url):
# Returns HTML to be rendered on the sign in page for
# this authentication provider.
Expand Down
50 changes: 6 additions & 44 deletions api/admin/controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

from api.admin.config import Configuration as AdminClientConfig
from api.admin.exceptions import *
from api.admin.google_oauth_admin_authentication_provider import (
GoogleOAuthAdminAuthenticationProvider,
)
from api.admin.opds import AdminAnnotator, AdminFeed
from api.admin.password_admin_authentication_provider import (
PasswordAdminAuthenticationProvider,
Expand Down Expand Up @@ -144,9 +141,7 @@ def setup_admin_controllers(manager):
manager.admin_patron_auth_service_self_tests_controller = (
PatronAuthServiceSelfTestsController(manager)
)
from api.admin.controller.admin_auth_services import AdminAuthServicesController

manager.admin_auth_services_controller = AdminAuthServicesController(manager)
from api.admin.controller.collection_settings import CollectionSettingsController

manager.admin_collection_settings_controller = CollectionSettingsController(manager)
Expand Down Expand Up @@ -216,23 +211,10 @@ def __init__(self, manager):

@property
def admin_auth_providers(self):
auth_providers = []
auth_service = ExternalIntegration.admin_authentication(self._db)
if auth_service and auth_service.protocol == ExternalIntegration.GOOGLE_OAUTH:
auth_providers.append(
GoogleOAuthAdminAuthenticationProvider(
auth_service,
url_for("google_auth_callback", _external=True),
test_mode=self.manager.testing,
)
)
if Admin.with_password(self._db).count() != 0:
auth_providers.append(
PasswordAdminAuthenticationProvider(
auth_service,
)
)
return auth_providers
return [PasswordAdminAuthenticationProvider()]

return []

def admin_auth_provider(self, type):
# Return an auth provider with the given type.
Expand All @@ -255,7 +237,7 @@ def authenticated_admin_from_request(self):
auth = self.admin_auth_provider(type)
if not auth:
return ADMIN_AUTH_MECHANISM_NOT_CONFIGURED
if admin and auth.active_credentials(admin):
if admin:
flask.request.admin = admin
return admin
flask.request.admin = None
Expand All @@ -265,17 +247,14 @@ def authenticated_admin(self, admin_details):
"""Creates or updates an admin with the given details"""

admin, is_new = get_one_or_create(self._db, Admin, email=admin_details["email"])
admin.update_credentials(
self._db,
credential=admin_details.get("credentials"),
)

if is_new and admin_details.get("roles"):
for role in admin_details.get("roles"):
if role.get("role") in AdminRole.ROLES:
library = Library.lookup(self._db, role.get("library"))
if role.get("library") and not library:
self.log.warn(
"%s authentication provider specifiec an unknown library for a new admin: %s"
"%s authentication provider specified an unknown library for a new admin: %s"
% (admin_details.get("type"), role.get("library"))
)
else:
Expand Down Expand Up @@ -595,23 +574,6 @@ def sign_in(self):
elif admin:
return redirect(flask.request.args.get("redirect"), Response=Response)

def redirect_after_google_sign_in(self):
"""Uses the Google OAuth client to determine admin details upon
callback. Barring error, redirects to the provided redirect url.."""
if not self.admin_auth_providers:
return ADMIN_AUTH_NOT_CONFIGURED

auth = self.admin_auth_provider(GoogleOAuthAdminAuthenticationProvider.NAME)
if not auth:
return ADMIN_AUTH_MECHANISM_NOT_CONFIGURED

admin_details, redirect_url = auth.callback(self._db, flask.request.args)
if isinstance(admin_details, ProblemDetail):
return self.error_response(admin_details)

admin = self.authenticated_admin(admin_details)
return redirect(redirect_url, Response=Response)

def password_sign_in(self):
if not self.admin_auth_providers:
return ADMIN_AUTH_NOT_CONFIGURED
Expand Down
110 changes: 0 additions & 110 deletions api/admin/controller/admin_auth_services.py

This file was deleted.

Loading