Skip to content

Commit e8a644e

Browse files
authored
feat(auth): add OAuth client update support (#1812)
1 parent 3e7e301 commit e8a644e

File tree

2 files changed

+62
-12
lines changed

2 files changed

+62
-12
lines changed

packages/core/auth-js/src/GoTrueAdminApi.ts

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
SignOutScope,
2424
GoTrueAdminOAuthApi,
2525
CreateOAuthClientParams,
26+
UpdateOAuthClientParams,
2627
OAuthClientResponse,
2728
OAuthClientListResponse,
2829
} from './lib/types'
@@ -66,6 +67,7 @@ export default class GoTrueAdminApi {
6667
listClients: this._listOAuthClients.bind(this),
6768
createClient: this._createOAuthClient.bind(this),
6869
getClient: this._getOAuthClient.bind(this),
70+
updateClient: this._updateOAuthClient.bind(this),
6971
deleteClient: this._deleteOAuthClient.bind(this),
7072
regenerateClientSecret: this._regenerateOAuthClientSecret.bind(this),
7173
}
@@ -414,9 +416,7 @@ export default class GoTrueAdminApi {
414416
*
415417
* This function should only be called on a server. Never expose your `service_role` key in the browser.
416418
*/
417-
private async _createOAuthClient(
418-
params: CreateOAuthClientParams
419-
): Promise<OAuthClientResponse> {
419+
private async _createOAuthClient(params: CreateOAuthClientParams): Promise<OAuthClientResponse> {
420420
try {
421421
return await _request(this.fetch, 'POST', `${this.url}/admin/oauth/clients`, {
422422
body: params,
@@ -457,6 +457,33 @@ export default class GoTrueAdminApi {
457457
}
458458
}
459459

460+
/**
461+
* Updates an existing OAuth client.
462+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
463+
*
464+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
465+
*/
466+
private async _updateOAuthClient(
467+
clientId: string,
468+
params: UpdateOAuthClientParams
469+
): Promise<OAuthClientResponse> {
470+
try {
471+
return await _request(this.fetch, 'PUT', `${this.url}/admin/oauth/clients/${clientId}`, {
472+
body: params,
473+
headers: this.headers,
474+
xform: (client: any) => {
475+
return { data: client, error: null }
476+
},
477+
})
478+
} catch (error) {
479+
if (isAuthError(error)) {
480+
return { data: null, error }
481+
}
482+
483+
throw error
484+
}
485+
}
486+
460487
/**
461488
* Deletes an OAuth client.
462489
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
@@ -467,15 +494,10 @@ export default class GoTrueAdminApi {
467494
clientId: string
468495
): Promise<{ data: null; error: AuthError | null }> {
469496
try {
470-
await _request(
471-
this.fetch,
472-
'DELETE',
473-
`${this.url}/admin/oauth/clients/${clientId}`,
474-
{
475-
headers: this.headers,
476-
noResolveJson: true,
477-
}
478-
)
497+
await _request(this.fetch, 'DELETE', `${this.url}/admin/oauth/clients/${clientId}`, {
498+
headers: this.headers,
499+
noResolveJson: true,
500+
})
479501
return { data: null, error: null }
480502
} catch (error) {
481503
if (isAuthError(error)) {

packages/core/auth-js/src/lib/types.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,8 @@ export type OAuthClient = {
14921492
registration_type: OAuthClientRegistrationType
14931493
/** URI of the OAuth client */
14941494
client_uri?: string
1495+
/** URI of the OAuth client's logo */
1496+
logo_uri?: string
14951497
/** Array of allowed redirect URIs */
14961498
redirect_uris: string[]
14971499
/** Array of allowed grant types */
@@ -1525,6 +1527,24 @@ export type CreateOAuthClientParams = {
15251527
scope?: string
15261528
}
15271529

1530+
/**
1531+
* Parameters for updating an existing OAuth client.
1532+
* All fields are optional. Only provided fields will be updated.
1533+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1534+
*/
1535+
export type UpdateOAuthClientParams = {
1536+
/** Human-readable name of the OAuth client */
1537+
client_name?: string
1538+
/** URI of the OAuth client */
1539+
client_uri?: string
1540+
/** URI of the OAuth client's logo */
1541+
logo_uri?: string
1542+
/** Array of allowed redirect URIs */
1543+
redirect_uris?: string[]
1544+
/** Array of allowed grant types */
1545+
grant_types?: OAuthClientGrantType[]
1546+
}
1547+
15281548
/**
15291549
* Response type for OAuth client operations.
15301550
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
@@ -1574,6 +1594,14 @@ export interface GoTrueAdminOAuthApi {
15741594
*/
15751595
getClient(clientId: string): Promise<OAuthClientResponse>
15761596

1597+
/**
1598+
* Updates an existing OAuth client.
1599+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
1600+
*
1601+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
1602+
*/
1603+
updateClient(clientId: string, params: UpdateOAuthClientParams): Promise<OAuthClientResponse>
1604+
15771605
/**
15781606
* Deletes an OAuth client.
15791607
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.

0 commit comments

Comments
 (0)