@@ -1001,37 +1001,44 @@ export class ObjectStackClient {
10011001 } ;
10021002
10031003 /**
1004- * OAuth / OpenID Connect Provider — admin endpoints exposed by better-auth's
1005- * `oidc- provider` plugin (when enabled on the server). Lets users register
1006- * their own OAuth client applications, list them, and revoke them.
1004+ * OAuth / OpenID Connect Provider — admin endpoints exposed by
1005+ * `@better-auth/oauth- provider` (when enabled on the server). Lets users
1006+ * register their own OAuth client applications, list them, and revoke them.
10071007 *
10081008 * All endpoints are mounted under the auth route, e.g. `/api/v1/auth/oauth2/*`.
10091009 */
10101010 oauth = {
10111011 applications : {
10121012 /**
10131013 * Register a new OAuth client application.
1014- * POST /api/v1/auth/oauth2/register
1014+ * POST /api/v1/auth/oauth2/create-client (authenticated)
10151015 *
10161016 * Returns the freshly-issued `client_id` and `client_secret`.
10171017 * The secret is only returned at creation time — store it securely.
10181018 */
10191019 register : async ( req : {
1020- client_name : string ;
1020+ client_name ?: string ;
1021+ name ?: string ;
10211022 redirect_uris : string [ ] ;
10221023 token_endpoint_auth_method ?: 'none' | 'client_secret_basic' | 'client_secret_post' ;
10231024 grant_types ?: string [ ] ;
10241025 response_types ?: string [ ] ;
10251026 client_uri ?: string ;
10261027 logo_uri ?: string ;
10271028 scope ?: string ;
1029+ scopes ?: string [ ] ;
10281030 contacts ?: string [ ] ;
10291031 tos_uri ?: string ;
10301032 policy_uri ?: string ;
10311033 metadata ?: Record < string , unknown > ;
10321034 } ) => {
10331035 const route = this . getRoute ( 'auth' ) ;
1034- const res = await this . fetch ( `${ this . baseUrl } ${ route } /oauth2/register` , {
1036+ // The new oauth-provider package exposes `/oauth2/create-client`
1037+ // (authenticated dynamic registration). The legacy `/oauth2/register`
1038+ // endpoint is now disabled by default for security and only
1039+ // available when the server explicitly opts in via the
1040+ // `allowUnauthenticatedClientRegistration` option.
1041+ const res = await this . fetch ( `${ this . baseUrl } ${ route } /oauth2/create-client` , {
10351042 method : 'POST' ,
10361043 body : JSON . stringify ( req ) ,
10371044 } ) ;
@@ -1040,54 +1047,57 @@ export class ObjectStackClient {
10401047
10411048 /**
10421049 * Get a single OAuth application by its `client_id`.
1043- * GET /api/v1/auth/oauth2/client/:id
1050+ * GET /api/v1/auth/oauth2/get- client?client_id=...
10441051 */
10451052 get : async ( clientId : string ) => {
10461053 const route = this . getRoute ( 'auth' ) ;
10471054 const res = await this . fetch (
1048- `${ this . baseUrl } ${ route } /oauth2/client/${ encodeURIComponent ( clientId ) } ` ,
1055+ `${ this . baseUrl } ${ route } /oauth2/get-client?client_id=${ encodeURIComponent ( clientId ) } ` ,
1056+ ) ;
1057+ return res . json ( ) ;
1058+ } ,
1059+
1060+ /**
1061+ * Get a single OAuth application's public fields (no auth required
1062+ * once the user has signed in). Used by the consent screen.
1063+ * GET /api/v1/auth/oauth2/public-client?client_id=...
1064+ */
1065+ getPublic : async ( clientId : string ) => {
1066+ const route = this . getRoute ( 'auth' ) ;
1067+ const res = await this . fetch (
1068+ `${ this . baseUrl } ${ route } /oauth2/public-client?client_id=${ encodeURIComponent ( clientId ) } ` ,
10491069 ) ;
10501070 return res . json ( ) ;
10511071 } ,
10521072
10531073 /**
10541074 * List OAuth applications visible to the current user.
10551075 *
1056- * better-auth doesn't expose a list endpoint yet — we query the
1057- * underlying `sys_oauth_application` table via the data API. In
1058- * production deployments, row-level security on this system table
1059- * should restrict rows to those owned by the current user; in
1060- * single-project / local mode every authenticated user sees the
1061- * full list.
1076+ * Uses `@better-auth/oauth-provider`'s `/oauth2/get-clients` endpoint
1077+ * which returns clients owned by the current user (and their
1078+ * organization, if applicable).
10621079 */
10631080 list : async ( ) => {
1064- const route = this . getRoute ( 'data' ) ;
1065- const params = new URLSearchParams ( { sort : '-created_at' } ) ;
1066- const res = await this . fetch (
1067- `${ this . baseUrl } ${ route } /sys_oauth_application?${ params . toString ( ) } ` ,
1068- ) ;
1081+ const route = this . getRoute ( 'auth' ) ;
1082+ const res = await this . fetch ( `${ this . baseUrl } ${ route } /oauth2/get-clients` ) ;
10691083 const data = await res . json ( ) ;
1070- const items =
1071- data ?. records ??
1072- data ?. items ??
1073- data ?. data ?. records ??
1074- data ?. data ?. items ??
1075- [ ] ;
1084+ const items = Array . isArray ( data ) ? data : data ?. clients ?? data ?. data ?? [ ] ;
10761085 return { applications : items as Array < Record < string , any > > } ;
10771086 } ,
10781087
10791088 /**
1080- * Delete an OAuth application by its row id (not client_id).
1089+ * Delete an OAuth application by its `client_id`.
1090+ * POST /api/v1/auth/oauth2/delete-client
10811091 *
10821092 * Tokens and consents referencing the client cascade-delete via the
10831093 * better-auth schema's `onDelete: cascade` foreign keys.
10841094 */
1085- delete : async ( id : string ) => {
1086- const route = this . getRoute ( 'data ' ) ;
1087- const res = await this . fetch (
1088- ` ${ this . baseUrl } ${ route } /sys_oauth_application/ ${ encodeURIComponent ( id ) } ` ,
1089- { method : 'DELETE' } ,
1090- ) ;
1095+ delete : async ( clientId : string ) => {
1096+ const route = this . getRoute ( 'auth ' ) ;
1097+ const res = await this . fetch ( ` ${ this . baseUrl } ${ route } /oauth2/delete-client` , {
1098+ method : 'POST' ,
1099+ body : JSON . stringify ( { client_id : clientId } ) ,
1100+ } ) ;
10911101 return res . json ( ) ;
10921102 } ,
10931103 } ,
@@ -1096,9 +1106,12 @@ export class ObjectStackClient {
10961106 * Submit the user's decision to a pending consent request.
10971107 * POST /api/v1/auth/oauth2/consent
10981108 *
1099- * Called by the consent screen after the user accepts or denies.
1109+ * Called by the consent screen after the user accepts or denies. The
1110+ * `oauth_query` is the raw query string of the consent page URL — it
1111+ * carries the signed authorization request that the consent endpoint
1112+ * verifies before issuing the authorization code.
11001113 */
1101- consent : async ( req : { accept : boolean ; consent_code ?: string } ) => {
1114+ consent : async ( req : { accept : boolean ; scope ?: string ; oauth_query ?: string } ) => {
11021115 const route = this . getRoute ( 'auth' ) ;
11031116 const res = await this . fetch ( `${ this . baseUrl } ${ route } /oauth2/consent` , {
11041117 method : 'POST' ,
0 commit comments