Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Chore/fix oauth app api auth (#28093)

Joshen Lim9081324666b2
diff --git a/apps/studio/data/api-authorization/api-authorization-approve-mutation.ts b/apps/studio/data/api-authorization/api-authorization-approve-mutation.ts
index c8f027bef98..68cfda4c378 100644
--- a/apps/studio/data/api-authorization/api-authorization-approve-mutation.ts
+++ b/apps/studio/data/api-authorization/api-authorization-approve-mutation.ts
@@ -21,7 +21,6 @@ export async function approveApiAuthorization({ id, slug }: ApiAuthorizationAppr
// @ts-ignore [Joshen] Endpoint doesnt need slug in the path params, but the endpoint path requires slug
// it's a little weird, will need API to decide if they wanna shift this route outside of the {slug} endpoint
params: { path: { slug, id }, query: { skip_browser_redirect: true } },
- body: { organization_id: slug },
})
if (error) handleError(error)
diff --git a/apps/studio/data/api-authorization/api-authorization-query.ts b/apps/studio/data/api-authorization/api-authorization-query.ts
index fe72e9343e8..529302cb95e 100644
--- a/apps/studio/data/api-authorization/api-authorization-query.ts
+++ b/apps/studio/data/api-authorization/api-authorization-query.ts
@@ -2,12 +2,10 @@ import type { OAuthScope } from '@supabase/shared-types/out/constants'
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
-import { API_URL } from 'lib/constants'
import { resourceKeys } from './keys'
export type ApiAuthorizationVariables = {
id?: string
- slug?: string
}
export type ApiAuthorizationResponse = {
@@ -22,15 +20,13 @@ export type ApiAuthorizationResponse = {
}
export async function getApiAuthorizationDetails(
- { id, slug }: ApiAuthorizationVariables,
+ { id }: ApiAuthorizationVariables,
signal?: AbortSignal
) {
if (!id) throw new Error('Authorization ID is required')
- const { data, error } = await get('/platform/organizations/{slug}/oauth/authorizations/{id}', {
- // @ts-ignore [Joshen] Endpoint doesnt need slug in the path params, but the endpoint path requires slug
- // it's a little weird, will need API to decide if they wanna shift this route outside of the {slug} endpoint
- params: { path: { slug, id } },
+ const { data, error } = await get('/platform/oauth/authorizations/{id}', {
+ params: { path: { id } },
signal,
})
@@ -42,12 +38,12 @@ export type ResourceData = Awaited<ReturnType<typeof getApiAuthorizationDetails>
export type ResourceError = { errorEventId: string; message: string }
export const useApiAuthorizationQuery = <TData = ResourceData>(
- { id, slug }: ApiAuthorizationVariables,
+ { id }: ApiAuthorizationVariables,
{ enabled = true, ...options }: UseQueryOptions<ResourceData, ResourceError, TData> = {}
) =>
useQuery<ResourceData, ResourceError, TData>(
resourceKeys.resource(id),
- ({ signal }) => getApiAuthorizationDetails({ id, slug }, signal),
+ ({ signal }) => getApiAuthorizationDetails({ id }, signal),
{
enabled: enabled && typeof id !== 'undefined',
...options,
diff --git a/apps/studio/data/permissions/permissions-query.ts b/apps/studio/data/permissions/permissions-query.ts
index 1a3e2ff563c..61614607aa5 100644
--- a/apps/studio/data/permissions/permissions-query.ts
+++ b/apps/studio/data/permissions/permissions-query.ts
@@ -10,7 +10,9 @@ export type PermissionsResponse = Permission[]
export async function getPermissions(signal?: AbortSignal) {
const { data, error } = await get('/platform/profile/permissions', { signal })
if (error) handleError(error)
- return data as PermissionsResponse
+
+ // [Joshen] TODO: Type this properly from the API
+ return data as unknown as PermissionsResponse
}
export type PermissionsData = Awaited<ReturnType<typeof getPermissions>>
diff --git a/apps/studio/pages/authorize.tsx b/apps/studio/pages/authorize.tsx
index c3b7c795d94..54d31f672c4 100644
--- a/apps/studio/pages/authorize.tsx
+++ b/apps/studio/pages/authorize.tsx
@@ -25,12 +25,7 @@ const APIAuthorizationPage: NextPageWithLayout = () => {
const [selectedOrgSlug, setSelectedOrgSlug] = useState<string>()
const { data: organizations, isLoading: isLoadingOrganizations } = useOrganizationsQuery()
- const {
- data: requester,
- isLoading,
- isError,
- error,
- } = useApiAuthorizationQuery({ id: auth_id, slug: selectedOrgSlug })
+ const { data: requester, isLoading, isError, error } = useApiAuthorizationQuery({ id: auth_id })
const isApproved = (requester?.approved_at ?? null) !== null
const isExpired = dayjs().isAfter(dayjs(requester?.expires_at))
@@ -78,7 +73,7 @@ const APIAuthorizationPage: NextPageWithLayout = () => {
if (isLoading) {
return (
<FormPanel header={<p>Authorize API access</p>}>
- <div className="w-[500px] px-8 py-6 space-y-2">
+ <div className="px-8 py-6 space-y-2">
<ShimmeringLoader />
<ShimmeringLoader className="w-3/4" />
<ShimmeringLoader className="w-1/2" />
@@ -90,7 +85,7 @@ const APIAuthorizationPage: NextPageWithLayout = () => {
if (auth_id === undefined) {
return (
<FormPanel header={<p>Authorization for API access</p>}>
- <div className="w-[500px] px-8 py-6">
+ <div className="px-8 py-6">
<Alert withIcon variant="warning" title="Missing authorization ID">
Please provide a valid authorization ID in the URL
</Alert>
@@ -102,7 +97,7 @@ const APIAuthorizationPage: NextPageWithLayout = () => {
if (isError) {
return (
<FormPanel header={<p>Authorize API access</p>}>
- <div className="w-[500px] px-8 py-6">
+ <div className="px-8 py-6">
<Alert
withIcon
variant="warning"
@@ -123,7 +118,7 @@ const APIAuthorizationPage: NextPageWithLayout = () => {
return (
<FormPanel header={<p>Authorize API access for {requester?.name}</p>}>
- <div className="w-full md:w-[500px] px-8 py-6 space-y-8">
+ <div className="w-full px-8 py-6 space-y-8">
<Alert withIcon variant="success" title="This authorization request has been approved">
<p>
{requester.name} has read and write access to the organization "
diff --git a/packages/api-types/types/api.d.ts b/packages/api-types/types/api.d.ts
index 69b7e974492..8bb1e54da2c 100644
--- a/packages/api-types/types/api.d.ts
+++ b/packages/api-types/types/api.d.ts
@@ -234,6 +234,10 @@ export interface paths {
/** Get an aggregated data of interest across all notifications for the user */
get: operations['NotificationsController_getNotificationsSummary']
}
+ '/platform/oauth/authorizations/{id}': {
+ /** [Beta] Get oauth app authorization request */
+ get: operations['OAuthAuthorizationsController_getAuthorizationRequest']
+ }
'/platform/organizations': {
/** Gets user's organizations */
get: operations['OrganizationsController_getOrganizations']
@@ -265,7 +269,7 @@ export interface paths {
get: operations['OrgInvoicesController_getUpcomingInvoice']
}
'/platform/organizations/{slug}/billing/plans': {
- /** Gets subscription plans */
+ /** Gets subscription Plans */
get: operations['OrgPlansController_getAvailablePlans']
}
'/platform/organizations/{slug}/billing/subscription': {
@@ -386,12 +390,10 @@ export interface paths {
post: operations['OAuthAppsController_revokeAuthorizedOAuthApp']
}
'/platform/organizations/{slug}/oauth/authorizations/{id}': {
- /** [Beta] Get oauth app authorization request */
- get: operations['AuthorizationsController_getAuthorizationRequest']
/** [Beta] Approve oauth app authorization request */
- post: operations['AuthorizationsController_approveAuthorizationRequest']
+ post: operations['OrganizationOAuthAuthorizationsController_approveAuthorizationRequest']
/** [Beta] Decline oauth app authorization request */
- delete: operations['AuthorizationsController_declineAuthorizationRequest']
+ delete: operations['OrganizationOAuthAuthorizationsController_declineAuthorizationRequest']
}
'/platform/organizations/{slug}/payments': {
/** Gets Stripe payment methods for the given organization */
@@ -2067,6 +2069,16 @@ export type webhooks = Record<string, never>
export interface components {
schemas: {
+ AccessControlPermission: {
+ actions: string[] | null
+ condition: Record<string, never>
+ organization_id: number | null
+ organization_slug: string
+ project_ids: number[] | null
+ project_refs: string[] | null
+ resources: string[] | null
+ restrictive: boolean | null
+ }
AccessToken: {
created_at: string
id: number
@@ -2314,9 +2326,6 @@ export interface components {
name: string
version: string
}
- AuthorizationsApproveBody: {
- organization_id: string
- }
AutoApiService: {
app: {
id?: number
@@ -2654,7 +2663,8 @@ export interface components {
db_sql?: string
desired_instance_size?: components['schemas']['DesiredInstanceSize']
name: string
- org_id: number
+ org_id?: number
+ organization_slug?: string
}
CreateProjectResponse: {
anon_key: string
@@ -2663,17 +2673,18 @@ export interface components {
endpoint: string
id: number
infra_compute_size?: components['schemas']['DbInstanceSize']
- inserted_at: string
+ inserted_at: string | null
is_branch_enabled: boolean
- is_physical_backups_enabled: boolean
+ is_physical_backups_enabled: boolean | null
name: string
organization_id: number
+ organization_slug: string
preview_branch_refs: string[]
ref: string
region: string
service_key: string
status: string
- subscription_id: string
+ subscription_id: string | null
}
CreateProviderBody: {
attribute_mapping?: components['schemas']['AttributeMapping']
@@ -2978,7 +2989,7 @@ export interface components {
id: string
}
/**
- * @description Desired compute size, will use default size if not defined. Paid plans only.
+ * @description Desired instance size, will use default size if not defined. Paid Plans only.
* @enum {string}
*/
DesiredInstanceSize:
@@ -3108,13 +3119,25 @@ export interface components {
verify_jwt?: boolean
version: number
}
- GetAuthorizationResponse: {
+ GetMetricsBody: {
+ /** @enum {string} */
+ interval: '1d' | '3d' | '7d'
+ /** @enum {string} */
+ metric: 'user_queries'
+ project_refs: string[]
+ region: string
+ }
+ GetMetricsResponse: {
+ metrics: components['schemas']['ProjectMetric'][]
+ }
+ GetOAuthAuthorizationResponse: {
approved_at?: string
approved_organization_slug?: string
domain: string
expires_at: string
icon?: string
name: string
+ organization_slug?: string
scopes?: (
| 'analytics:read'
| 'analytics:write'
@@ -3141,17 +3164,6 @@ export interface components {
)[]
website: string
}
- GetMetricsBody: {
- /** @enum {string} */
- interval: '1d' | '3d' | '7d'
- /** @enum {string} */
- metric: 'user_queries'
- project_refs: string[]
- region: string
- }
- GetMetricsResponse: {
- metrics: components['schemas']['ProjectMetric'][]
- }
GetObjectsBody: {
options: components['schemas']['StorageObjectSearchOptions']
path: string
@@ -3687,6 +3699,7 @@ export interface components {
}
Member: {
gotrue_id: string
+ is_sso_user: boolean | null
mfa_enabled: boolean
primary_email: string | null
role_ids: number[]
@@ -3896,7 +3909,6 @@ export interface components {
| 'MONTHLY_ACTIVE_USERS'
| 'MONTHLY_ACTIVE_SSO_USERS'
| 'FUNCTION_INVOCATIONS'
- | 'FUNCTION_COUNT'
| 'STORAGE_IMAGES_TRANSFORMED'
| 'REALTIME_MESSAGE_COUNT'
| 'REALTIME_PEAK_CONNECTIONS'
@@ -3978,39 +3990,6 @@ export interface components {
data: components['schemas']['Payment'][]
defaultPaymentMethodId: string | null
}
- Permission: {
- actions: (
- | 'analytics:Read'
- | 'analytics:Write'
- | 'auth:Execute'
- | 'billing:Read'
- | 'billing:Write'
- | 'write:Create'
- | 'write:Delete'
- | 'functions:Read'
- | 'functions:Write'
- | 'infra:Execute'
- | 'read:Read'
- | 'sql:Read:Select'
- | 'sql:Write:Delete'
- | 'sql:Write:Insert'
- | 'sql:Write:Update'
- | 'storage:Admin:Read'
- | 'storage:Admin:Write'
- | 'tenant:Sql:Admin:Read'
- | 'tenant:Sql:Admin:Write'
- | 'tenant:Sql:CreateTable'
- | 'tenant:Sql:Write:Delete'
- | 'tenant:Sql:Write:Insert'
- | 'tenant:Sql:Query'
- | 'tenant:Sql:Read:Select'
- | 'tenant:Sql:Write:Update'
- | 'write:Update'
- )[]
- condition: unknown
- organization_id: number
- resources: string[]
- }
PgbouncerConfigResponse: {
connectionString: string
db_dns_name: string
@@ -4385,16 +4364,17 @@ export interface components {
disk_volume_size_gb?: number
id: number
infra_compute_size?: components['schemas']['DbInstanceSize']
- inserted_at: string
+ inserted_at: string | null
is_branch_enabled: boolean
- is_physical_backups_enabled: boolean
+ is_physical_backups_enabled: boolean | null
name: string
organization_id: number
+ organization_slug: string
preview_branch_refs: string[]
ref: string
region: string
status: string
- subscription_id: string
+ subscription_id: string | null
}
ProjectIntegrationConnection: {
added_by: {
@@ -4614,7 +4594,7 @@ export interface components {
*/
costs: number
/**
- * @description In case of a usage item, the free usage included in the customers plan
+ * @description In case of a usage item, the free usage included in the customers Plan
* @example 100
*/
freeUnitsInPlan?: number
@@ -4642,10 +4622,10 @@ export interface components {
usageTotal?: number
}
ResourceBillingResponse: {
- /** @description Whether the user is exceeding the included quotas in the plan - only relevant for users on usage-capped plans. */
+ /** @description Whether the user is exceeding the included quotas in the Plan - only relevant for users on usage-capped Plans. */
exceedsPlanLimits: boolean
items: components['schemas']['ResourceBillingItem'][]
- /** @description Whether the user is can have over-usage, which will be billed - this will be false on usage-capped plans. */
+ /** @description Whether the user is can have over-usage, which will be billed - this will be false on usage-capped Plans. */
overusageAllowed: boolean
}
ResourceProvisioningConfigResponse: {
@@ -4853,7 +4833,7 @@ export interface components {
variant: components['schemas']['ProjectAddonVariantResponse']
}
/**
- * @description Organization subscription plan
+ * @description Organization subscription Plan
* @enum {string}
*/
SelfServePlanId: 'free' | 'pro' | 'team'
@@ -5140,7 +5120,7 @@ export interface components {
/** @description Slug of your organization */
organization_id: string
/**
- * @description Subscription plan
+ * @description Subscription Plan
* @example free
* @enum {string}
*/
@@ -6079,7 +6059,7 @@ export interface components {
organization_id: string
/**
* @deprecated
- * @description Subscription plan is now set on organization level and is ignored in this request
+ * @description Subscription Plan is now set on organization level and is ignored in this request
* @example free
* @enum {string}
*/
@@ -7420,6 +7400,22 @@ export interface operations {
}
}
}
+ /** [Beta] Get oauth app authorization request */
+ OAuthAuthorizationsController_getAuthorizationRequest: {
+ parameters: {
+ path: {
+ /** @description Oauth authorization id */
+ id: string
+ }
+ }
+ responses: {
+ 200: {
+ content: {
+ 'application/json': components['schemas']['GetOAuthAuthorizationResponse']
+ }
+ }
+ }
+ }
/** Gets user's organizations */
OrganizationsController_getOrganizations: {
responses: {
@@ -7627,7 +7623,7 @@ export interface operations {
}
}
}
- /** Gets subscription plans */
+ /** Gets subscription Plans */
OrgPlansController_getAvailablePlans: {
parameters: {
path: {
@@ -7644,7 +7640,7 @@ export interface operations {
403: {
content: never
}
- /** @description Failed to get subscription plans */
+ /** @description Failed to get subscription Plans */
500: {
content: never
}
@@ -7803,7 +7799,6 @@ export interface operations {
| 'MONTHLY_ACTIVE_USERS'
| 'MONTHLY_ACTIVE_SSO_USERS'
| 'FUNCTION_INVOCATIONS'
- | 'FUNCTION_COUNT'
| 'STORAGE_IMAGES_TRANSFORMED'
| 'REALTIME_MESSAGE_COUNT'
| 'REALTIME_PEAK_CONNECTIONS'
@@ -8365,45 +8360,34 @@ export interface operations {
}
}
}
- /** [Beta] Get oauth app authorization request */
- AuthorizationsController_getAuthorizationRequest: {
- parameters: {
- path: {
- id: string
- }
- }
- responses: {
- 200: {
- content: {
- 'application/json': components['schemas']['GetAuthorizationResponse']
- }
- }
- }
- }
/** [Beta] Approve oauth app authorization request */
- AuthorizationsController_approveAuthorizationRequest: {
+ OrganizationOAuthAuthorizationsController_approveAuthorizationRequest: {
parameters: {
path: {
+ /** @description Organization slug */
+ slug: string
+ /** @description Oauth authorization id */
id: string
}
}
- requestBody: {
- content: {
- 'application/json': components['schemas']['AuthorizationsApproveBody']
- }
- }
responses: {
201: {
content: {
'application/json': components['schemas']['ApproveAuthorizationResponse']
}
}
+ 403: {
+ content: never
+ }
}
}
/** [Beta] Decline oauth app authorization request */
- AuthorizationsController_declineAuthorizationRequest: {
+ OrganizationOAuthAuthorizationsController_declineAuthorizationRequest: {
parameters: {
path: {
+ /** @description Organization slug */
+ slug: string
+ /** @description Oauth authorization id */
id: string
}
}
@@ -8413,6 +8397,9 @@ export interface operations {
'application/json': components['schemas']['DeclineAuthorizationResponse']
}
}
+ 403: {
+ content: never
+ }
}
}
/** Gets Stripe payment methods for the given organization */
@@ -10432,7 +10419,7 @@ export interface operations {
responses: {
200: {
content: {
- 'application/json': components['schemas']['Permission'][]
+ 'application/json': components['schemas']['AccessControlPermission'][]
}
}
/** @description Failed to retrieve permissions */