@@ -109,6 +109,8 @@ import type {
109109 AuthOAuthServerApi ,
110110 AuthOAuthAuthorizationDetailsResponse ,
111111 AuthOAuthConsentResponse ,
112+ AuthOAuthGrantsResponse ,
113+ AuthOAuthRevokeGrantResponse ,
112114 Prettify ,
113115 Provider ,
114116 ResendParams ,
@@ -352,6 +354,8 @@ export default class GoTrueClient {
352354 getAuthorizationDetails : this . _getAuthorizationDetails . bind ( this ) ,
353355 approveAuthorization : this . _approveAuthorization . bind ( this ) ,
354356 denyAuthorization : this . _denyAuthorization . bind ( this ) ,
357+ listGrants : this . _listOAuthGrants . bind ( this ) ,
358+ revokeGrant : this . _revokeOAuthGrant . bind ( this ) ,
355359 }
356360
357361 if ( this . persistSession ) {
@@ -3567,6 +3571,79 @@ export default class GoTrueClient {
35673571 }
35683572 }
35693573
3574+ /**
3575+ * Lists all OAuth grants that the authenticated user has authorized.
3576+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
3577+ */
3578+ private async _listOAuthGrants ( ) : Promise < AuthOAuthGrantsResponse > {
3579+ try {
3580+ return await this . _useSession ( async ( result ) => {
3581+ const {
3582+ data : { session } ,
3583+ error : sessionError ,
3584+ } = result
3585+
3586+ if ( sessionError ) {
3587+ return this . _returnResult ( { data : null , error : sessionError } )
3588+ }
3589+
3590+ if ( ! session ) {
3591+ return this . _returnResult ( { data : null , error : new AuthSessionMissingError ( ) } )
3592+ }
3593+
3594+ return await _request ( this . fetch , 'GET' , `${ this . url } /user/oauth/grants` , {
3595+ headers : this . headers ,
3596+ jwt : session . access_token ,
3597+ xform : ( data : any ) => ( { data, error : null } ) ,
3598+ } )
3599+ } )
3600+ } catch ( error ) {
3601+ if ( isAuthError ( error ) ) {
3602+ return this . _returnResult ( { data : null , error } )
3603+ }
3604+
3605+ throw error
3606+ }
3607+ }
3608+
3609+ /**
3610+ * Revokes a user's OAuth grant for a specific client.
3611+ * Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
3612+ */
3613+ private async _revokeOAuthGrant ( options : {
3614+ clientId : string
3615+ } ) : Promise < AuthOAuthRevokeGrantResponse > {
3616+ try {
3617+ return await this . _useSession ( async ( result ) => {
3618+ const {
3619+ data : { session } ,
3620+ error : sessionError ,
3621+ } = result
3622+
3623+ if ( sessionError ) {
3624+ return this . _returnResult ( { data : null , error : sessionError } )
3625+ }
3626+
3627+ if ( ! session ) {
3628+ return this . _returnResult ( { data : null , error : new AuthSessionMissingError ( ) } )
3629+ }
3630+
3631+ return await _request ( this . fetch , 'DELETE' , `${ this . url } /user/oauth/grants` , {
3632+ headers : this . headers ,
3633+ jwt : session . access_token ,
3634+ query : { client_id : options . clientId } ,
3635+ xform : ( ) => ( { data : { } , error : null } ) ,
3636+ } )
3637+ } )
3638+ } catch ( error ) {
3639+ if ( isAuthError ( error ) ) {
3640+ return this . _returnResult ( { data : null , error } )
3641+ }
3642+
3643+ throw error
3644+ }
3645+ }
3646+
35703647 private async fetchJwk ( kid : string , jwks : { keys : JWK [ ] } = { keys : [ ] } ) : Promise < JWK | null > {
35713648 // try fetching from the supplied jwks
35723649 let jwk = jwks . keys . find ( ( key ) => key . kid === kid )
0 commit comments