'Apache Superset TypeError while starting with OAuth authentication enabled

I'm trying to configure OAuth authentication with GitHub apis, on Superset 1.0.1. Following the docs, I added the following lines in superset_config.py

from flask_appbuilder.security.manager import AUTH_OAUTH
import logging

from custom_sso_security_manager import CustomSsoSecurityManager
CUSTOM_SECURITY_MANAGER = CustomSsoSecurityManager


    
AUTH_TYPE = AUTH_OAUTH

OAUTH_PROVIDERS = {
        "name": "github",
        "icon": "fa-github",
        "remote_app": {
            "client_id": "<my github client_id>" ,
            "client_secret": "<my github client secret>",
            "api_base_url": "https://github.com",
            "request_token_url": "https://github.com/login/oauth/request_token",
            "access_token_url": "https://github.com/login/oauth/access_token",
            "authorize_url": "https://github.com/login/oauth/authorize",
        },
    }
# Will allow user self registration, allowing to create Flask users from Authorized User
AUTH_USER_REGISTRATION = True

# The default user self registration role
AUTH_USER_REGISTRATION_ROLE = "Public"

and created the file custom_sso_security_manager.py

from superset.security import SupersetSecurityManager

class CustomSsoSecurityManager(SupersetSecurityManager):
    def oauth_user_info(self, provider, response=None):
        logging.debug("Oauth2 provider: {0}.".format(provider))
        if provider == 'github':
            me = self.appbuilder.sm.oauth_remotes[provider].get('userinfo').data
            logging.debug("user_data: {0}".format(me))
            return { 'email': me['email'], 'username': me['email'], 'first_name': me['nickname'], 'last_name': me['nickname'] }

When I start superset with the following command

superset run -h $(hostname) -p 8088 --with-threads --reload --debugger

(the $(hostname) param in order to provide access to the gui from a browser, since I'm deploying superset on a remote AWS EC2 instance)

I receive the following error

Traceback (most recent call last):
  File "/opt/superset/venv/lib/python3.8/site-packages/superset/app.py", line 62, in create_app
    app_initializer.init_app()
  File "/opt/superset/venv/lib/python3.8/site-packages/superset/app.py", line 551, in init_app
    self.init_app_in_ctx()
  File "/opt/superset/venv/lib/python3.8/site-packages/superset/app.py", line 520, in init_app_in_ctx
    self.configure_fab()
  File "/opt/superset/venv/lib/python3.8/site-packages/superset/app.py", line 591, in configure_fab
    appbuilder.init_app(self.flask_app, db.session)
  File "/opt/superset/venv/lib/python3.8/site-packages/flask_appbuilder/base.py", line 202, in init_app
    self.sm = self.security_manager_class(self)
  File "/opt/superset/venv/lib/python3.8/site-packages/flask_appbuilder/security/sqla/manager.py", line 51, in __init__
    super(SecurityManager, self).__init__(appbuilder)
  File "/opt/superset/venv/lib/python3.8/site-packages/flask_appbuilder/security/manager.py", line 261, in __init__
    provider_name = _provider["name"]
TypeError: string indices must be integers
Traceback (most recent call last):
  File "/opt/superset/venv/bin/superset", line 33, in <module>
    sys.exit(load_entry_point('apache-superset==1.0.1', 'console_scripts', 'superset')())
  File "/opt/superset/venv/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/superset/venv/lib/python3.8/site-packages/flask/cli.py", line 586, in main
    return super(FlaskGroup, self).main(*args, **kwargs)
  File "/opt/superset/venv/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/superset/venv/lib/python3.8/site-packages/click/core.py", line 1256, in invoke
    Command.invoke(self, ctx)
  File "/opt/superset/venv/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/superset/venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/superset/venv/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/opt/superset/venv/lib/python3.8/site-packages/flask/cli.py", line 425, in decorator
    with __ctx.ensure_object(ScriptInfo).load_app().app_context():
  File "/opt/superset/venv/lib/python3.8/site-packages/flask/cli.py", line 381, in load_app
    app = call_factory(self, self.create_app)
  File "/opt/superset/venv/lib/python3.8/site-packages/flask/cli.py", line 119, in call_factory
    return app_factory()
  File "/opt/superset/venv/lib/python3.8/site-packages/superset/app.py", line 69, in create_app
    raise ex
  File "/opt/superset/venv/lib/python3.8/site-packages/superset/app.py", line 62, in create_app
    app_initializer.init_app()
  File "/opt/superset/venv/lib/python3.8/site-packages/superset/app.py", line 551, in init_app
    self.init_app_in_ctx()
  File "/opt/superset/venv/lib/python3.8/site-packages/superset/app.py", line 520, in init_app_in_ctx
    self.configure_fab()
  File "/opt/superset/venv/lib/python3.8/site-packages/superset/app.py", line 591, in configure_fab
    appbuilder.init_app(self.flask_app, db.session)
  File "/opt/superset/venv/lib/python3.8/site-packages/flask_appbuilder/base.py", line 202, in init_app
    self.sm = self.security_manager_class(self)
  File "/opt/superset/venv/lib/python3.8/site-packages/flask_appbuilder/security/sqla/manager.py", line 51, in __init__
    super(SecurityManager, self).__init__(appbuilder)
  File "/opt/superset/venv/lib/python3.8/site-packages/flask_appbuilder/security/manager.py", line 261, in __init__
    provider_name = _provider["name"]
TypeError: string indices must be integers

What could it be ? My gut feeling is that I'm using the wrong authlib package version or something like this. My python package env is the following

Package                Version
---------------------- -----------
aiohttp                3.7.4.post0
alembic                1.5.8
amqp                   2.6.1
apache-superset        1.0.1
apispec                3.3.2
async-timeout          3.0.1
attrs                  20.3.0
Authlib                0.15.3
Babel                  2.9.0
backoff                1.10.0
billiard               3.6.3.0
bleach                 3.3.0
Brotli                 1.0.9
cachelib               0.1.1
celery                 4.4.7
certifi                2020.12.5
cffi                   1.14.5
chardet                4.0.0
click                  7.1.2
colorama               0.4.4
contextlib2            0.6.0.post1
convertdate            2.3.2
cron-descriptor        1.2.24
croniter               1.0.10
cryptography           3.4.7
decorator              4.4.2
defusedxml             0.7.1
dnspython              2.1.0
email-validator        1.1.2
Flask                  1.1.2
Flask-AppBuilder       3.2.1
Flask-Babel            1.0.0
Flask-Caching          1.10.1
Flask-Compress         1.9.0
Flask-JWT-Extended     3.25.1
Flask-Login            0.4.1
Flask-Migrate          2.7.0
Flask-OpenID           1.2.5
Flask-SQLAlchemy       2.5.1
flask-talisman         0.7.0
Flask-WTF              0.14.3
geographiclib          1.50
geopy                  2.1.0
greenlet               1.0.0
gunicorn               20.0.4
holidays               0.10.3
humanize               3.3.0
idna                   2.10
isodate                0.6.0
itsdangerous           1.1.0
Jinja2                 2.11.3
jsonschema             3.2.0
kombu                  4.6.11
korean-lunar-calendar  0.2.1
Mako                   1.1.4
Markdown               3.3.4
MarkupSafe             1.1.1
marshmallow            3.10.0
marshmallow-enum       1.5.1
marshmallow-sqlalchemy 0.23.1
msgpack                1.0.2
multidict              5.1.0
numpy                  1.20.1
packaging              20.9
pandas                 1.1.5
parsedatetime          2.6
pathlib2               2.3.5
pgsanity               0.2.9
pip                    21.0.1
polyline               1.4.0
prison                 0.1.3
py                     1.10.0
pyarrow                1.0.1
pycparser              2.20
PyJWT                  1.7.1
PyMeeus                0.5.11
PyMySQL                1.0.2
pyparsing              2.4.7
pyrsistent             0.17.3
pysqlite3              0.4.5
python-dateutil        2.8.1
python-dotenv          0.15.0
python-editor          1.0.4
python-geohash         0.8.5
python3-openid         3.2.0
pytz                   2021.1
PyYAML                 5.4.1
redis                  3.5.3
requests               2.25.1
retry                  0.9.2
selenium               3.141.0
setuptools             49.2.1
simplejson             3.17.2
six                    1.15.0
slackclient            2.5.0
SQLAlchemy             1.3.23
SQLAlchemy-Utils       0.36.8
sqlparse               0.3.0
typing-extensions      3.7.4.3
urllib3                1.26.4
vine                   1.3.0
webencodings           0.5.1
Werkzeug               1.0.1
WTForms                2.3.3
WTForms-JSON           0.3.3
yarl                   1.6.3

And I'm using Python 3.8.7 on CentOS 7.9



Solution 1:[1]

Maybe I shouldn't have posted the question so early, since it was a very simple error ...

The OAUTH_PROVIDERS variable should be an array!

OAUTH_PROVIDERS = [{
        "name": "github",
        "icon": "fa-github",
        "remote_app": {
            "client_id": "<my github client_id>" ,
            "client_secret": "<my github client secret>",
            "api_base_url": "https://github.com",
            "request_token_url": "https://github.com/login/oauth/request_token",
            "access_token_url": "https://github.com/login/oauth/access_token",
            "authorize_url": "https://github.com/login/oauth/authorize",
        },
    }
]

Now superset starts correctly. Though I have some other issues with the github login, but I think this should be another question.

P.S. I thought about removing the question since this is just a typo and I should have RTFM (again), but I'll leave it maybe it could be useful to other people.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cat