@supabase/gotrue-js 2.4.2 → 2.5.0
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/dist/main/GoTrueAdminApi.d.ts +3 -2
- package/dist/main/GoTrueAdminApi.d.ts.map +1 -1
- package/dist/main/GoTrueAdminApi.js +7 -1
- package/dist/main/GoTrueAdminApi.js.map +1 -1
- package/dist/main/GoTrueClient.d.ts +12 -3
- package/dist/main/GoTrueClient.d.ts.map +1 -1
- package/dist/main/GoTrueClient.js +89 -48
- package/dist/main/GoTrueClient.js.map +1 -1
- package/dist/main/lib/helpers.d.ts.map +1 -1
- package/dist/main/lib/helpers.js +1 -1
- package/dist/main/lib/helpers.js.map +1 -1
- package/dist/main/lib/types.d.ts +26 -34
- package/dist/main/lib/types.d.ts.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/module/GoTrueAdminApi.d.ts +3 -2
- package/dist/module/GoTrueAdminApi.d.ts.map +1 -1
- package/dist/module/GoTrueAdminApi.js +7 -1
- package/dist/module/GoTrueAdminApi.js.map +1 -1
- package/dist/module/GoTrueClient.d.ts +12 -3
- package/dist/module/GoTrueClient.d.ts.map +1 -1
- package/dist/module/GoTrueClient.js +89 -48
- package/dist/module/GoTrueClient.js.map +1 -1
- package/dist/module/lib/helpers.d.ts.map +1 -1
- package/dist/module/lib/helpers.js +1 -1
- package/dist/module/lib/helpers.js.map +1 -1
- package/dist/module/lib/types.d.ts +26 -34
- package/dist/module/lib/types.d.ts.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/GoTrueAdminApi.ts +9 -3
- package/src/GoTrueClient.ts +104 -61
- package/src/lib/helpers.ts +1 -1
- package/src/lib/types.ts +27 -34
- package/src/lib/version.ts +1 -1
package/src/GoTrueClient.ts
CHANGED
|
@@ -1140,99 +1140,138 @@ export default class GoTrueClient {
|
|
|
1140
1140
|
}
|
|
1141
1141
|
|
|
1142
1142
|
private async _unenroll(params: MFAUnenrollParams): Promise<AuthMFAUnenrollResponse> {
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1143
|
+
try {
|
|
1144
|
+
const { data: sessionData, error: sessionError } = await this.getSession()
|
|
1145
|
+
if (sessionError) {
|
|
1146
|
+
return { data: null, error: sessionError }
|
|
1147
|
+
}
|
|
1147
1148
|
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1149
|
+
return await _request(this.fetch, 'DELETE', `${this.url}/factors/${params.factorId}`, {
|
|
1150
|
+
headers: this.headers,
|
|
1151
|
+
jwt: sessionData?.session?.access_token,
|
|
1152
|
+
})
|
|
1153
|
+
} catch (error) {
|
|
1154
|
+
if (isAuthError(error)) {
|
|
1155
|
+
return { data: null, error }
|
|
1156
|
+
}
|
|
1157
|
+
throw error
|
|
1158
|
+
}
|
|
1152
1159
|
}
|
|
1153
1160
|
|
|
1154
1161
|
/**
|
|
1155
|
-
*
|
|
1162
|
+
* Enrolls a factor
|
|
1156
1163
|
* @param friendlyName Human readable name assigned to a device
|
|
1157
1164
|
* @param factorType device which we're validating against. Can only be TOTP for now.
|
|
1158
1165
|
* @param issuer domain which the user is enrolling with
|
|
1159
1166
|
*/
|
|
1160
1167
|
private async _enroll(params: MFAEnrollParams): Promise<AuthMFAEnrollResponse> {
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1168
|
+
try {
|
|
1169
|
+
const { data: sessionData, error: sessionError } = await this.getSession()
|
|
1170
|
+
if (sessionError) {
|
|
1171
|
+
return { data: null, error: sessionError }
|
|
1172
|
+
}
|
|
1165
1173
|
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1174
|
+
const { data, error } = await _request(this.fetch, 'POST', `${this.url}/factors`, {
|
|
1175
|
+
body: {
|
|
1176
|
+
friendly_name: params.friendlyName,
|
|
1177
|
+
factor_type: params.factorType,
|
|
1178
|
+
issuer: params.issuer,
|
|
1179
|
+
},
|
|
1180
|
+
headers: this.headers,
|
|
1181
|
+
jwt: sessionData?.session?.access_token,
|
|
1182
|
+
})
|
|
1175
1183
|
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1184
|
+
if (error) {
|
|
1185
|
+
return { data: null, error }
|
|
1186
|
+
}
|
|
1179
1187
|
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1188
|
+
if (data?.totp?.qr_code) {
|
|
1189
|
+
data.totp.qr_code = `data:image/svg+xml;utf-8,${data.totp.qr_code}`
|
|
1190
|
+
}
|
|
1183
1191
|
|
|
1184
|
-
|
|
1192
|
+
return { data, error: null }
|
|
1193
|
+
} catch (error) {
|
|
1194
|
+
if (isAuthError(error)) {
|
|
1195
|
+
return { data: null, error }
|
|
1196
|
+
}
|
|
1197
|
+
throw error
|
|
1198
|
+
}
|
|
1185
1199
|
}
|
|
1186
1200
|
|
|
1187
1201
|
/**
|
|
1188
1202
|
* Validates a device as part of the enrollment step.
|
|
1189
|
-
* @param
|
|
1203
|
+
* @param factorId System assigned identifier for authenticator device as returned by enroll
|
|
1190
1204
|
* @param code Code Generated by an authenticator device
|
|
1191
1205
|
*/
|
|
1192
1206
|
private async _verify(params: MFAVerifyParams): Promise<AuthMFAVerifyResponse> {
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1207
|
+
try {
|
|
1208
|
+
const { data: sessionData, error: sessionError } = await this.getSession()
|
|
1209
|
+
if (sessionError) {
|
|
1210
|
+
return { data: null, error: sessionError }
|
|
1211
|
+
}
|
|
1197
1212
|
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1213
|
+
const { data, error } = await _request(
|
|
1214
|
+
this.fetch,
|
|
1215
|
+
'POST',
|
|
1216
|
+
`${this.url}/factors/${params.factorId}/verify`,
|
|
1217
|
+
{
|
|
1218
|
+
body: { code: params.code, challenge_id: params.challengeId },
|
|
1219
|
+
headers: this.headers,
|
|
1220
|
+
jwt: sessionData?.session?.access_token,
|
|
1221
|
+
}
|
|
1222
|
+
)
|
|
1223
|
+
if (error) {
|
|
1224
|
+
return { data: null, error }
|
|
1206
1225
|
}
|
|
1207
|
-
)
|
|
1208
|
-
if (error) {
|
|
1209
|
-
return { data: null, error }
|
|
1210
|
-
}
|
|
1211
1226
|
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1227
|
+
await this._saveSession({
|
|
1228
|
+
expires_at: Math.round(Date.now() / 1000) + data.expires_in,
|
|
1229
|
+
...data,
|
|
1230
|
+
})
|
|
1231
|
+
this._notifyAllSubscribers('MFA_CHALLENGE_VERIFIED', data)
|
|
1217
1232
|
|
|
1218
|
-
|
|
1233
|
+
return { data, error }
|
|
1234
|
+
} catch (error) {
|
|
1235
|
+
if (isAuthError(error)) {
|
|
1236
|
+
return { data: null, error }
|
|
1237
|
+
}
|
|
1238
|
+
throw error
|
|
1239
|
+
}
|
|
1219
1240
|
}
|
|
1220
1241
|
|
|
1221
1242
|
/**
|
|
1222
1243
|
* Creates a challenge which a user can verify against
|
|
1223
|
-
* @param
|
|
1244
|
+
* @param factorId System assigned identifier for authenticator device as returned by enroll
|
|
1224
1245
|
*/
|
|
1225
1246
|
private async _challenge(params: MFAChallengeParams): Promise<AuthMFAChallengeResponse> {
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1247
|
+
try {
|
|
1248
|
+
const { data: sessionData, error: sessionError } = await this.getSession()
|
|
1249
|
+
if (sessionError) {
|
|
1250
|
+
return { data: null, error: sessionError }
|
|
1251
|
+
}
|
|
1230
1252
|
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1253
|
+
return await _request(
|
|
1254
|
+
this.fetch,
|
|
1255
|
+
'POST',
|
|
1256
|
+
`${this.url}/factors/${params.factorId}/challenge`,
|
|
1257
|
+
{
|
|
1258
|
+
headers: this.headers,
|
|
1259
|
+
jwt: sessionData?.session?.access_token,
|
|
1260
|
+
}
|
|
1261
|
+
)
|
|
1262
|
+
} catch (error) {
|
|
1263
|
+
if (isAuthError(error)) {
|
|
1264
|
+
return { data: null, error }
|
|
1265
|
+
}
|
|
1266
|
+
throw error
|
|
1267
|
+
}
|
|
1235
1268
|
}
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* Creates a challenge and immediately verifies it
|
|
1272
|
+
* @param factorId System assigned identifier for authenticator device as returned by enroll
|
|
1273
|
+
* @param code Code Generated by an authenticator device
|
|
1274
|
+
*/
|
|
1236
1275
|
private async _challengeAndVerify(
|
|
1237
1276
|
params: MFAChallengeAndVerifyParams
|
|
1238
1277
|
): Promise<AuthMFAVerifyResponse> {
|
|
@@ -1275,6 +1314,10 @@ export default class GoTrueClient {
|
|
|
1275
1314
|
}
|
|
1276
1315
|
}
|
|
1277
1316
|
|
|
1317
|
+
/**
|
|
1318
|
+
* Gets the current and next authenticator assurance level (AAL)
|
|
1319
|
+
* and the current authentication methods for the session (AMR)
|
|
1320
|
+
*/
|
|
1278
1321
|
private async _getAuthenticatorAssuranceLevel(): Promise<AuthMFAGetAuthenticatorAssuranceLevelResponse> {
|
|
1279
1322
|
const {
|
|
1280
1323
|
data: { session },
|
package/src/lib/helpers.ts
CHANGED
|
@@ -13,7 +13,7 @@ export function uuid() {
|
|
|
13
13
|
})
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export const isBrowser = () => typeof
|
|
16
|
+
export const isBrowser = () => typeof document !== 'undefined'
|
|
17
17
|
|
|
18
18
|
export function getParameterByName(name: string, url?: string) {
|
|
19
19
|
if (!url) url = window?.location?.href || ''
|
package/src/lib/types.ts
CHANGED
|
@@ -595,8 +595,11 @@ export type GenerateLinkType =
|
|
|
595
595
|
| 'email_change_new'
|
|
596
596
|
|
|
597
597
|
export type MFAEnrollParams = {
|
|
598
|
+
/** The type of factor being enrolled. */
|
|
598
599
|
factorType: 'totp'
|
|
600
|
+
/** Domain which the user is enrolled with. */
|
|
599
601
|
issuer?: string
|
|
602
|
+
/** Human readable name assigned to the factor. */
|
|
600
603
|
friendlyName?: string
|
|
601
604
|
}
|
|
602
605
|
|
|
@@ -606,10 +609,10 @@ export type MFAUnenrollParams = {
|
|
|
606
609
|
}
|
|
607
610
|
|
|
608
611
|
export type MFAVerifyParams = {
|
|
609
|
-
/** ID of the factor being verified. */
|
|
612
|
+
/** ID of the factor being verified. Returned in enroll(). */
|
|
610
613
|
factorId: string
|
|
611
614
|
|
|
612
|
-
/** ID of the challenge being verified. */
|
|
615
|
+
/** ID of the challenge being verified. Returned in challenge(). */
|
|
613
616
|
challengeId: string
|
|
614
617
|
|
|
615
618
|
/** Verification code provided by the user. */
|
|
@@ -617,12 +620,12 @@ export type MFAVerifyParams = {
|
|
|
617
620
|
}
|
|
618
621
|
|
|
619
622
|
export type MFAChallengeParams = {
|
|
620
|
-
/** ID of the factor to be challenged. */
|
|
623
|
+
/** ID of the factor to be challenged. Returned in enroll(). */
|
|
621
624
|
factorId: string
|
|
622
625
|
}
|
|
623
626
|
|
|
624
627
|
export type MFAChallengeAndVerifyParams = {
|
|
625
|
-
/** ID of the factor being verified. */
|
|
628
|
+
/** ID of the factor being verified. Returned in enroll(). */
|
|
626
629
|
factorId: string
|
|
627
630
|
/** Verification code provided by the user. */
|
|
628
631
|
code: string
|
|
@@ -755,54 +758,38 @@ export type AuthMFAGetAuthenticatorAssuranceLevelResponse =
|
|
|
755
758
|
*/
|
|
756
759
|
export interface GoTrueMFAApi {
|
|
757
760
|
/**
|
|
758
|
-
* Starts the enrollment process for a new Multi-Factor Authentication
|
|
759
|
-
* factor. This method creates a new
|
|
760
|
-
*
|
|
761
|
-
* authenticator app.
|
|
762
|
-
*
|
|
761
|
+
* Starts the enrollment process for a new Multi-Factor Authentication (MFA)
|
|
762
|
+
* factor. This method creates a new `unverified` factor.
|
|
763
|
+
* To verify a factor, present the QR code or secret to the user and ask them to add it to their
|
|
764
|
+
* authenticator app.
|
|
765
|
+
* The user has to enter the code from their authenticator app to verify it.
|
|
763
766
|
*
|
|
764
|
-
*
|
|
765
|
-
* factor. All other sessions are logged out and the current one gets an
|
|
766
|
-
* `aal2` authenticator level.
|
|
767
|
-
*
|
|
768
|
-
* @see {@link GoTrueMFAApi#challenge}
|
|
769
|
-
* @see {@link GoTrueMFAApi#verify}
|
|
770
|
-
* @see {@link GoTrueMFAApi#getAuthenticatorAssuranceLevel}
|
|
767
|
+
* Upon verifying a factor, all other sessions are logged out and the current session's authenticator level is promoted to `aal2`.
|
|
771
768
|
*
|
|
772
769
|
*/
|
|
773
770
|
enroll(params: MFAEnrollParams): Promise<AuthMFAEnrollResponse>
|
|
774
771
|
|
|
775
772
|
/**
|
|
776
773
|
* Prepares a challenge used to verify that a user has access to a MFA
|
|
777
|
-
* factor.
|
|
778
|
-
* {@link GoTrueMFAApi#verify}.
|
|
779
|
-
*
|
|
774
|
+
* factor.
|
|
780
775
|
*/
|
|
781
776
|
challenge(params: MFAChallengeParams): Promise<AuthMFAChallengeResponse>
|
|
782
777
|
|
|
783
778
|
/**
|
|
784
|
-
* Verifies a
|
|
779
|
+
* Verifies a code against a challenge. The verification code is
|
|
785
780
|
* provided by the user by entering a code seen in their authenticator app.
|
|
786
|
-
*
|
|
787
|
-
* @see {@link GoTrueMFAApi#challenge}
|
|
788
|
-
*
|
|
789
781
|
*/
|
|
790
782
|
verify(params: MFAVerifyParams): Promise<AuthMFAVerifyResponse>
|
|
791
783
|
|
|
792
784
|
/**
|
|
793
|
-
* Unenroll removes a MFA factor.
|
|
794
|
-
*
|
|
795
|
-
* cannot be done from a session with an `aal1` authenticator level.
|
|
796
|
-
*
|
|
785
|
+
* Unenroll removes a MFA factor.
|
|
786
|
+
* A user has to have an `aal2` authenticator level in order to unenroll a `verified` factor.
|
|
797
787
|
*/
|
|
798
788
|
unenroll(params: MFAUnenrollParams): Promise<AuthMFAUnenrollResponse>
|
|
799
789
|
|
|
800
790
|
/**
|
|
801
791
|
* Helper method which creates a challenge and immediately uses the given code to verify against it thereafter. The verification code is
|
|
802
792
|
* provided by the user by entering a code seen in their authenticator app.
|
|
803
|
-
*
|
|
804
|
-
* @see {@link GoTrueMFAApi#challengeAndVerify}
|
|
805
|
-
*
|
|
806
793
|
*/
|
|
807
794
|
challengeAndVerify(params: MFAChallengeAndVerifyParams): Promise<AuthMFAVerifyResponse>
|
|
808
795
|
|
|
@@ -877,7 +864,7 @@ export type AuthMFAAdminListFactorsResponse =
|
|
|
877
864
|
* @expermental
|
|
878
865
|
*/
|
|
879
866
|
export type AuthMFAAdminListFactorsParams = {
|
|
880
|
-
/** ID of the user
|
|
867
|
+
/** ID of the user. */
|
|
881
868
|
userId: string
|
|
882
869
|
}
|
|
883
870
|
|
|
@@ -888,15 +875,14 @@ export type AuthMFAAdminListFactorsParams = {
|
|
|
888
875
|
*/
|
|
889
876
|
export interface GoTrueAdminMFAApi {
|
|
890
877
|
/**
|
|
891
|
-
* Lists all factors
|
|
878
|
+
* Lists all factors associated to a user.
|
|
892
879
|
*
|
|
893
880
|
*/
|
|
894
881
|
listFactors(params: AuthMFAAdminListFactorsParams): Promise<AuthMFAAdminListFactorsResponse>
|
|
895
882
|
|
|
896
883
|
/**
|
|
897
884
|
* Deletes a factor on a user. This will log the user out of all active
|
|
898
|
-
* sessions
|
|
899
|
-
* unverified factors.
|
|
885
|
+
* sessions if the deleted factor was verified.
|
|
900
886
|
*
|
|
901
887
|
* @see {@link GoTrueMFAApi#unenroll}
|
|
902
888
|
*
|
|
@@ -927,3 +913,10 @@ export type CallRefreshTokenResult =
|
|
|
927
913
|
session: null
|
|
928
914
|
error: AuthError
|
|
929
915
|
}
|
|
916
|
+
|
|
917
|
+
export type PageParams = {
|
|
918
|
+
/** The page number */
|
|
919
|
+
page?: number
|
|
920
|
+
/** Number of items returned per page */
|
|
921
|
+
perPage?: number
|
|
922
|
+
}
|
package/src/lib/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '2.
|
|
2
|
+
export const version = '2.5.0'
|