Flask AppBuilder中用于SecurityManager的装饰器可提供最佳效果 [英] Decorator for SecurityManager in flask appbuilder for superest

查看:530
本文介绍了Flask AppBuilder中用于SecurityManager的装饰器可提供最佳效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从超级授权中的OAuth添加自定义用户信息,该信息建立在flask-appbuilder之上。

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:


使用SecurityManager装饰您的方法oauth_user_info_getter
装饰员。使您的方法接受与
示例相同的参数,然后返回包含检索到的用户
信息的字典。

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 / zh_CN / latest / security.html#authentication-oauth

文档中的示例也无济于事,因为装饰器已添加到注释中。

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

我在哪里将自定义装饰器放在Superset中?我已将自定义装饰器放在superset_config.py中,但没有为我工作。

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.

推荐答案

我使用的方法可归结为以下内容:

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

这篇关于Flask AppBuilder中用于SecurityManager的装饰器可提供最佳效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆