Skip to content

Commit

Permalink
Fix auth when connecting via HTTP (#3223)
Browse files Browse the repository at this point in the history
* Fix + test

* Remove print statements + fix import for 3.7

* CHANGELOG

* Remove more print statements

* Add 60 second timeout for uploading data

* Fix test

* Add unsecure token

* Undo diff

* Add CHANGELOG

* Fix on main

* remove __gradio_loader__

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
  • Loading branch information
freddyaboulton and abidlabs authored Feb 17, 2023
1 parent 3530a86 commit 9b2119f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ By [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3165](https://github.
* The `change` event is now triggered when users click the 'Clear All' button of the multiselect DropDown component by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3195](https://github.com/gradio-app/gradio/pull/3195)
* Support Chinese pinyin in Dataframe by [@aliabid94](https://github.com/aliabid94) in [PR 3206](https://github.com/gradio-app/gradio/pull/3206)
* The `clear` event is now triggered when images are cleared by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3218](https://github.com/gradio-app/gradio/pull/3218)
* Fix bug where auth cookies where not sent when connecting to an app via http by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3223](https://github.com/gradio-app/gradio/pull/3223)

## Documentation Changes:
* Sort components in docs by alphabetic order by [@aliabd](https://github.com/aliabd) in [PR 3152](https://github.com/gradio-app/gradio/pull/3152)
Expand Down
7 changes: 6 additions & 1 deletion gradio/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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.")
Expand Down
3 changes: 0 additions & 3 deletions ui/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ declare global {
launchGradioFromSpaces: Function;
gradio_config: Config;
scoped_css_attach: (link: HTMLLinkElement) => void;
__gradio_loader__: Array<{
$set: (args: any) => any;
}>;
__is_colab__: boolean;
}
}
Expand Down
1 change: 0 additions & 1 deletion ui/packages/app/src/Login.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
export let app_mode: boolean;
export let is_space: boolean;
window.__gradio_loader__[id].$set({ status: "complete" });
let username = "";
let password = "";
let incorrect_credentials = false;
Expand Down

0 comments on commit 9b2119f

Please sign in to comment.