plotly / plotly/dash-auth

[Feature Request] Allow passing a post-authentication callable to OIDCAuth

Open
#151 3 comments 2 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.