-
Notifications
You must be signed in to change notification settings - Fork 230
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
💥 Fix oauth name & username mixup #1050
Open
coyotte508
wants to merge
12
commits into
main
Choose a base branch
from
fix-avatar-url
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+284
−80
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2cd06cd
💥 Fix avatar name & username mixup
coyotte508 ef546f7
💥 Actually use raw API result
coyotte508 91ab753
✨ Also work in node context
coyotte508 0ee5ffa
✨ Other features to be available in node context
coyotte508 be01749
💡 Comment OAuth fields
coyotte508 e861740
✅ Add oauth test
coyotte508 c7cb4bb
🚨
coyotte508 0e079ab
Merge branch 'main' into fix-avatar-url
coyotte508 0bf77c6
✅ Fix test
coyotte508 81d2c3c
Merge branch 'main' into fix-avatar-url
coyotte508 cf8abd8
Merge branch 'main' into fix-avatar-url
coyotte508 91dc0cc
⚗️ try full url now for avatar
coyotte508 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { TEST_COOKIE, TEST_HUB_URL } from "../test/consts"; | ||
import { oauthLoginUrl } from "./oauth-login-url"; | ||
import { oauthHandleRedirect } from "./oauth-handle-redirect"; | ||
|
||
describe("oauthHandleRedirect", () => { | ||
it("should work", async () => { | ||
const localStorage = { | ||
nonce: undefined, | ||
codeVerifier: undefined, | ||
}; | ||
const url = await oauthLoginUrl({ | ||
clientId: "dummy-app", | ||
redirectUrl: "http://localhost:3000", | ||
localStorage, | ||
scopes: "openid profile email", | ||
hubUrl: TEST_HUB_URL, | ||
}); | ||
const resp = await fetch(url, { | ||
method: "POST", | ||
headers: { | ||
Cookie: `token=${TEST_COOKIE}`, | ||
}, | ||
redirect: "manual", | ||
}); | ||
if (resp.status !== 303) { | ||
throw new Error(`Failed to fetch url ${url}: ${resp.status} ${resp.statusText}`); | ||
} | ||
const location = resp.headers.get("Location"); | ||
if (!location) { | ||
throw new Error(`No location header in response`); | ||
} | ||
const result = await oauthHandleRedirect({ | ||
redirectedUrl: location, | ||
codeVerifier: localStorage.codeVerifier, | ||
nonce: localStorage.nonce, | ||
hubUrl: TEST_HUB_URL, | ||
}); | ||
|
||
if (!result) { | ||
throw new Error("Expected result to be defined"); | ||
} | ||
expect(result.accessToken).toEqual(expect.any(String)); | ||
expect(result.accessTokenExpiresAt).toBeInstanceOf(Date); | ||
expect(result.accessTokenExpiresAt.getTime()).toBeGreaterThan(Date.now()); | ||
expect(result.scope).toEqual(expect.any(String)); | ||
expect(result.userInfo).toEqual({ | ||
sub: "62f264b9f3c90f4b6514a269", | ||
name: "@huggingface/hub CI bot", | ||
preferred_username: "hub.js", | ||
email_verified: true, | ||
email: "[email protected]", | ||
isPro: false, | ||
picture: "https://hub-ci.huggingface.co/avatars/934b830e9fdaa879487852f79eef7165.svg", | ||
profile: "https://hub-ci.huggingface.co/hub.js", | ||
website: "https://github.com/huggingface/hub.js", | ||
orgs: [], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how of curiosity, is there any reason to do a POST instead of a GET (or vice-versa) here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The POST is to grant the oauth app the authorization. GET works for subsequent calls, but not the first time ever for the user <-> app tuple