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

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

Open
DrGFreeman opened this issue Jul 10, 2024 · 2 comments

Comments

@DrGFreeman
Copy link

DrGFreeman commented Jul 10, 2024

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.

@FrancisRalph
Copy link

This would be very useful. Currently my workaround is to override the OIDCAuth:

class OIDCAuthCustom(OIDCAuth):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def callback(self, idp: str):
        return_value = super().callback(idp)

        client = self.get_oauth_client(idp)
        userinfo = client.userinfo()
        # ...

        return return_value

@georgewayne
Copy link

georgewayne commented Oct 4, 2024

@FrancisRalph - brilliant! thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants