hoogenm commented on issue #36117:
URL: https://github.com/apache/superset/issues/36117#issuecomment-5206234499

   I tried the code below for Superset 6.1 and it worked again.
   
   - Note that this code requires pre-creation of new users (no automatic / 
self-registration).
   - Note that it uses an HTTP header name, not an ENV variable name.
   - I'm not sure if this would be safe if used without an authentication proxy 
in front (but, using an auth proxy is the whole idea with auth_remote_user)
   - I'm not sure if setting a request attribute on flask.g is useful or 
necessary (it was an AI suggestion that seemed harmless to me). Other than 
this, I think the code is very concise/minimal.
   
   I hope it may help others with ideas on how to keep and future-proof 
auth_remote_user support for Superset.
   
   ```
   from flask_appbuilder.security.manager import AUTH_REMOTE_USER
   from flask_login import login_user
   from flask import g,request
   
   AUTH_TYPE = AUTH_REMOTE_USER
   AUTH_REMOTE_USER_REQUEST_HEADER = 'X-Auth-Request-Email'
   AUTH_USER_REGISTRATION = False
   
   def init_remote_user_auth(app):
       @app.before_request
       def ensure_remote_user():
           # Prevent running multiple times per request cycle
           if getattr(g, '_remote_user_checked', False):
               return
           g._remote_user_checked = True
           username = request.headers.get(AUTH_REMOTE_USER_REQUEST_HEADER)
           if not username:
               return
           user = app.appbuilder.sm.find_user(username=username)
           login_user(user, remember=False)
   
   FLASK_APP_MUTATOR = init_remote_user_auth
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to