Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions packages/core/auth-js/src/GoTrueAdminApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
SignOutScope,
GoTrueAdminOAuthApi,
CreateOAuthClientParams,
UpdateOAuthClientParams,
OAuthClientResponse,
OAuthClientListResponse,
} from './lib/types'
Expand Down Expand Up @@ -66,6 +67,7 @@ export default class GoTrueAdminApi {
listClients: this._listOAuthClients.bind(this),
createClient: this._createOAuthClient.bind(this),
getClient: this._getOAuthClient.bind(this),
updateClient: this._updateOAuthClient.bind(this),
deleteClient: this._deleteOAuthClient.bind(this),
regenerateClientSecret: this._regenerateOAuthClientSecret.bind(this),
}
Expand Down Expand Up @@ -414,9 +416,7 @@ export default class GoTrueAdminApi {
*
* This function should only be called on a server. Never expose your `service_role` key in the browser.
*/
private async _createOAuthClient(
params: CreateOAuthClientParams
): Promise<OAuthClientResponse> {
private async _createOAuthClient(params: CreateOAuthClientParams): Promise<OAuthClientResponse> {
try {
return await _request(this.fetch, 'POST', `${this.url}/admin/oauth/clients`, {
body: params,
Expand Down Expand Up @@ -457,6 +457,33 @@ export default class GoTrueAdminApi {
}
}

/**
* Updates an existing OAuth client.
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
*
* This function should only be called on a server. Never expose your `service_role` key in the browser.
*/
private async _updateOAuthClient(
clientId: string,
params: UpdateOAuthClientParams
): Promise<OAuthClientResponse> {
try {
return await _request(this.fetch, 'PUT', `${this.url}/admin/oauth/clients/${clientId}`, {
body: params,
headers: this.headers,
xform: (client: any) => {
return { data: client, error: null }
},
})
} catch (error) {
if (isAuthError(error)) {
return { data: null, error }
}

throw error
}
}

/**
* Deletes an OAuth client.
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
Expand All @@ -467,15 +494,10 @@ export default class GoTrueAdminApi {
clientId: string
): Promise<{ data: null; error: AuthError | null }> {
try {
await _request(
this.fetch,
'DELETE',
`${this.url}/admin/oauth/clients/${clientId}`,
{
headers: this.headers,
noResolveJson: true,
}
)
await _request(this.fetch, 'DELETE', `${this.url}/admin/oauth/clients/${clientId}`, {
headers: this.headers,
noResolveJson: true,
})
return { data: null, error: null }
} catch (error) {
if (isAuthError(error)) {
Expand Down
28 changes: 28 additions & 0 deletions packages/core/auth-js/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,8 @@ export type OAuthClient = {
registration_type: OAuthClientRegistrationType
/** URI of the OAuth client */
client_uri?: string
/** URI of the OAuth client's logo */
logo_uri?: string
/** Array of allowed redirect URIs */
redirect_uris: string[]
/** Array of allowed grant types */
Expand Down Expand Up @@ -1525,6 +1527,24 @@ export type CreateOAuthClientParams = {
scope?: string
}

/**
* Parameters for updating an existing OAuth client.
* All fields are optional. Only provided fields will be updated.
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
*/
export type UpdateOAuthClientParams = {
/** Human-readable name of the OAuth client */
client_name?: string
/** URI of the OAuth client */
client_uri?: string
/** URI of the OAuth client's logo */
logo_uri?: string
/** Array of allowed redirect URIs */
redirect_uris?: string[]
/** Array of allowed grant types */
grant_types?: OAuthClientGrantType[]
}

/**
* Response type for OAuth client operations.
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
Expand Down Expand Up @@ -1574,6 +1594,14 @@ export interface GoTrueAdminOAuthApi {
*/
getClient(clientId: string): Promise<OAuthClientResponse>

/**
* Updates an existing OAuth client.
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
*
* This function should only be called on a server. Never expose your `service_role` key in the browser.
*/
updateClient(clientId: string, params: UpdateOAuthClientParams): Promise<OAuthClientResponse>

/**
* Deletes an OAuth client.
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
Expand Down