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

OAuth: 2FA #2633

Merged
merged 21 commits into from
Jul 12, 2024
Merged

OAuth: 2FA #2633

merged 21 commits into from
Jul 12, 2024

Conversation

matthieusieben
Copy link
Contributor

This PR contains the non-SDK changes of feat-oauth-client (#2483)

@matthieusieben matthieusieben changed the title Feat oauth entryway OAuth: 2FA Jul 10, 2024
fix(oauth): support building from parcel
feat(oauth): add runtime lock support to prevent concurrent session updates
feat(oauth): improve metadata validation
fix(oauth): allow use of handle as login hint
fix: proper parsing of authorization header
feat(oauth): add email 2fa support
feat(oauth): adapt auth UI to match app UI
Copy link
Collaborator

@devinivy devinivy left a comment

Choose a reason for hiding this comment

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

Had a few small notes, but this looks great 👍

return `SHA-${name.slice(-3)}`
default:
throw new TypeError(`Unknown hash algorithm ${name}`)
const buf = await crypto.subtle.digest(`SHA-${name.slice(3)}`, data)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know DigestAlgorithm describes SHAs, but it seems like it would be possible for a new digest algo to be introduced to the type without triggering any issue here. Could we ensure that it begins with "sha" using types (maybe satisfies?) or a runtime assertion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure why I didn't keep the check... i'll add it back

packages/oauth/oauth-client-node/README.md Outdated Show resolved Hide resolved
Comment on lines 54 to 61
// actions={
// onOther && (
// <Button onClick={onOther} aria-label={otherAria}>
// {otherLabel}
// <CaretRight className="h-4 ml-2" />
// </Button>
// )
// }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove this dead code?

className,
...props
}: InputHTMLAttributes<HTMLInputElement>) {
const [id] = useState(generateUniqueId)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If props contains id then the input and label could get out of sync with each other. Perhaps the unique id should be used as a fallback.

Comment on lines 20 to 33
switch (desc) {
case 'Unknown request_uri': // Request was removed from database
case 'This request has expired':
switch (true) {
case desc?.startsWith('Unknown request_uri'): // Request was removed from database
case desc === 'This request has expired':
return 'This sign-in session has expired'
default:
return desc || 'An unknown error occurred'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a small style nit, but I find it quite a bit more common to see a regular old if statement for this kind of thing.

if (
  desc?.startsWith('Unknown request_uri') ||
  desc === 'This request has expired'
) {
  // ...
} else {
  // ...
}

@@ -75,13 +62,15 @@ function parseColor(color: string): undefined | ParsedColor {
return undefined
}

const rgbMatch = color.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/)
const rgbMatch = color.match(/rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want some ^/$ in here? (And same question below for rgba.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made the whole customization more strongly parsed & pre-computed during init of the lib

const requestUri = authorizeUrl.searchParams.get('request_uri')
if (!requestUri) return

// @TODO find a way to actually do this
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just flagging to ensure this TODO is still intended to be here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is fine for now. Improved my comments there.

Comment on lines 113 to 124
const response = await fetch(request)

if (response.status !== 200) {
throw new TypeError(`Failed to fetch client metadata: ${response.status}`)
}

const mime = response.headers.get('content-type')?.split(';')[0].trim()
if (mime !== 'application/json') {
throw new TypeError(`Invalid client metadata content type: ${mime}`)
}

const json: unknown = await response.json()
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the case of an error it looks like the response body would not be read. If I'm not mistaken, in node environments the body should always be read to avoid a leak.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice catch!

@matthieusieben matthieusieben merged commit acc9093 into main Jul 12, 2024
10 checks passed
@matthieusieben matthieusieben deleted the feat-oauth-entryway branch July 12, 2024 15:28
@github-actions github-actions bot mentioned this pull request Jul 12, 2024
estrattonbailey added a commit that referenced this pull request Jul 16, 2024
…cements

* origin/main: (181 commits)
  Minor OAuth client fixes (#2640)
  Version packages (#2639)
  OAuth: 2FA (#2633)
  Version packages (#2622)
  Update data source for `getSuggestedFollowsByActor` (#2630)
  Add in-memory did cache to Ozone backend (#2635)
  Filter out reference lists from `getLists` (#2629)
  lexicons: add missing ozone Tag event type to unions (#2632)
  ✨ Add ozone proxy for getLikes and getRepostedBy (#2624)
  Upgrade pnpm/action-setup in workflows (#2625)
  ✨ Add proxy for user typeahead through ozone (#2612)
  Fix development commands (#2623)
  Add starter packs to post hydration (#2613)
  Social proof blocks (#2603)
  Appview: apply hosting status in getRecord (#2620)
  Add `labelersPref` to `getPreferences` union return types (#2554)
  Version packages (#2618)
  Add new preference and api for bsky app state; also put preference updates within transactional lock regions (#2492)
  remove mentions of sandbox (#2611)
  Appview: simple fix for no-hosted known followers (#2609)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants