Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

chore: Consolidate scopes to avoid duplication and show only the most permissive scope

Kiran Kcdbf8705c79e
diff --git a/apps/web/app/app.dub.co/(auth)/oauth/authorize/scopes-requested.tsx b/apps/web/app/app.dub.co/(auth)/oauth/authorize/scopes-requested.tsx
index 05ea208fd9..e9d61ee9bf 100644
--- a/apps/web/app/app.dub.co/(auth)/oauth/authorize/scopes-requested.tsx
+++ b/apps/web/app/app.dub.co/(auth)/oauth/authorize/scopes-requested.tsx
@@ -13,7 +13,7 @@ export const ScopesRequested = ({ scopes }: ScopesProps) => {
scopes.push("user.read");
}
- const scopeWithDescriptions = scopes.map((scope) => {
+ const scopeWithDescriptions = consolidateScopes(scopes).map((scope) => {
return {
scope,
description: OAUTH_SCOPE_DESCRIPTIONS[scope],
@@ -48,3 +48,20 @@ export const ScopesRequested = ({ scopes }: ScopesProps) => {
</>
);
};
+
+// Consolidate scopes to avoid duplication and show only the most permissive scope
+const consolidateScopes = (scopes: string[]) => {
+ const consolidated = new Set();
+
+ scopes.forEach((scope) => {
+ const [resource, action] = scope.split(".");
+
+ if (action === "write") {
+ consolidated.add(`${resource}.write`);
+ } else if (action === "read" && !consolidated.has(`${resource}.write`)) {
+ consolidated.add(`${resource}.read`);
+ }
+ });
+
+ return Array.from(consolidated) as string[];
+};
diff --git a/apps/web/lib/api/oauth/constants.ts b/apps/web/lib/api/oauth/constants.ts
index 9d23e62d42..f26acced16 100644
--- a/apps/web/lib/api/oauth/constants.ts
+++ b/apps/web/lib/api/oauth/constants.ts
@@ -16,6 +16,8 @@ export const OAUTH_ACCESS_TOKEN_PREFIX = "dub_access_token_";
export const OAUTH_REFRESH_TOKEN_PREFIX = "dub_refresh_token_";
// These are the scopes an OAuth app can request on behalf of an user
+// Keep it separate from the actual scopes to avoid confusion
+// We don't all the scopes to be requested by an app
export const OAUTH_SCOPES = [
"workspaces.read",
"workspaces.write",