-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
New, Dynamic user registration role #1410
New, Dynamic user registration role #1410
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice feature, dependencies are not correct (let's make it an extra) or document that the use of jmepath
needs an extra package.
Also would be great if you could add some documentation with a couple of examples
requirements.txt
Outdated
@@ -22,6 +22,7 @@ flask==1.1.1 | |||
idna==2.9 # via email-validator | |||
itsdangerous==1.1.0 # via flask | |||
jinja2==2.10.1 # via flask, flask-babel | |||
jmespath==0.9.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not on setup.py
it can't be here, this file is auto generated by pip-compile. We could add it to requirements-dev.txt if we decide it's not a root dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think it's not a root dependency. Added to extras.
flask_appbuilder/security/manager.py
Outdated
@@ -347,6 +348,10 @@ def auth_user_registration(self): | |||
def auth_user_registration_role(self): | |||
return self.appbuilder.get_app.config["AUTH_USER_REGISTRATION_ROLE"] | |||
|
|||
@property | |||
def auth_user_registration_role_jmespath(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'm starting to add type annotations, at least on every new PR.
def auth_user_registration_role_jmespath(self) -> str:
@dpgaspar Thanks for the review! I've moved the dependency to setup's extras and added a few lines of documentation with examples |
This PR brings dynamic user role on registration based on OAuth userinfo.
The current approach sets static
AUTH_USER_REGISTRATION_ROLE
for all users if self-registration is enabled. In our case, with OAuth authentication on GSuite domain (with FAB being auth engine for Airflow), we'd like to set team members as Admins and every other employee as read-only user ("Viewer").This PR implements method that is used in Grafana (docs), it uses JMESPath to resolve the role from userinfo retrieved from OAuth. It's quite flexible, as some OAuth providers return only username (like Google does), but others, like Okta, can return groups, so they can be utilized by the dynamic expression.
If needed, I'm more than happy to extend the docs by adding more examples of JMESPath.