Decorator for SecurityManager in flask appbuilder for superest

為{幸葍}努か 提交于 2019-12-11 05:09:43

问题


I'm trying to add a custom user information retrieval from OAuth in superset, which is build on top of flask-appbuilder.

Official doc provides following information:

Decorate your method with the SecurityManager oauth_user_info_getter decorator. Make your method accept the exact parameters as on this example, and then return a dictionary with the retrieved user information.

http://flask-appbuilder.readthedocs.io/en/latest/security.html#authentication-oauth

The example in the doc also does not help much, as decorator was put in the comments.

I am where to put custom decorator in Superset? I've put the custom decorator in superset_config.py but I didn't work for me.


回答1:


The approach that I use boils down to the following:

# For superset version >= 0.25.0

from superset.security import SupersetSecurityManager


class CustomSecurityManager(SupersetSecurityManager):

     def __init__(self, appbuilder):
         super(CustomSecurityManager, self).__init__(appbuilder)

     def whatever_you_want_to_override(self, ...):
         # Your implementation here


CUSTOM_SECURITY_MANAGER = CustomSecurityManager


# For superset version < 0.25.0
from flask_appbuilder.security.sqla.manager import SecurityManager


class CustomSecurityManager(SecurityManager):

     def __init__(self, appbuilder):
         super(CustomSecurityManager, self).__init__(appbuilder)

     def whatever_you_want_to_override(self, ...):
         # Your implementation here


CUSTOM_SECURITY_MANAGER = CustomSecurityManager


来源:https://stackoverflow.com/questions/50492494/decorator-for-securitymanager-in-flask-appbuilder-for-superest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!