@supabase/auth-js 2.80.1-canary.1 → 2.80.1-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -19
- package/dist/main/AuthAdminApi.js +2 -4
- package/dist/main/AuthAdminApi.js.map +1 -1
- package/dist/main/AuthClient.js +2 -4
- package/dist/main/AuthClient.js.map +1 -1
- package/dist/main/GoTrueAdminApi.d.ts +48 -1
- package/dist/main/GoTrueAdminApi.d.ts.map +1 -1
- package/dist/main/GoTrueAdminApi.js +162 -12
- package/dist/main/GoTrueAdminApi.js.map +1 -1
- package/dist/main/GoTrueClient.d.ts +58 -2
- package/dist/main/GoTrueClient.d.ts.map +1 -1
- package/dist/main/GoTrueClient.js +293 -156
- package/dist/main/GoTrueClient.js.map +1 -1
- package/dist/main/index.js +7 -23
- package/dist/main/index.js.map +1 -1
- package/dist/main/lib/error-codes.d.ts +1 -1
- package/dist/main/lib/fetch.js +2 -12
- package/dist/main/lib/fetch.js.map +1 -1
- package/dist/main/lib/helpers.d.ts +11 -0
- package/dist/main/lib/helpers.d.ts.map +1 -1
- package/dist/main/lib/helpers.js +39 -42
- package/dist/main/lib/helpers.js.map +1 -1
- package/dist/main/lib/types.d.ts +283 -2
- package/dist/main/lib/types.d.ts.map +1 -1
- package/dist/main/lib/types.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/main/lib/webauthn.d.ts +7 -5
- package/dist/main/lib/webauthn.d.ts.map +1 -1
- package/dist/main/lib/webauthn.js +5 -15
- package/dist/main/lib/webauthn.js.map +1 -1
- package/dist/module/GoTrueAdminApi.d.ts +48 -1
- package/dist/module/GoTrueAdminApi.d.ts.map +1 -1
- package/dist/module/GoTrueAdminApi.js +161 -11
- package/dist/module/GoTrueAdminApi.js.map +1 -1
- package/dist/module/GoTrueClient.d.ts +58 -2
- package/dist/module/GoTrueClient.d.ts.map +1 -1
- package/dist/module/GoTrueClient.js +292 -153
- package/dist/module/GoTrueClient.js.map +1 -1
- package/dist/module/lib/error-codes.d.ts +1 -1
- package/dist/module/lib/fetch.js +1 -11
- package/dist/module/lib/fetch.js.map +1 -1
- package/dist/module/lib/helpers.d.ts +11 -0
- package/dist/module/lib/helpers.d.ts.map +1 -1
- package/dist/module/lib/helpers.js +38 -9
- package/dist/module/lib/helpers.js.map +1 -1
- package/dist/module/lib/types.d.ts +283 -2
- package/dist/module/lib/types.d.ts.map +1 -1
- package/dist/module/lib/types.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.js +1 -1
- package/dist/module/lib/webauthn.d.ts +7 -5
- package/dist/module/lib/webauthn.d.ts.map +1 -1
- package/dist/module/lib/webauthn.js +3 -13
- package/dist/module/lib/webauthn.js.map +1 -1
- package/dist/tsconfig.module.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +12 -13
- package/src/GoTrueAdminApi.ts +186 -0
- package/src/GoTrueClient.ts +378 -150
- package/src/lib/error-codes.ts +1 -1
- package/src/lib/helpers.ts +46 -8
- package/src/lib/types.ts +307 -1
- package/src/lib/version.ts +1 -1
- package/src/lib/webauthn.ts +12 -8
package/src/GoTrueAdminApi.ts
CHANGED
|
@@ -21,6 +21,11 @@ import {
|
|
|
21
21
|
PageParams,
|
|
22
22
|
SIGN_OUT_SCOPES,
|
|
23
23
|
SignOutScope,
|
|
24
|
+
GoTrueAdminOAuthApi,
|
|
25
|
+
CreateOAuthClientParams,
|
|
26
|
+
UpdateOAuthClientParams,
|
|
27
|
+
OAuthClientResponse,
|
|
28
|
+
OAuthClientListResponse,
|
|
24
29
|
} from './lib/types'
|
|
25
30
|
import { AuthError, isAuthError } from './lib/errors'
|
|
26
31
|
|
|
@@ -28,6 +33,12 @@ export default class GoTrueAdminApi {
|
|
|
28
33
|
/** Contains all MFA administration methods. */
|
|
29
34
|
mfa: GoTrueAdminMFAApi
|
|
30
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Contains all OAuth client administration methods.
|
|
38
|
+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
|
|
39
|
+
*/
|
|
40
|
+
oauth: GoTrueAdminOAuthApi
|
|
41
|
+
|
|
31
42
|
protected url: string
|
|
32
43
|
protected headers: {
|
|
33
44
|
[key: string]: string
|
|
@@ -52,6 +63,14 @@ export default class GoTrueAdminApi {
|
|
|
52
63
|
listFactors: this._listFactors.bind(this),
|
|
53
64
|
deleteFactor: this._deleteFactor.bind(this),
|
|
54
65
|
}
|
|
66
|
+
this.oauth = {
|
|
67
|
+
listClients: this._listOAuthClients.bind(this),
|
|
68
|
+
createClient: this._createOAuthClient.bind(this),
|
|
69
|
+
getClient: this._getOAuthClient.bind(this),
|
|
70
|
+
updateClient: this._updateOAuthClient.bind(this),
|
|
71
|
+
deleteClient: this._deleteOAuthClient.bind(this),
|
|
72
|
+
regenerateClientSecret: this._regenerateOAuthClientSecret.bind(this),
|
|
73
|
+
}
|
|
55
74
|
}
|
|
56
75
|
|
|
57
76
|
/**
|
|
@@ -349,4 +368,171 @@ export default class GoTrueAdminApi {
|
|
|
349
368
|
throw error
|
|
350
369
|
}
|
|
351
370
|
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Lists all OAuth clients with optional pagination.
|
|
374
|
+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
|
|
375
|
+
*
|
|
376
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
377
|
+
*/
|
|
378
|
+
private async _listOAuthClients(params?: PageParams): Promise<OAuthClientListResponse> {
|
|
379
|
+
try {
|
|
380
|
+
const pagination: Pagination = { nextPage: null, lastPage: 0, total: 0 }
|
|
381
|
+
const response = await _request(this.fetch, 'GET', `${this.url}/admin/oauth/clients`, {
|
|
382
|
+
headers: this.headers,
|
|
383
|
+
noResolveJson: true,
|
|
384
|
+
query: {
|
|
385
|
+
page: params?.page?.toString() ?? '',
|
|
386
|
+
per_page: params?.perPage?.toString() ?? '',
|
|
387
|
+
},
|
|
388
|
+
xform: _noResolveJsonResponse,
|
|
389
|
+
})
|
|
390
|
+
if (response.error) throw response.error
|
|
391
|
+
|
|
392
|
+
const clients = await response.json()
|
|
393
|
+
const total = response.headers.get('x-total-count') ?? 0
|
|
394
|
+
const links = response.headers.get('link')?.split(',') ?? []
|
|
395
|
+
if (links.length > 0) {
|
|
396
|
+
links.forEach((link: string) => {
|
|
397
|
+
const page = parseInt(link.split(';')[0].split('=')[1].substring(0, 1))
|
|
398
|
+
const rel = JSON.parse(link.split(';')[1].split('=')[1])
|
|
399
|
+
pagination[`${rel}Page`] = page
|
|
400
|
+
})
|
|
401
|
+
|
|
402
|
+
pagination.total = parseInt(total)
|
|
403
|
+
}
|
|
404
|
+
return { data: { ...clients, ...pagination }, error: null }
|
|
405
|
+
} catch (error) {
|
|
406
|
+
if (isAuthError(error)) {
|
|
407
|
+
return { data: { clients: [] }, error }
|
|
408
|
+
}
|
|
409
|
+
throw error
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Creates a new OAuth client.
|
|
415
|
+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
|
|
416
|
+
*
|
|
417
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
418
|
+
*/
|
|
419
|
+
private async _createOAuthClient(params: CreateOAuthClientParams): Promise<OAuthClientResponse> {
|
|
420
|
+
try {
|
|
421
|
+
return await _request(this.fetch, 'POST', `${this.url}/admin/oauth/clients`, {
|
|
422
|
+
body: params,
|
|
423
|
+
headers: this.headers,
|
|
424
|
+
xform: (client: any) => {
|
|
425
|
+
return { data: client, error: null }
|
|
426
|
+
},
|
|
427
|
+
})
|
|
428
|
+
} catch (error) {
|
|
429
|
+
if (isAuthError(error)) {
|
|
430
|
+
return { data: null, error }
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
throw error
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Gets details of a specific OAuth client.
|
|
439
|
+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
|
|
440
|
+
*
|
|
441
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
442
|
+
*/
|
|
443
|
+
private async _getOAuthClient(clientId: string): Promise<OAuthClientResponse> {
|
|
444
|
+
try {
|
|
445
|
+
return await _request(this.fetch, 'GET', `${this.url}/admin/oauth/clients/${clientId}`, {
|
|
446
|
+
headers: this.headers,
|
|
447
|
+
xform: (client: any) => {
|
|
448
|
+
return { data: client, error: null }
|
|
449
|
+
},
|
|
450
|
+
})
|
|
451
|
+
} catch (error) {
|
|
452
|
+
if (isAuthError(error)) {
|
|
453
|
+
return { data: null, error }
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
throw error
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
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
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Deletes an OAuth client.
|
|
489
|
+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
|
|
490
|
+
*
|
|
491
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
492
|
+
*/
|
|
493
|
+
private async _deleteOAuthClient(
|
|
494
|
+
clientId: string
|
|
495
|
+
): Promise<{ data: null; error: AuthError | null }> {
|
|
496
|
+
try {
|
|
497
|
+
await _request(this.fetch, 'DELETE', `${this.url}/admin/oauth/clients/${clientId}`, {
|
|
498
|
+
headers: this.headers,
|
|
499
|
+
noResolveJson: true,
|
|
500
|
+
})
|
|
501
|
+
return { data: null, error: null }
|
|
502
|
+
} catch (error) {
|
|
503
|
+
if (isAuthError(error)) {
|
|
504
|
+
return { data: null, error }
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
throw error
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Regenerates the secret for an OAuth client.
|
|
513
|
+
* Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
|
|
514
|
+
*
|
|
515
|
+
* This function should only be called on a server. Never expose your `service_role` key in the browser.
|
|
516
|
+
*/
|
|
517
|
+
private async _regenerateOAuthClientSecret(clientId: string): Promise<OAuthClientResponse> {
|
|
518
|
+
try {
|
|
519
|
+
return await _request(
|
|
520
|
+
this.fetch,
|
|
521
|
+
'POST',
|
|
522
|
+
`${this.url}/admin/oauth/clients/${clientId}/regenerate_secret`,
|
|
523
|
+
{
|
|
524
|
+
headers: this.headers,
|
|
525
|
+
xform: (client: any) => {
|
|
526
|
+
return { data: client, error: null }
|
|
527
|
+
},
|
|
528
|
+
}
|
|
529
|
+
)
|
|
530
|
+
} catch (error) {
|
|
531
|
+
if (isAuthError(error)) {
|
|
532
|
+
return { data: null, error }
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
throw error
|
|
536
|
+
}
|
|
537
|
+
}
|
|
352
538
|
}
|