mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Description
Part of the work for OAuth apps with the scoped permissions. This PR
wires consent screen to the backend.
## Review instructions
### Setup
Copy the `examples/oauth-app-authorization-flow/.env.example` to
`examples/oauth-app-authorization-flow/.env`
> [!IMPORTANT]
> In next steps, make sure to copy the apps ids/secrets in the
`examples/oauth-app-authorization-flow/.env` with a way to differentiate
them:
> ```
> # org bound all projects
> SUPABASE_CLIENT_ID=xxx
> SUPABASE_CLIENT_SECRET=xxx
> ```
As an organization admin, go to the _Organization settings/OAuth Apps_
and create the following _Publishable apps_:
- `test_org_bound`:
- _Use the permissions of the person who connects_ unchecked
- _Ask for specific projects_ unchecked
- Select only _Database Read_ for the permissions
- `test_org_bound_projects`:
- _Use the permissions of the person who connects_ unchecked
- _Ask for specific projects_ checked
- Select only _Database Read_ for the permissions
- `test_member_bound`:
- _Use the permissions of the person who connects_ checked
- _Ask for specific projects_ unchecked
- Select only _Database Read/Write_ for the permissions
- `test_member_bound_projects`:
- _Use the permissions of the person who connects_ checked
- _Ask for specific projects_ checked
- Select only _Database Read/Write_ for the permissions
Make sure you have 3 projects in the org. Add a team member that have
Administration rights on the first project, read-only access to the 2nd
and no access to the third.
Install the `examples/oauth-app-authorization-flow` dependencies and
start the app.
- `test_org_bound`:
- connected on studio as the org admin
- click the `oauth-app-authorization-flow` button
- check that you don't have to select a project on the consent screen
- check that the permissions requested are correct and you can approve
the app
- update the published app to include the _Database Write_ permissions
- return to the `oauth-app-authorization-flow` index and click its
button again
- check that the consent screen shows the permissions difference and
approve it again
- connected as a simple team member, check that you have a message
indicating you can't approve this app
- `test_org_bound_projects`:
- connected on studio as the org admin
- click the `oauth-app-authorization-flow` button
- check that you have to select projects on the consent screen
- check that the permissions requested are correct and you can approve
the app
- update the published app to include the _Database Write_ permissions
- return to the `oauth-app-authorization-flow` index and click its
button again
- check that the consent screen shows the permissions difference and
approve it again
- connected as a simple team member, check that you have a message
indicating you can't approve this app
- `test_member_bound`:
- connected on studio as a member
- click the `oauth-app-authorization-flow` button
- check that you don't have to select a project on the consent screen
- check that the permissions requested are correct and you can approve
the app
- update the published app to add another permission
- return to the `oauth-app-authorization-flow` index and click its
button again
- check that the consent screen shows the permissions difference and
approve it again
- `test_member_bound_projects`:
- connected on studio as the org admin
- click the `oauth-app-authorization-flow` button
- check that you have to select projects on the consent screen (you
should see only the two you have access to) and select them all one by
one
- check that the permissions requested are correct
- approve the app and check that you have an error related to the
project with read-only access
- unselect it and approve the app
- update the published app to include the _Database Write_ permissions
- return to the `oauth-app-authorization-flow` index and click its
button again
- check that the consent screen shows the permissions difference and
approve it again
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { QueryOptions, queryOptions } from '@tanstack/react-query'
|
|
|
|
import { oauthAppsKeys } from './keys'
|
|
import { get, handleError, unguarded } from '@/data/fetchers'
|
|
import type { StudioError } from '@/lib/errors/studio-errors'
|
|
|
|
export type OAuthAppsAuthorizeRequestVariables = {
|
|
id?: string
|
|
}
|
|
|
|
async function getOAuthAppsAuthorizeRequest(
|
|
{ id }: OAuthAppsAuthorizeRequestVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!id) throw new Error('Authorization request id is required')
|
|
|
|
const { data, error } = await get('/platform/oauth/authorizations/{id}', {
|
|
params: { path: { id } },
|
|
grant: unguarded.byDesign('Only already-approved authorizations should check grants'),
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type OAuthAppsAuthorizeRequestData = Awaited<ReturnType<typeof getOAuthAppsAuthorizeRequest>>
|
|
export type OAuthAppsAuthorizeRequestError = StudioError
|
|
|
|
export const getOAuthAppsAuthorizeRequestQueryOptions = (
|
|
{ id }: OAuthAppsAuthorizeRequestVariables,
|
|
options?: QueryOptions<
|
|
OAuthAppsAuthorizeRequestData,
|
|
OAuthAppsAuthorizeRequestError,
|
|
OAuthAppsAuthorizeRequestData,
|
|
ReturnType<typeof oauthAppsKeys.authorizeRequest>
|
|
>
|
|
) =>
|
|
queryOptions({
|
|
queryKey: oauthAppsKeys.authorizeRequest(id),
|
|
queryFn: ({ signal }) => getOAuthAppsAuthorizeRequest({ id }, signal),
|
|
enabled: id != null,
|
|
...options,
|
|
})
|