Question: How to auto login (bypass) login page?
Hi ,
I am new to superset. Actually what i want is when i click a link in my application, it should redirect to superset and open dashboard page bypassing the login page in a separate window? can you please briefly explain or give me step wise instructions on how to do this. My mail Id: [email protected]
Thanks & Regards, Govardhan
Do you want 1) to grant public access to there dashboards, or 2) you want to setup some sort of auto login?
-
there should be a
Publicrole, you can setup the install paramPUBLIC_ROLE_LIKE_GAMMAto give a set of basic permissions to public, and then manually add datasources you want public to thePublicrole. -
for auto login at Airbnb we use REMOTE_USER, a mechanism that Flask App Builder (FAB) support that involves a reverse proxy that does LDAP authentication and adds headers with username and groups as it passes requests to the app itself. The app has to be configured to expect that. FAB documents how to do this.
Hi, Thanks for your reply.
I want to setup some sort of auto login? I am developing a web application using nodejs. After loging into my app then clicking on some link redirect to superset auto login. can you please get me some more detailed information on this as I couldn't find it in FAB.
Thanks, Govardhan
Not sure where/if you looked but authentication is very well documented: http://flask-appbuilder.readthedocs.io/en/latest/security.html#authentication-methods
@govardhank are you finished?
@govardhank thanks,I have solved this problem
@qq273681448 Hi, how do you solve this? Can you help me out? Thx 👍
You need 3 things in your superset_config.py:
- A custom REMOTE_USER authenticator
- Update the security manager to point to a new one that have you custom authenticator
- Set the auth type to AUTH_REMOTE_USER
In a nutshel:
# Import some libraries that are required
from flask_appbuilder.security.views import expose
from flask_appbuilder.security.sqla.manager import SecurityManager
from flask_appbuilder.security.manager import BaseSecurityManager
from flask_appbuilder.security.manager import AUTH_REMOTE_USER
# Create a custom view to authenticate the user
AuthRemoteUserView=BaseSecurityManager.authremoteuserview
class AirbnbAuthRemoteUserView(AuthRemoteUserView):
@expose('/login/')
def login(self):
print("This is LOGIN")
return ("This is the response from your custom authenticator")
# Create a custom Security manager that override the authremoteuserview with the one I've created
class CustomSecurityManager(SecurityManager):
authremoteuserview = AirbnbAuthRemoteUserView
# Use my custom authenticator
CUSTOM_SECURITY_MANAGER = CustomSecurityManager
# User remote authentication
AUTH_TYPE = AUTH_REMOTE_USER
I use docker to do all my test and found that running superset with gunicorn is much easier because I can reload the server as soon as I update the configuration file:
# Start the docker container
# I'm using 0.23.3 because I had issue with more recent versions
docker run -it -v $(pwd)/config:/etc/superset -v $(pwd)/SQLlite:/var/lib/superset -p 8088:6000 --entrypoint sh --user root amancevice/superset:0.23.3
# First you'll need to update gunicorn to get the version >= 19.8+ in order to use reload-extra-file
pip3 install gunicorn --upgrade
# Then inside the container start gunicorn
gunicorn -w 1 -k gevent --timeout 120 \
--reload \
--reload-extra-file /etc/superset/superset_config.py \
-b 0.0.0.0:6000 --limit-request-line 0 --limit-request-field_size 0 superset:app
I hope this will help anyone looking for auto-login. I could not find any clear documentation anywhere, but once I found out that it was using Flask App then it was a bit more easy. All the doc is here and here is the source code of the security views
@Maxwell2022 I tried to apply your changes to config file from Superset docker image and am now getting 502 error for all requests from browser. I tried to CURL to endpoints while passing REMOTE_USER header additionally - same result.
This REMOTE_USER auth scheme is really poorly documented, could you give a complete working example? I think it will worth it as Superset looks like a product that gets integrated as part of other products.
@Maxwell2022 In fact I found how to use REMOTE_USER , instruction is pretty obvious in main doc.
Try this in superset_config.py:
from flask_appbuilder.security.views import expose
from superset.security import SupersetSecurityManager
from flask_appbuilder.security.manager import BaseSecurityManager
from flask_appbuilder.security.manager import AUTH_REMOTE_USER
from flask import redirect
from flask_login import login_user
# Create a custom view to authenticate the user
AuthRemoteUserView=BaseSecurityManager.authremoteuserview
class AirbnbAuthRemoteUserView(AuthRemoteUserView):
@expose('/login/')
def login(self):
user = self.appbuilder.sm.auth_user_db("admin", "admin")
login_user(user, remember=False)
return redirect(self.appbuilder.get_url_for_index)
# Create a custom Security manager that override the authremoteuserview with the one I've created
class CustomSecurityManager(SupersetSecurityManager):
authremoteuserview = AirbnbAuthRemoteUserView
# Use my custom authenticator
CUSTOM_SECURITY_MANAGER = CustomSecurityManager
# User remote authentication
AUTH_TYPE = AUTH_REMOTE_USER
source code of the security views
Can you please explain how you solved ?
HI!我是邵磊,您的邮件我已经收到啦,我会在第一时间给您回复哦。
The solution mentioned https://github.com/apache/superset/issues/2580#issuecomment-293291888 works for me, i.e. adding:
class RemoteUserMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
user = environ.pop('HTTP_X_PROXY_REMOTE_USER', None)
environ['REMOTE_USER'] = user
return self.app(environ, start_response)
ADDITIONAL_MIDDLEWARE = [RemoteUserMiddleware, ]
AUTH_TYPE = AUTH_REMOTE_USER
AUTH_USER_REGISTRATION = True
Ensure the header used is X-PROXY-REMOTE-USER (without the HTTP).
HI!我是邵磊,您的邮件我已经收到啦,我会在第一时间给您回复哦。
session = requests.session() login_url = "http://<superset_server>:8088/api/v1/security/login" login_data = {'username': 'xxx_user', 'password': 'xxx_pass', 'provider': 'db', 'refresh': True} response = session.post(url=login_url, json=login_data) Then you can obtain csrf_token from response, and use it as a key for the following requests
HI!我是邵磊,您的邮件我已经收到啦,我会在第一时间给您回复哦。
can anyone please tell how to fetch value of guest token in superset_config.py file ...as in url am passing token and that token need to verify in config file so it bypass the login screen of superset for user. http:/localhost.com:8080/login?token=1234&next=/superset/dashboard/11?standalone=true
Thanks in advance!!!!!!
HI!我是邵磊,您的邮件我已经收到啦,我会在第一时间给您回复哦。