Repository: gradio-app/gradio

Issue:
Cannot login to application when deployed on-premise
### Describe the bug

I cannot login to my gradio app when it's deployed in docker container on any server. I've tried on 2 different machines with different docker versions. After passing my credentials I'm not redirected to main but login page is refreshed. I've encountered this problem only on versions 3.17.x and 3.18.0 and only when deployed on some server. Everything works perfectly fine on my local machine, both when run locally or via docker.  

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Reproduction

1. Dockerize gradio app with gradio authentication enabled and deploy on some server while exposing it
2. Open the app in your browser
3. Log in
4. Encounter page refresh with no redirection to actual app

### Screenshot

_No response_

### Logs

```shell
I have no logs for this. There's no error or logs neither on python side nor browser.
```


### System Info

```shell
Gradio version: 3.17.x, 3.18.0 (it worked previously on 3.16.2)
```


### Severity

blocking upgrade to latest gradio version


Discussion:
Hi @Norbiox !

Do you have third party cookies enabled in your browser?

If you open the developer tools, there should be a request to the `login` route, would be helpful to see what that looks like to debug!
Hi,
Yes, I have enabled third party cookies.
I can't find this request. I'm attaching screenshots from before login and immediately after.

Before:
![before_login](https://user-images.githubusercontent.com/22893882/218649969-9713b5c8-e2b0-47f1-93e8-33710aa32028.png)

After:
![after_login](https://user-images.githubusercontent.com/22893882/218649756-c0b6b859-9e7f-4646-975b-02d184e8f99d.png)

I had the same issue and I was getting this warning in the firefox console:
`Cookie “access-token” has been rejected because a non-HTTPS cookie can’t be set as “secure”.`

Downgrading gradio to 3.16.2 allows login but obviously it is not a very good solution.
If I check the cookie set by gradio with version 3.16.2 it is indeed *not* set as "secure"

The change to make the cookie secure and "sameSite" was added in [this commit ](https://github.com/gradio-app/gradio/commit/9ccfef05421d1733400e3e73d83c756213f2ef29)
Though the commit message does mention it or explain why, as far as I can tell
Thanks for getting back to me @Norbiox and @nerochiaro ! 

I'm having trouble reproducing this issue. 

I created this simple [app ](https://github.com/freddyaboulton/graido-auth) with auth (ignore the typo in the repo name 🙈). It is packaged with Docker and works well for me locally and when I deployed it to this url: https://gradio-auth.onrender.com/ . Credentials `admin/admin`

I tried in Chrome with and without incognito mode and also microsoft edge. I was able to log in correctly. There's a gif of that here: 

![gradio_auth_docker_server](https://user-images.githubusercontent.com/41651716/218817823-c0a5f5ff-bad1-44c8-8856-8067dcdd5dbc.gif)

My guess is that for some reason, your browser is rejecting the gradio cookie set during a successful login? 


Resolving patch:
diff --git a/gradio/routes.py b/gradio/routes.py
--- a/gradio/routes.py
+++ b/gradio/routes.py
@@ -148,7 +148,9 @@ def create_app(blocks: gradio.Blocks) -> App:
         @app.get("/user")
         @app.get("/user/")
         def get_current_user(request: fastapi.Request) -> Optional[str]:
-            token = request.cookies.get("access-token")
+            token = request.cookies.get("access-token") or request.cookies.get(
+                "access-token-unsecure"
+            )
             return app.tokens.get(token)
 
         @app.get("/login_check")
@@ -196,6 +198,9 @@ def login(form_data: OAuth2PasswordRequestForm = Depends()):
                     samesite="none",
                     secure=True,
                 )
+                response.set_cookie(
+                    key="access-token-unsecure", value=token, httponly=True
+                )
                 return response
             else:
                 raise HTTPException(status_code=400, detail="Incorrect credentials.")


Test patch: