Skip to content

Commit

Permalink
move login_manager initialisation into auth_manager init_app method
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquesfize committed Jul 16, 2024
1 parent db17c96 commit 6e8a31a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/pypnusershub/auth/auth_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pypnusershub.env import db

from .authentication import Authentication
from pypnusershub.login_manager import login_manager


from typing import TypedDict
Expand Down Expand Up @@ -61,30 +62,33 @@ def add_provider(
provider : Authentification
The authentication provider class.
Raises
------
AssertionError
If the provider is not an instance of Authentification.
"""
if not isinstance(provider_authentification, Authentication):
raise AssertionError("Provider must be an instance of Authentication")
if id_provider in self.provider_authentication_cls:
raise Exception(
f"Id provider {id_provider} already exist, please check your authentication config"
)
if not isinstance(provider_authentification, Authentication):
raise AssertionError("Provider must be an instance of Authentication")
self.provider_authentication_cls[id_provider] = provider_authentification

def init_app(
self, app, prefix: str = "/auth", providers_declaration: list[ProviderType] = []
) -> None:
"""
Initializes the Flask application with the AuthManager. In addtion, it registers the authentification module blueprint.
Initializes the Flask application with the AuthManager. In addition, it registers the authentication module blueprint.
Parameters
----------
app : Flask
The Flask application instance.
prefix : str, optional
The URL prefix for the authentication module blueprint.
providers_declaration : list[ProviderType], optional
List of provider declarations to be used by the AuthManager.
"""
from pypnusershub.routes import routes
Expand All @@ -104,6 +108,7 @@ def init_app(
instance_provider: Authentication = class_()
instance_provider.configure(configuration=provider_config)
self.add_provider(instance_provider.id_provider, instance_provider)
login_manager.init_app(app)

def get_provider(self, instance_name: str) -> Authentication:
"""
Expand Down

0 comments on commit 6e8a31a

Please sign in to comment.