diff --git a/src/GoTrueClient.ts b/src/GoTrueClient.ts index 00477783a..7c84d8470 100644 --- a/src/GoTrueClient.ts +++ b/src/GoTrueClient.ts @@ -2452,6 +2452,7 @@ export default class GoTrueClient { await this._notifyAllSubscribers('MFA_CHALLENGE_VERIFIED', data) return { data, error } } else if ('factorType' in params && params.factorType === 'webauthn') { + // Single Step enroll // TODO: Replace the placeholder const { data, error } = await _request( this.fetch, @@ -2459,7 +2460,6 @@ export default class GoTrueClient { `${this.url}/factors/verify`, { body: { - use_multi_step: params.useMultiStep, factorType: params.factorType, }, headers: this.headers, diff --git a/src/lib/types.ts b/src/lib/types.ts index 4b1e9a775..72ecc302b 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -844,13 +844,17 @@ export type MFAVerifyTOTPParams = { // Declared as a separate type to allow for future changes export type MFAVerifyPhoneParams = MFAVerifyTOTPParams -export type MFAVerifyWebAuthnParams = { - /** The type of factor being enrolled. */ - factorType: 'webauthn' +export type MFAVerifyWebAuthnParams = + | { + /** The type of factor being enrolled. */ + factorType: 'webauthn' + } + | { + // TODO: define the type for this + factorId: string - /** Have the Auth client library handle the browser-authenticator interaction for you */ - useMultiStep?: boolean -} + credential: Object + } export type MFAEnrollParams = MFAEnrollTOTPParams | MFAEnrollPhoneParams | MFAEnrollWebAuthnParams @@ -1244,3 +1248,161 @@ export type SignOut = { */ scope?: 'global' | 'local' | 'others' } + +/** + * Available only in secure contexts. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AuthenticatorAssertionResponse) + */ +export interface AuthenticatorAssertionResponse extends AuthenticatorResponse { + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/AuthenticatorAssertionResponse/authenticatorData) */ + readonly authenticatorData: ArrayBuffer + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/AuthenticatorAssertionResponse/signature) */ + readonly signature: ArrayBuffer + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/AuthenticatorAssertionResponse/userHandle) */ + readonly userHandle: ArrayBuffer | null +} + +/** + * Available only in secure contexts. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AuthenticatorAttestationResponse) + */ +export interface AuthenticatorAttestationResponse extends AuthenticatorResponse { + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/AuthenticatorAttestationResponse/attestationObject) */ + readonly attestationObject: ArrayBuffer + getAuthenticatorData(): ArrayBuffer + getPublicKey(): ArrayBuffer | null + getPublicKeyAlgorithm(): COSEAlgorithmIdentifier + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/AuthenticatorAttestationResponse/getTransports) */ + getTransports(): string[] +} + +export interface AuthenticationExtensionsClientInputs { + appid?: string + credProps?: boolean + hmacCreateSecret?: boolean +} + +export interface AuthenticationExtensionsClientOutputs { + appid?: boolean + credProps?: CredentialPropertiesOutput + hmacCreateSecret?: boolean +} + +export interface AuthenticatorSelectionCriteria { + authenticatorAttachment?: AuthenticatorAttachment + requireResidentKey?: boolean + residentKey?: ResidentKeyRequirement + userVerification?: UserVerificationRequirement +} + +/** + * Available only in secure contexts. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PublicKeyCredential) + */ +export interface PublicKeyCredential extends Credential { + readonly authenticatorAttachment: string | null + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/PublicKeyCredential/rawId) */ + readonly rawId: ArrayBuffer + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/PublicKeyCredential/response) */ + readonly response: AuthenticatorResponse + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/PublicKeyCredential/getClientExtensionResults) */ + getClientExtensionResults(): AuthenticationExtensionsClientOutputs +} + +export interface PublicKeyCredentialCreationOptions { + attestation?: AttestationConveyancePreference + authenticatorSelection?: AuthenticatorSelectionCriteria + challenge: BufferSource + excludeCredentials?: PublicKeyCredentialDescriptor[] + extensions?: AuthenticationExtensionsClientInputs + pubKeyCredParams: PublicKeyCredentialParameters[] + rp: PublicKeyCredentialRpEntity + timeout?: number + user: PublicKeyCredentialUserEntity +} + +export interface PublicKeyCredentialDescriptor { + id: BufferSource + transports?: AuthenticatorTransport[] + type: PublicKeyCredentialType +} + +export interface PublicKeyCredentialParameters { + alg: COSEAlgorithmIdentifier + type: PublicKeyCredentialType +} + +export interface PublicKeyCredentialRequestOptions { + allowCredentials?: PublicKeyCredentialDescriptor[] + challenge: BufferSource + extensions?: AuthenticationExtensionsClientInputs + rpId?: string + timeout?: number + userVerification?: UserVerificationRequirement +} + +export interface PublicKeyCredentialUserEntity extends PublicKeyCredentialEntity { + displayName: string + id: BufferSource +} + +/** + * Available only in secure contexts. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AuthenticatorResponse) + */ +export interface AuthenticatorResponse { + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/AuthenticatorResponse/clientDataJSON) */ + readonly clientDataJSON: ArrayBuffer +} + +export interface CredentialPropertiesOutput { + rk?: boolean +} + +/** + * Available only in secure contexts. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Credential) + */ +export interface Credential { + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Credential/id) */ + readonly id: string + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Credential/type) */ + readonly type: string +} + +export interface PublicKeyCredentialRpEntity extends PublicKeyCredentialEntity { + id?: string +} + +export interface PublicKeyCredentialEntity { + name: string +} + +export type AttestationConveyancePreference = 'direct' | 'enterprise' | 'indirect' | 'none' +export type AuthenticatorTransport = 'ble' | 'hybrid' | 'internal' | 'nfc' | 'usb' +export type COSEAlgorithmIdentifier = number +export type UserVerificationRequirement = 'discouraged' | 'preferred' | 'required' +export type AuthenticatorAttachment = 'cross-platform' | 'platform' +export type ResidentKeyRequirement = 'discouraged' | 'preferred' | 'required' +export type BufferSource = ArrayBufferView | ArrayBuffer +export type PublicKeyCredentialType = 'public-key' +export type AlgorithmIdentifier = Algorithm | string +export type KeyUsage = + | 'decrypt' + | 'deriveBits' + | 'deriveKey' + | 'encrypt' + | 'sign' + | 'unwrapKey' + | 'verify' + | 'wrapKey' +export type KeyFormat = 'jwk' | 'pkcs8' | 'raw' | 'spki' +export type KeyType = 'private' | 'public' | 'secret' +export type HashAlgorithmIdentifier = AlgorithmIdentifier +export type NamedCurve = string +export type BigInteger = Uint8Array