Skip to content

Commit ce5c06b

Browse files
authored
Update types for verify methods (#92)
* return user authenticator object * update types
1 parent 22e475b commit ce5c06b

17 files changed

+131
-46
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@authsignal/browser",
3-
"version": "1.4.1",
3+
"version": "1.5.0",
44
"type": "module",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

src/api/email-api-client.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import {ChallengeResponse, EnrollResponse} from "../types";
21
import {buildHeaders, handleTokenExpired} from "./helpers";
3-
import {ApiClientOptions, ErrorResponse, VerifyResponse} from "./types/shared";
2+
import {ApiClientOptions, ChallengeResponse, EnrollResponse, ErrorResponse, VerifyResponse} from "./types/shared";
43

54
export class EmailApiClient {
65
tenantId: string;

src/api/email-magic-link-api-client.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import {ChallengeResponse, EnrollResponse} from "../types";
21
import {buildHeaders, handleTokenExpired} from "./helpers";
3-
import {CheckVerificationStatusResponse} from "./types/email-magic-link";
4-
import {ApiClientOptions, ErrorResponse} from "./types/shared";
2+
import {ApiClientOptions, ChallengeResponse, EnrollResponse, ErrorResponse, VerifyResponse} from "./types/shared";
53

64
export class EmailMagicLinkApiClient {
75
tenantId: string;
@@ -43,8 +41,8 @@ export class EmailMagicLinkApiClient {
4341
return responseJson;
4442
}
4543

46-
async checkVerificationStatus({token}: {token: string}): Promise<CheckVerificationStatusResponse | ErrorResponse> {
47-
const pollVerificationStatus = async (): Promise<CheckVerificationStatusResponse | ErrorResponse> => {
44+
async checkVerificationStatus({token}: {token: string}): Promise<VerifyResponse | ErrorResponse> {
45+
const pollVerificationStatus = async (): Promise<VerifyResponse | ErrorResponse> => {
4846
const response = await fetch(`${this.baseUrl}/client/verify/email-magic-link/finalize`, {
4947
method: "POST",
5048
headers: buildHeaders({token, tenantId: this.tenantId}),

src/api/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/api/sms-api-client.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import {ChallengeResponse, EnrollResponse} from "../types";
21
import {buildHeaders, handleTokenExpired} from "./helpers";
3-
import {ApiClientOptions, ErrorResponse, VerifyResponse} from "./types/shared";
2+
import {ApiClientOptions, ChallengeResponse, EnrollResponse, ErrorResponse, VerifyResponse} from "./types/shared";
43

54
export class SmsApiClient {
65
tenantId: string;

src/api/totp-api-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {buildHeaders, handleTokenExpired} from "./helpers";
22
import {ApiClientOptions, ErrorResponse, VerifyResponse} from "./types/shared";
3-
import {EnrollTotpResponse} from "../types";
3+
import {EnrollTotpResponse} from "./types/totp";
44

55
export class TotpApiClient {
66
tenantId: string;

src/api/types/email-magic-link.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/api/types/passkey.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
PublicKeyCredentialCreationOptionsJSON,
55
RegistrationResponseJSON,
66
} from "@simplewebauthn/types";
7+
import {Authenticator} from "./shared";
78

89
export type RegistrationOptsRequest = {
910
username?: string;
@@ -34,6 +35,7 @@ export type AddAuthenticatorResponse = {
3435
accessToken?: string;
3536
userAuthenticatorId?: string;
3637
userId?: string;
38+
userAuthenticator?: Authenticator;
3739
};
3840

3941
export type VerifyRequest = {

src/api/types/shared.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1+
import {CredentialDeviceType} from "@simplewebauthn/types";
2+
13
export type ApiClientOptions = {
24
baseUrl: string;
35
tenantId: string;
46
onTokenExpired?: () => void;
57
};
68

9+
export type EnrollResponse = {
10+
userAuthenticatorId: string;
11+
userId: string;
12+
};
13+
14+
export type ChallengeResponse = {
15+
challengeId: string;
16+
};
17+
718
export type VerifyResponse = {
819
isVerified: boolean;
920
accessToken?: string;
1021
failureReason?: string;
22+
/**
23+
* Only present when successfully verifying an authenticator during enrollment.
24+
*/
25+
userAuthenticator?: Authenticator;
1126
};
1227

1328
export type ErrorResponse = {
@@ -16,3 +31,87 @@ export type ErrorResponse = {
1631
errorCode?: "expired_token" | (string & {});
1732
errorDescription?: string;
1833
};
34+
35+
export enum VerificationMethod {
36+
SMS = "SMS",
37+
AUTHENTICATOR_APP = "AUTHENTICATOR_APP",
38+
RECOVERY_CODE = "RECOVERY_CODE",
39+
EMAIL_MAGIC_LINK = "EMAIL_MAGIC_LINK",
40+
EMAIL_OTP = "EMAIL_OTP",
41+
PUSH = "PUSH",
42+
SECURITY_KEY = "SECURITY_KEY",
43+
PASSKEY = "PASSKEY",
44+
VERIFF = "VERIFF",
45+
IPROOV = "IPROOV",
46+
PALM_BIOMETRICS_RR = "PALM_BIOMETRICS_RR",
47+
IDVERSE = "IDVERSE",
48+
}
49+
50+
enum SmsChannel {
51+
"DEFAULT" = "DEFAULT",
52+
"WHATSAPP" = "WHATSAPP",
53+
"SMS" = "SMS",
54+
}
55+
56+
enum DevicePlatform {
57+
"IOS" = "IOS",
58+
"ANDROID" = "ANDROID",
59+
"WEB" = "WEB",
60+
}
61+
62+
type WebauthnCredential = {
63+
credentialId: string;
64+
deviceId: string;
65+
name: string;
66+
aaguid?: string;
67+
credentialBackedUp: boolean;
68+
credentialDeviceType?: CredentialDeviceType;
69+
parsedUserAgent?: {
70+
ua: string;
71+
browser: {
72+
name?: string;
73+
version?: string;
74+
major?: string;
75+
};
76+
device: {
77+
model?: string;
78+
type?: string;
79+
vendor?: string;
80+
};
81+
engine: {
82+
name?: string;
83+
version?: string;
84+
};
85+
os: {
86+
name?: string;
87+
version?: string;
88+
};
89+
cpu: {
90+
architecture?: string;
91+
};
92+
};
93+
verifiedAt: string;
94+
authenticatorAttachment?: AuthenticatorAttachment;
95+
aaguidMapping?: {
96+
name: string;
97+
svgIconLight?: string;
98+
svgIconDark?: string;
99+
};
100+
};
101+
102+
export type Authenticator = {
103+
userAuthenticatorId: string;
104+
verificationMethod: VerificationMethod;
105+
createdAt: string;
106+
verifiedAt?: string;
107+
lastVerifiedAt?: string;
108+
isDefault?: boolean;
109+
email?: string;
110+
phoneNumber?: string;
111+
displayName?: string;
112+
authenticatorAttachment?: AuthenticatorAttachment;
113+
previousSmsChannel?: SmsChannel;
114+
devicePlatform?: DevicePlatform;
115+
username?: string;
116+
webauthnCredential?: WebauthnCredential;
117+
};

src/api/types/totp.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {EnrollResponse} from "./shared";
2+
3+
export type EnrollTotpResponse = {
4+
uri: string;
5+
secret: string;
6+
} & EnrollResponse;

src/email-magic-link.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import {EnrollResponse, ChallengeResponse} from "./api/types/shared";
12
import {EmailMagicLinkApiClient} from "./api/email-magic-link-api-client";
23
import {handleApiResponse} from "./helpers";
34
import {TokenCache} from "./token-cache";
4-
import {AuthsignalResponse, ChallengeResponse, EnrollResponse, CheckVerificationStatusResponse} from "./types";
5+
import {AuthsignalResponse, VerifyResponse} from "./types";
56

67
type EmailMagicLinkOptions = {
78
baseUrl: string;
@@ -41,7 +42,7 @@ export class EmailMagicLink {
4142
return handleApiResponse(response);
4243
}
4344

44-
async checkVerificationStatus(): Promise<AuthsignalResponse<CheckVerificationStatusResponse>> {
45+
async checkVerificationStatus(): Promise<AuthsignalResponse<VerifyResponse>> {
4546
if (!this.cache.token) {
4647
return this.cache.handleTokenNotSetError();
4748
}

src/email.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {EmailApiClient} from "./api/email-api-client";
2+
import {EnrollResponse, ChallengeResponse} from "./api/types/shared";
23
import {handleApiResponse} from "./helpers";
34
import {TokenCache} from "./token-cache";
4-
import {AuthsignalResponse, ChallengeResponse, EnrollResponse, VerifyResponse} from "./types";
5+
import {AuthsignalResponse, VerifyResponse} from "./types";
56

67
type EmailOptions = {
78
baseUrl: string;

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export * from "./authsignal";
22
export * from "./types";
3+
export type {Authenticator, VerificationMethod, EnrollResponse, ChallengeResponse} from "./api/types/shared";
4+
export type {EnrollTotpResponse} from "./api/types/totp";

src/passkey.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {startAuthentication, startRegistration} from "@simplewebauthn/browser";
22

3-
import {PasskeyApiClient} from "./api";
3+
import {PasskeyApiClient} from "./api/passkey-api-client";
44
import {AuthenticationResponseJSON, RegistrationResponseJSON, AuthenticatorAttachment} from "@simplewebauthn/types";
55
import {TokenCache} from "./token-cache";
66
import {handleErrorResponse, handleWebAuthnError} from "./helpers";
77
import {AuthsignalResponse} from "./types";
8-
8+
import {Authenticator} from "./api/types/shared";
99
type PasskeyOptions = {
1010
baseUrl: string;
1111
tenantId: string;
@@ -23,6 +23,7 @@ type SignUpParams = {
2323

2424
type SignUpResponse = {
2525
token?: string;
26+
userAuthenticator?: Authenticator;
2627
registrationResponse?: RegistrationResponseJSON;
2728
};
2829

@@ -109,6 +110,7 @@ export class Passkey {
109110
return {
110111
data: {
111112
token: addAuthenticatorResponse.accessToken,
113+
userAuthenticator: addAuthenticatorResponse.userAuthenticator,
112114
registrationResponse,
113115
},
114116
};

src/sms.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {SmsApiClient} from "./api/sms-api-client";
2+
import {EnrollResponse, ChallengeResponse} from "./api/types/shared";
23
import {handleApiResponse} from "./helpers";
34
import {TokenCache} from "./token-cache";
4-
import {AuthsignalResponse, ChallengeResponse, EnrollResponse, VerifyResponse} from "./types";
5+
import {AuthsignalResponse, VerifyResponse} from "./types";
56

67
type SmsOptions = {
78
baseUrl: string;

src/totp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {TotpApiClient} from "./api/totp-api-client";
2+
import {EnrollTotpResponse} from "./api/types/totp";
23
import {handleApiResponse} from "./helpers";
34
import {TokenCache} from "./token-cache";
4-
import {AuthsignalResponse, EnrollTotpResponse, VerifyResponse} from "./types";
5+
import {AuthsignalResponse, VerifyResponse} from "./types";
56

67
type TotpOptions = {
78
baseUrl: string;

src/types.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {WebAuthnError} from "@simplewebauthn/browser";
2-
2+
import {VerifyResponse as ApiVerifyResponse} from "./api/types/shared";
33
type BaseLaunchOptions = {
44
/**
55
* How the Authsignal Prebuilt MFA page should launch.
@@ -81,28 +81,7 @@ export type AuthsignalResponse<T> = {
8181
data?: T;
8282
};
8383

84-
export type EnrollResponse = {
85-
userAuthenticatorId: string;
86-
userId: string;
87-
};
88-
89-
export type EnrollTotpResponse = {
90-
uri: string;
91-
secret: string;
92-
} & EnrollResponse;
93-
94-
export type ChallengeResponse = {
95-
challengeId: string;
96-
};
97-
98-
export type VerifyResponse = {
99-
isVerified: boolean;
100-
token?: string;
101-
failureReason?: string;
102-
};
103-
104-
export type CheckVerificationStatusResponse = {
105-
isVerified: boolean;
84+
export type VerifyResponse = Omit<ApiVerifyResponse, "accessToken"> & {
10685
token?: string;
10786
};
10887

0 commit comments

Comments
 (0)