Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When authenticating with HF OAuth, stay in same tab #7887

Merged
merged 22 commits into from
Apr 10, 2024

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Mar 29, 2024

Related to this slack thread (internal), https://github.com/huggingface/moon-landing/issues/9054 (internal) and https://github.com/huggingface/moon-landing/pull/9164 (internal).

Thanks to @coyotte508's work in moon-landing , we do not need to open a new tab to login with OAuth in a Gradio Space anymore! This PR simply updates the JS code in LoginButton to stay in the same tab during the process. I've also updated the cookie key to invalidate all cookies (necessary). Not a big problem anyway since it will only impact Spaces that will upgrade their Gradio version.

Test Space: https://huggingface.co/spaces/templates/gradio-oauth. To test the full OAuth workflow, don't forget to revoke the permission first in https://huggingface.co/settings/connected-applications.

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Mar 29, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detecting...

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/7cdb53fee862c584ec26b7d6834fdce0d810a196/gradio-4.26.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@7cdb53fee862c584ec26b7d6834fdce0d810a196#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Mar 29, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/app patch
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

When authenticating with HF OAuth, stay in same tab

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@abidlabs
Copy link
Member

This LGTM. But just a heads up, one issue I noticed in the test space was that I couldn't scroll down to give permissions to specific organizations and then click accept:

image

I think this is due to way that the iframe is set up. Until we fix it, we may want to keep opening in a new tab.

@abidlabs abidlabs added the v: patch A change that requires a patch release label Mar 29, 2024
@freddyaboulton
Copy link
Collaborator

@Wauplin do you know if that issue pointed out by @abidlabs will be fixed in the hub?

@Wauplin
Copy link
Contributor Author

Wauplin commented Apr 2, 2024

@abidlabs @freddyaboulton I also noticed this issue and reported it on slack (internal).

Copy link
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good left a comment about the iframe options.

We also need to 'reset' the scrolling when we go back to gradio. This should be straightforward because when we go back to gradio it is a fresh page load, so we can do it somewhere like this:
https://github.com/gradio-app/gradio/blob/main/js/app/index.html#L60-L65

The code to disable scrolling is like so:

window.parent?.postMessage({type: "SET_SCROLLING", enabled: false})

Comment on lines 103 to 104
uri = buttonValue === BUTTON_DEFAULT_VALUE ? '/login/huggingface' : '/logout';
window.location.assign(uri + window.location.search);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we will need to set the scrolling of the iframe as mention in @coyotte508's PR.

We should be able to add this as the first line of this function:

window.parent?.postMessage({type: "SET_SCROLLING", enabled: true})

Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the SET_SCROLLING comments @Wauplin ! This looks good to me cc @pngwn

@pngwn
Copy link
Member

pngwn commented Apr 8, 2024

I think it is still not scrolling. lmk if/ when you want me to take a look @Wauplin.

@Wauplin
Copy link
Contributor Author

Wauplin commented Apr 8, 2024

No it's not working indeed 😕 I posted a message on slack (internal), you might have an idea @pngwn?

@coyotte508

This comment was marked as resolved.

@Wauplin
Copy link
Contributor Author

Wauplin commented Apr 9, 2024

@pete @coyotte508 Thanks for your help! Scrolling now works on this demo Space: https://huggingface.co/spaces/templates/gradio-oauth. I still had to add a 500ms timeout on the redirection to make sure the message is posted (see here). I don't think it downgrades UX but it is not 100% safe on slow connections. Should be ok though? 🙄

@coyotte508
Copy link

Posting the message shouldn't be related to the speed of the internet connection, it's child iframe communicating with parent iframe, so I think slow connections will be ok

@pngwn
Copy link
Member

pngwn commented Apr 9, 2024

I'm surprised that such a long timeout is required. I don't think it will cause issues for slow connections. Technically a low machine might have issues but I don't think it is a major concern. A wait of some amount of time is expected though as the message is sent and forgotten about, it doesn't wait for the parent to process it.

Copy link
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, and I have tested the demo space and it seems to work great, even on tiny screens! Thanks for battling with this one @Wauplin! And thanks for your help on the hub side @coyotte508!

gradio/components/login_button.py Outdated Show resolved Hide resolved
@Wauplin
Copy link
Contributor Author

Wauplin commented Apr 10, 2024

I'm surprised that such a long timeout is required.

TBH I only tried with this timeout. If you think it's too long I can update. It's just that it's annoying to test different values (need to push commit, wait for gradio build, then update the Space, wait for rebuild, then test). So if 500ms is fine, I'll keep it 😄

@pete
Copy link

pete commented Apr 10, 2024

@pete @coyotte508 Thanks for your help!

You are welcome, but I cannot take credit.

@pngwn
Copy link
Member

pngwn commented Apr 10, 2024

So if 500ms is fine, I'll keep it

it's fine, we'll keep an eye on it.

@pngwn pngwn changed the title OAuth: stay in same tab When authenticating with HF OAuth, stay in same tab Apr 10, 2024
@Wauplin
Copy link
Contributor Author

Wauplin commented Apr 10, 2024

Great, then feel free to merge whenever it's ready/approved :)

@pngwn pngwn merged commit 5f0248e into gradio-app:main Apr 10, 2024
7 of 8 checks passed
@pngwn pngwn mentioned this pull request Apr 10, 2024
freddyaboulton pushed a commit that referenced this pull request Apr 11, 2024
* OAuth: stay in same tab

* add changeset

* add changeset

* typo

* scroll

* add changeset

* lint

* test

* test with timeout

* log

* new test

* fix origin in postMessage

* with timeout

* shoud be fine

* lint

* lint

* remove logs

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v: patch A change that requires a patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants