4ahul commented on issue #4393:
URL: https://github.com/apache/superset/issues/4393#issuecomment-2595929889

   > 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!!!!!!
   
    CODE : 
   
   ``
   
   `class TokenManager:
       _instance = None
   
       def __new__(cls):
           if cls._instance is None:
               cls._instance = super(TokenManager, cls).__new__(cls)
               cls._instance.auth_token = None
               cls._instance.csrf_token = None
           return cls._instance
   
       def set_auth_token(self, token):
           self.auth_token = token
       
       def get_auth_token(self):
           return self.auth_token
       
       def set_csrf_token(self, token):
           self.csrf_token = token
   
       def get_csrf_token(self):
           return self.csrf_token
   
   token_manager = TokenManager()`
   
   `@csrf_exempt 
   def getGuestToken(request):
   
       headers = {
           "Authorization":f"Bearer {token_manager.get_auth_token()}",
       }
   
       try:
           body = json.loads(request.body)
           GuestTokenPayload = getGuestTokenRequest(**body)
   
           api_instance = API()
   
           try:
               response = api_instance.post(request,endpoint=GUEST_TOKEN, 
headers=headers, body=asdict(GuestTokenPayload))
               return response
           
           except requests.RequestException as e:
               return Response({"error": str(e)}, status = 500)
       
       except requests.RequestException as e:
           return Response({"error": str(e)}, status= 500)
    `
   
   
   get access token from login response and pass it in header while calling 
guest token api 
   
   
   example body for guest token : 
   
   `{
       "resources": [
           {
               "type": "dashboard",
               "id": "c9a79243-1d31-4fe3-afc0-5302b8b7546a"
           }
       ],
       "rls": [],
       "user": {
           "username": "admin",
           "first_name": "admin",
           "last_name": "user"
       }
   }`


-- 
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