Repository navigation
feat(auth): ask for more OAuth scopes later with requestScopes and withScope - #42
Open
spacedevin wants to merge 1 commit into
Open
spacedevin wants to merge 1 commit into
spacedevin wants to merge 1 commit into
Conversation
…thScope Hypery's authorize endpoint already signs in silently for granted scopes, shows consent only for new ones and merges the grant, but the SDK had no way to use it. A 403 insufficient_scope now parses into a typed InsufficientScopeError carrying the required scopes; requestScopes runs the PKCE + state flow for the union of granted and new scopes by popup, redirect or a host-supplied openAuthUrl (native shells), and replaces the stored token; withScope retries once after the upgrade; grantedScopes exposes the token response's scope.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hypery's authorize endpoint already supports incremental consent (granted scopes sign in silently, new ones show consent, the grant is merged). The SDK now uses it.
InsufficientScopeError(code,status: 403,requiredScopes) from a Hypery403{ error: { code: 'insufficient_scope', message: 'OAuth token requires the X scope' } }. Scopes come fromerror.scope(s), an RFC 6750WWW-Authenticate: Bearer error="insufficient_scope", scope="…", or the message.parseInsufficientScope,throwIfInsufficientScope,isInsufficientScopeError.requestScopes(scopes, opts): PKCE + state authorize for the union of current and requested scopes, by'popup','redirect'or'external'(a hostopenUrl(authorizeUrl, redirectUri) => Promise<callbackUrl | null>, e.g. Tauri'shypery_auth_start). The new token replaces the stored one.withScope(scope, fn): on a thrownInsufficientScopeErroror a 403 Response, requests once and retries.grantedScopeson the context, andAuthTokens.scopesfrom the token response'sscope(kept across a refresh that omits it).config.openAuthUrl; contextgrantedScopes,requestScopes,withScope; the popup callback now relayserrorso a denial closes the popup.Docs in
docs/SCOPES.md(+ PROVIDER, README), example inexamples/scopes/narrate.tsx, tests insrc/lib/__tests__/scopes.test.ts.Local:
bun test src121 pass,tsc --noEmit,npm run typecheck:examples,npm run test:tish,npm run build.