Need Help Utilizing Gradio Auth page on HF space

I’m having some trouble with a gradio HuggingFace space that uses the builtin Gradio auth page to pass a username and API token from a third party service.

How can I store each user’s token and username in a dict that is tied to the user’s login session? This is so I can look up their token/username later for doing API calls, without user’s accidentally using a previous user’s data.

My first solution was using a form of request.username to get a unique session, but this seemed to only be working when the user was logged in to HF. I cannot find a way to use the OS library to generate a unique session ID otherwise, but I tried several methods in this terminal (ttw - a Hugging Face Space by mikeee)

I then tried to get the current user’s IP but it seems like gr.Request is not available at time of login, I was not able to pass (request : gr.Request) while in the authentication step. The login page would succesfully take the credentials but would never load the app, it would get stuck.

I think I need to be using gr.State() with the token and username but the documentation on it’s utilization has been a bit confusing. An example of using it to store log in details passed through the builtin Auth page would be a big help.

This is similar to this issue ftr (How to persist Gradio authentication username information on the next page after login)

Last time I asked a similar question on How to persist Gradio authentication username information on the next page after login URL, I didn’t get a reply and the options I tried didn’t work. It was an optional thing that I was planning to do. So, I didn’t search for later solutions. It was a long time ago, so probably there may be some other recent solutions. But, at that time, I couldn’t find.

Hey so I was overcomplicating this a lot because of a different bug that I was encountering (gradio auth page is not working in safari or some private tabs).

global credentials{}
credentials[username] = pass

This is to save the password of the login.

Then you can look up the auth username anytime with/

Function(request : gr.Request)
request.username

and you can get the password/token back with
credentials[request.username]

good luck!

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.