Skip to content

Commit

Permalink
remove hard coded config key in auth_manager init_app method
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquesfize committed Jul 15, 2024
1 parent fded771 commit bd62dac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/pypnusershub/auth/auth_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
from .authentication import Authentication


from typing import TypedDict

Provider = TypedDict(
"Provider",
{
"id_provider": str,
"module": str,
"label": str,
"group_mapping": dict,
"logo": str,
},
)


class AuthManager:
"""
Manages authentication providers.
Expand Down Expand Up @@ -66,7 +80,9 @@ def add_provider(
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") -> None:
def init_app(
self, app, prefix: str = "/auth", providers_declaration: list[Provider] = []
) -> None:
"""
Initializes the Flask application with the AuthManager. In addtion, it registers the authentification module blueprint.
Expand All @@ -82,7 +98,7 @@ def init_app(self, app, prefix: str = "/auth") -> None:

app.register_blueprint(routes, url_prefix=prefix)

for provider_config in app.config["AUTHENTICATION"].get("PROVIDERS", []):
for provider_config in providers_declaration:
path_provider = provider_config.get("module")
import_path, class_name = (
".".join(path_provider.split(".")[:-1]),
Expand Down
4 changes: 3 additions & 1 deletion src/pypnusershub/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def app():
app.testing = True
db.init_app(app)
ma.init_app(app)
auth_manager.init_app(app)
auth_manager.init_app(
app, providers_declaration=app.config["AUTHENTICATION"]["PROVIDERS"]
)
login_manager.init_app(app)

with app.app_context():
Expand Down

0 comments on commit bd62dac

Please sign in to comment.