-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathoauth2-scopes.ts
More file actions
90 lines (82 loc) · 3.02 KB
/
Copy pathoauth2-scopes.ts
File metadata and controls
90 lines (82 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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];
}