[Feature Request] Allow passing a post-authentication callable to OIDCAuth
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 135
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
The OIDCAuth class and group-based features added in 2.3.0 are great!
It would be useful for the OIDCAuth class to take a callable that is executed at the end of the OIDCAuth.callback method just before the redirect. This function would take the access token as single positional argument and have access to the session global, e.g.:
from dash import Dash
from dash_auth import OIDCAuth
from flask import session
def add_scopes_to_user(token):
if scope := token.get("scope"):
session["user"]["scopes"] = scope.split()
app = Dash(__name__)
auth = OIDCAuth(
app,
secret_key="aStaticSecretKey!",
post_auth_callback=add_scopes_to_user, # defaults to None
)
This feature would provide a lot of flexibility to app developers for different use cases:
- storage of additional fields from the token in the session (example above),
- add a user to the DB if not already existing,
- custom logging,
- etc.
I can submit a PR if this is a feature the maintainers would consider merging.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the OIDCAuth constructor and OIDCAuth.callback entry point described in the request, and inspect the existing OIDCAuth behavior around the final redirect. Define the optional callable's token argument, session access, and execution timing, then add coverage showing that it runs before redirecting and is skipped when unset.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- authentication
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100