-
Notifications
You must be signed in to change notification settings - Fork 242
feat: OAuth2 server consent & device verification screens #3087
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
45a95e5
feat: OAuth2 server consent & device verification screens
ChiragAgg5k bce070c
fix: prevent OAuth2 consent/device card from collapsing
ChiragAgg5k 7bcc6e9
fix: harden OAuth2 consent/device flows against stale requests
ChiragAgg5k cd81387
fix: pin ws to ^8.21.0 to clear high-severity audit advisory
ChiragAgg5k 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import type { ComponentType } from 'svelte'; | ||
| import { | ||
| IconShieldCheck, | ||
| IconUser, | ||
| IconMail, | ||
| IconIdentification, | ||
| IconKey | ||
| } from '@appwrite.io/pink-icons-svelte'; | ||
|
|
||
| export interface ScopeDescriptor { | ||
| id: string; | ||
| title: string; | ||
| description: string; | ||
| icon: ComponentType; | ||
| } | ||
|
|
||
| /** | ||
| * This consent screen always authorizes against the Appwrite **console** | ||
| * project. On the server, any OAuth2 access token issued for the console | ||
| * project is granted the full `users` (member) role — the same access a | ||
| * signed-in console session has — regardless of the OIDC scopes requested. | ||
| * The `openid`/`profile`/`email` scopes only shape the OIDC identity claims; | ||
| * they do NOT limit what the application can do. So the consent screen must | ||
| * lead with the full-access reality rather than implying read-only access. | ||
| */ | ||
| export const FULL_ACCESS_SCOPE: ScopeDescriptor = { | ||
| id: '__full_access__', | ||
| title: 'Full access to your account', | ||
| description: 'Manage your organizations, projects, and all their resources on your behalf.', | ||
| icon: IconShieldCheck | ||
| }; | ||
|
|
||
| const BUILTIN_SCOPES: Record<string, Omit<ScopeDescriptor, 'id'>> = { | ||
| openid: { | ||
| title: 'Verify your identity', | ||
| description: 'Confirm who you are using your Appwrite account.', | ||
| icon: IconIdentification | ||
| }, | ||
| profile: { | ||
| title: 'View your profile', | ||
| description: 'Read your name and profile details.', | ||
| icon: IconUser | ||
| }, | ||
| email: { | ||
| title: 'View your email address', | ||
| description: 'Read the email address associated with your account.', | ||
| icon: IconMail | ||
| } | ||
| }; | ||
|
|
||
| function titleizeScope(scope: string): string { | ||
| const cleaned = scope.replace(/[._:-]+/g, ' ').trim(); | ||
| if (!cleaned) return scope; | ||
| return cleaned.charAt(0).toUpperCase() + cleaned.slice(1); | ||
| } | ||
|
|
||
| export function describeScope(scope: string): ScopeDescriptor { | ||
| const builtin = BUILTIN_SCOPES[scope]; | ||
| if (builtin) { | ||
| return { id: scope, ...builtin }; | ||
| } | ||
| return { | ||
| id: scope, | ||
| title: titleizeScope(scope), | ||
| description: `Access to ${scope}.`, | ||
| icon: IconKey | ||
| }; | ||
| } | ||
|
|
||
| export function describeScopes(scopes: string[]): ScopeDescriptor[] { | ||
| return scopes.map(describeScope); | ||
| } | ||
|
|
||
| // Identity scopes shown (in this order) as secondary detail beneath the | ||
| // full-access item. `openid` is intentionally omitted — identity verification | ||
| // is implied by full account access, so listing it separately is redundant. | ||
| const CONSENT_IDENTITY_SCOPES = ['profile', 'email'] as const; | ||
|
|
||
| /** | ||
| * Build the permission list for the console OAuth2 consent screen. Always leads | ||
| * with the full-access item (the true effect of authorizing), followed by the | ||
| * identity scopes the application actually reads (profile, email) when present. | ||
| */ | ||
| export function describeConsentScopes(scopes: string[]): ScopeDescriptor[] { | ||
| const requested = new Set(scopes); | ||
| const identity = CONSENT_IDENTITY_SCOPES.filter((scope) => requested.has(scope)).map( | ||
| describeScope | ||
| ); | ||
| return [FULL_ACCESS_SCOPE, ...identity]; | ||
| } |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| <script lang="ts"> | ||
| import { base } from '$app/paths'; | ||
| import { app } from '$lib/stores/app'; | ||
| import { loading } from '$routes/store'; | ||
| import { Typography } from '@appwrite.io/pink-svelte'; | ||
|
|
||
| loading.set(false); | ||
| </script> | ||
|
|
||
| <div class="auth-bg"> | ||
| <section> | ||
| <div class="console-container"> | ||
| <slot /> | ||
| </div> | ||
| </section> | ||
| <footer> | ||
| <Typography.Eyebrow color="--fgcolor-neutral-secondary">POWERED BY</Typography.Eyebrow> | ||
| {#if $app.themeInUse === 'dark'} | ||
| <img | ||
| src="{base}/images/appwrite-logo-dark.svg" | ||
| width="120" | ||
| height="22" | ||
| alt="Appwrite Logo" /> | ||
| {:else} | ||
| <img | ||
| src="{base}/images/appwrite-logo-light.svg" | ||
| width="120" | ||
| height="22" | ||
| alt="Appwrite Logo" /> | ||
| {/if} | ||
| </footer> | ||
| </div> | ||
|
|
||
| <style lang="scss"> | ||
| .auth-bg { | ||
| position: fixed; | ||
| background: var(--bgcolor-neutral-primary, #fff); | ||
| background-size: cover; | ||
| top: 0; | ||
| left: 0; | ||
| height: 100%; | ||
| width: 100%; | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| justify-content: center; | ||
| justify-content: space-between; | ||
| section { | ||
| flex: 1; | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
| footer { | ||
| padding: 2rem 1rem; | ||
| display: flex; | ||
| gap: 0.5rem; | ||
| justify-content: center; | ||
| align-items: center; | ||
| flex-wrap: wrap; | ||
| } | ||
| } | ||
| </style> |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.