react-native-authsignal 2.6.1 → 2.8.0-alpha.1
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/android/build.gradle +3 -19
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/authsignal/react/AuthsignalEmailModule.kt +11 -18
- package/android/src/main/java/com/authsignal/react/AuthsignalInAppModule.kt +66 -45
- package/android/src/main/java/com/authsignal/react/AuthsignalModule.kt +25 -39
- package/android/src/main/java/com/authsignal/react/AuthsignalPackage.kt +70 -17
- package/android/src/main/java/com/authsignal/react/AuthsignalPasskeyModule.kt +23 -17
- package/android/src/main/java/com/authsignal/react/AuthsignalPushModule.kt +16 -21
- package/android/src/main/java/com/authsignal/react/AuthsignalQRCodeModule.kt +16 -22
- package/android/src/main/java/com/authsignal/react/AuthsignalSMSModule.kt +11 -25
- package/android/src/main/java/com/authsignal/react/AuthsignalTOTPModule.kt +10 -17
- package/android/src/main/java/com/authsignal/react/AuthsignalWhatsappModule.kt +10 -23
- package/ios/AuthsignalEmailModule.m +7 -7
- package/ios/AuthsignalEmailModule.swift +10 -9
- package/ios/AuthsignalInAppModule.m +18 -17
- package/ios/AuthsignalInAppModule.swift +42 -27
- package/ios/AuthsignalModule.m +4 -4
- package/ios/AuthsignalModule.swift +14 -10
- package/ios/AuthsignalPasskeyModule.m +10 -10
- package/ios/AuthsignalPasskeyModule.swift +22 -21
- package/ios/AuthsignalPushModule.m +9 -9
- package/ios/AuthsignalPushModule.swift +14 -13
- package/ios/AuthsignalQRModule.m +10 -10
- package/ios/AuthsignalQRModule.swift +15 -14
- package/ios/AuthsignalSMSModule.m +7 -7
- package/ios/AuthsignalSMSModule.swift +10 -9
- package/ios/AuthsignalTOTPModule.m +5 -5
- package/ios/AuthsignalTOTPModule.swift +8 -7
- package/ios/AuthsignalTurboModules.mm +26 -0
- package/ios/AuthsignalWhatsappModule.m +5 -5
- package/ios/AuthsignalWhatsappModule.swift +8 -7
- package/lib/commonjs/NativeAuthsignalEmailModule.js +9 -0
- package/lib/commonjs/NativeAuthsignalEmailModule.js.map +1 -0
- package/lib/commonjs/NativeAuthsignalInAppModule.js +9 -0
- package/lib/commonjs/NativeAuthsignalInAppModule.js.map +1 -0
- package/lib/commonjs/NativeAuthsignalModule.js +9 -0
- package/lib/commonjs/NativeAuthsignalModule.js.map +1 -0
- package/lib/commonjs/NativeAuthsignalPasskeyModule.js +9 -0
- package/lib/commonjs/NativeAuthsignalPasskeyModule.js.map +1 -0
- package/lib/commonjs/NativeAuthsignalPushModule.js +9 -0
- package/lib/commonjs/NativeAuthsignalPushModule.js.map +1 -0
- package/lib/commonjs/NativeAuthsignalQRCodeModule.js +9 -0
- package/lib/commonjs/NativeAuthsignalQRCodeModule.js.map +1 -0
- package/lib/commonjs/NativeAuthsignalSMSModule.js +9 -0
- package/lib/commonjs/NativeAuthsignalSMSModule.js.map +1 -0
- package/lib/commonjs/NativeAuthsignalTOTPModule.js +9 -0
- package/lib/commonjs/NativeAuthsignalTOTPModule.js.map +1 -0
- package/lib/commonjs/NativeAuthsignalWhatsappModule.js +9 -0
- package/lib/commonjs/NativeAuthsignalWhatsappModule.js.map +1 -0
- package/lib/commonjs/email.js +7 -9
- package/lib/commonjs/email.js.map +1 -1
- package/lib/commonjs/getNativeModule.js +23 -0
- package/lib/commonjs/getNativeModule.js.map +1 -0
- package/lib/commonjs/inapp.js +15 -16
- package/lib/commonjs/inapp.js.map +1 -1
- package/lib/commonjs/index.js +6 -27
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/passkey.js +21 -31
- package/lib/commonjs/passkey.js.map +1 -1
- package/lib/commonjs/push.js +8 -10
- package/lib/commonjs/push.js.map +1 -1
- package/lib/commonjs/qr.js +8 -10
- package/lib/commonjs/qr.js.map +1 -1
- package/lib/commonjs/sms.js +7 -9
- package/lib/commonjs/sms.js.map +1 -1
- package/lib/commonjs/totp.js +7 -9
- package/lib/commonjs/totp.js.map +1 -1
- package/lib/commonjs/types.js +6 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/whatsapp.js +7 -9
- package/lib/commonjs/whatsapp.js.map +1 -1
- package/lib/module/NativeAuthsignalEmailModule.js +3 -0
- package/lib/module/NativeAuthsignalEmailModule.js.map +1 -0
- package/lib/module/NativeAuthsignalInAppModule.js +3 -0
- package/lib/module/NativeAuthsignalInAppModule.js.map +1 -0
- package/lib/module/NativeAuthsignalModule.js +3 -0
- package/lib/module/NativeAuthsignalModule.js.map +1 -0
- package/lib/module/NativeAuthsignalPasskeyModule.js +3 -0
- package/lib/module/NativeAuthsignalPasskeyModule.js.map +1 -0
- package/lib/module/NativeAuthsignalPushModule.js +3 -0
- package/lib/module/NativeAuthsignalPushModule.js.map +1 -0
- package/lib/module/NativeAuthsignalQRCodeModule.js +3 -0
- package/lib/module/NativeAuthsignalQRCodeModule.js.map +1 -0
- package/lib/module/NativeAuthsignalSMSModule.js +3 -0
- package/lib/module/NativeAuthsignalSMSModule.js.map +1 -0
- package/lib/module/NativeAuthsignalTOTPModule.js +3 -0
- package/lib/module/NativeAuthsignalTOTPModule.js.map +1 -0
- package/lib/module/NativeAuthsignalWhatsappModule.js +3 -0
- package/lib/module/NativeAuthsignalWhatsappModule.js.map +1 -0
- package/lib/module/email.js +7 -10
- package/lib/module/email.js.map +1 -1
- package/lib/module/getNativeModule.js +17 -0
- package/lib/module/getNativeModule.js.map +1 -0
- package/lib/module/inapp.js +15 -17
- package/lib/module/inapp.js.map +1 -1
- package/lib/module/index.js +4 -27
- package/lib/module/index.js.map +1 -1
- package/lib/module/passkey.js +22 -33
- package/lib/module/passkey.js.map +1 -1
- package/lib/module/push.js +8 -11
- package/lib/module/push.js.map +1 -1
- package/lib/module/qr.js +8 -11
- package/lib/module/qr.js.map +1 -1
- package/lib/module/sms.js +7 -10
- package/lib/module/sms.js.map +1 -1
- package/lib/module/totp.js +7 -10
- package/lib/module/totp.js.map +1 -1
- package/lib/module/types.js +5 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/whatsapp.js +7 -10
- package/lib/module/whatsapp.js.map +1 -1
- package/lib/typescript/NativeAuthsignalEmailModule.d.ts +10 -0
- package/lib/typescript/NativeAuthsignalEmailModule.d.ts.map +1 -0
- package/lib/typescript/NativeAuthsignalInAppModule.d.ts +15 -0
- package/lib/typescript/NativeAuthsignalInAppModule.d.ts.map +1 -0
- package/lib/typescript/NativeAuthsignalModule.d.ts +8 -0
- package/lib/typescript/NativeAuthsignalModule.d.ts.map +1 -0
- package/lib/typescript/NativeAuthsignalPasskeyModule.d.ts +12 -0
- package/lib/typescript/NativeAuthsignalPasskeyModule.d.ts.map +1 -0
- package/lib/typescript/NativeAuthsignalPushModule.d.ts +12 -0
- package/lib/typescript/NativeAuthsignalPushModule.d.ts.map +1 -0
- package/lib/typescript/NativeAuthsignalQRCodeModule.d.ts +12 -0
- package/lib/typescript/NativeAuthsignalQRCodeModule.d.ts.map +1 -0
- package/lib/typescript/NativeAuthsignalSMSModule.d.ts +10 -0
- package/lib/typescript/NativeAuthsignalSMSModule.d.ts.map +1 -0
- package/lib/typescript/NativeAuthsignalTOTPModule.d.ts +9 -0
- package/lib/typescript/NativeAuthsignalTOTPModule.d.ts.map +1 -0
- package/lib/typescript/NativeAuthsignalWhatsappModule.d.ts +9 -0
- package/lib/typescript/NativeAuthsignalWhatsappModule.d.ts.map +1 -0
- package/lib/typescript/email.d.ts +1 -0
- package/lib/typescript/email.d.ts.map +1 -1
- package/lib/typescript/getNativeModule.d.ts +2 -0
- package/lib/typescript/getNativeModule.d.ts.map +1 -0
- package/lib/typescript/inapp.d.ts +2 -1
- package/lib/typescript/inapp.d.ts.map +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/passkey.d.ts +2 -0
- package/lib/typescript/passkey.d.ts.map +1 -1
- package/lib/typescript/push.d.ts +1 -0
- package/lib/typescript/push.d.ts.map +1 -1
- package/lib/typescript/qr.d.ts +1 -0
- package/lib/typescript/qr.d.ts.map +1 -1
- package/lib/typescript/sms.d.ts +1 -0
- package/lib/typescript/sms.d.ts.map +1 -1
- package/lib/typescript/totp.d.ts +1 -0
- package/lib/typescript/totp.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +10 -0
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/whatsapp.d.ts +1 -0
- package/lib/typescript/whatsapp.d.ts.map +1 -1
- package/package.json +10 -1
- package/react-native-authsignal.podspec +3 -2
- package/src/NativeAuthsignalEmailModule.ts +10 -0
- package/src/NativeAuthsignalInAppModule.ts +32 -0
- package/src/NativeAuthsignalModule.ts +8 -0
- package/src/NativeAuthsignalPasskeyModule.ts +26 -0
- package/src/NativeAuthsignalPushModule.ts +20 -0
- package/src/NativeAuthsignalQRCodeModule.ts +20 -0
- package/src/NativeAuthsignalSMSModule.ts +10 -0
- package/src/NativeAuthsignalTOTPModule.ts +9 -0
- package/src/NativeAuthsignalWhatsappModule.ts +9 -0
- package/src/email.ts +90 -0
- package/src/email.web.ts +105 -0
- package/src/error.ts +28 -0
- package/src/error.web.ts +21 -0
- package/src/getNativeModule.ts +28 -0
- package/src/inapp.ts +220 -0
- package/src/index.tsx +80 -0
- package/src/index.web.tsx +99 -0
- package/src/passkey.ts +165 -0
- package/src/passkey.web.ts +153 -0
- package/src/push.ts +147 -0
- package/src/qr.ts +150 -0
- package/src/sms.ts +92 -0
- package/src/sms.web.ts +107 -0
- package/src/totp.ts +79 -0
- package/src/totp.web.ts +95 -0
- package/src/types.ts +167 -0
- package/src/web-client.ts +29 -0
- package/src/whatsapp.ts +76 -0
- package/src/whatsapp.web.ts +83 -0
package/src/sms.web.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { getOrCreateWebClient } from './web-client';
|
|
2
|
+
import { handleErrorCodes } from './error';
|
|
3
|
+
import type { AuthsignalResponse, VerifyInput, VerifyResponse } from './types';
|
|
4
|
+
|
|
5
|
+
interface ConstructorArgs {
|
|
6
|
+
tenantID: string;
|
|
7
|
+
baseURL: string;
|
|
8
|
+
enableLogging: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface EnrollSmsInput {
|
|
12
|
+
phoneNumber: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class AuthsignalSms {
|
|
16
|
+
tenantID: string;
|
|
17
|
+
baseURL: string;
|
|
18
|
+
enableLogging: boolean;
|
|
19
|
+
|
|
20
|
+
constructor({ tenantID, baseURL, enableLogging }: ConstructorArgs) {
|
|
21
|
+
this.tenantID = tenantID;
|
|
22
|
+
this.baseURL = baseURL;
|
|
23
|
+
this.enableLogging = enableLogging;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async enroll({
|
|
27
|
+
phoneNumber,
|
|
28
|
+
}: EnrollSmsInput): Promise<AuthsignalResponse<void>> {
|
|
29
|
+
try {
|
|
30
|
+
const client = this.getClient();
|
|
31
|
+
const result = await client.sms.enroll({ phoneNumber });
|
|
32
|
+
|
|
33
|
+
if (result.errorCode) {
|
|
34
|
+
return {
|
|
35
|
+
error: result.errorDescription ?? result.error,
|
|
36
|
+
errorCode: result.errorCode,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {};
|
|
41
|
+
} catch (ex) {
|
|
42
|
+
return this.handleError(ex);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async challenge(): Promise<AuthsignalResponse<void>> {
|
|
47
|
+
try {
|
|
48
|
+
const client = this.getClient();
|
|
49
|
+
const result = await client.sms.challenge();
|
|
50
|
+
|
|
51
|
+
if (result.errorCode) {
|
|
52
|
+
return {
|
|
53
|
+
error: result.errorDescription ?? result.error,
|
|
54
|
+
errorCode: result.errorCode,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {};
|
|
59
|
+
} catch (ex) {
|
|
60
|
+
return this.handleError(ex);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async verify({
|
|
65
|
+
code,
|
|
66
|
+
}: VerifyInput): Promise<AuthsignalResponse<VerifyResponse>> {
|
|
67
|
+
try {
|
|
68
|
+
const client = this.getClient();
|
|
69
|
+
const result = await client.sms.verify({ code });
|
|
70
|
+
|
|
71
|
+
if (result.errorCode) {
|
|
72
|
+
return {
|
|
73
|
+
error: result.errorDescription ?? result.error,
|
|
74
|
+
errorCode: result.errorCode,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
data: result.data
|
|
80
|
+
? {
|
|
81
|
+
isVerified: result.data.isVerified,
|
|
82
|
+
token: result.data.token,
|
|
83
|
+
failureReason: result.data.failureReason,
|
|
84
|
+
}
|
|
85
|
+
: undefined,
|
|
86
|
+
};
|
|
87
|
+
} catch (ex) {
|
|
88
|
+
return this.handleError(ex);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private getClient() {
|
|
93
|
+
return getOrCreateWebClient({
|
|
94
|
+
tenantID: this.tenantID,
|
|
95
|
+
baseURL: this.baseURL,
|
|
96
|
+
enableLogging: this.enableLogging,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private handleError(ex: unknown) {
|
|
101
|
+
if (this.enableLogging) {
|
|
102
|
+
console.log(ex);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return handleErrorCodes(ex);
|
|
106
|
+
}
|
|
107
|
+
}
|
package/src/totp.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { handleErrorCodes } from './error';
|
|
2
|
+
import { getNativeModule } from './getNativeModule';
|
|
3
|
+
import NativeAuthsignalTOTPModule, {
|
|
4
|
+
type Spec as AuthsignalTOTPModuleSpec,
|
|
5
|
+
} from './NativeAuthsignalTOTPModule';
|
|
6
|
+
import type { AuthsignalResponse, VerifyInput, VerifyResponse } from './types';
|
|
7
|
+
|
|
8
|
+
interface ConstructorArgs {
|
|
9
|
+
tenantID: string;
|
|
10
|
+
baseURL: string;
|
|
11
|
+
enableLogging: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface EnrollTotpResponse {
|
|
15
|
+
uri: string;
|
|
16
|
+
secret: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const AuthsignalTOTPModule = getNativeModule<AuthsignalTOTPModuleSpec>(
|
|
20
|
+
'AuthsignalTOTPModule',
|
|
21
|
+
NativeAuthsignalTOTPModule
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export class AuthsignalTotp {
|
|
25
|
+
tenantID: string;
|
|
26
|
+
baseURL: string;
|
|
27
|
+
enableLogging: boolean;
|
|
28
|
+
private initialized = false;
|
|
29
|
+
|
|
30
|
+
constructor({ tenantID, baseURL, enableLogging }: ConstructorArgs) {
|
|
31
|
+
this.tenantID = tenantID;
|
|
32
|
+
this.baseURL = baseURL;
|
|
33
|
+
this.enableLogging = enableLogging;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async enroll(): Promise<AuthsignalResponse<EnrollTotpResponse>> {
|
|
37
|
+
await this.ensureModuleIsInitialized();
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const data = (await AuthsignalTOTPModule.enroll()) as EnrollTotpResponse;
|
|
41
|
+
|
|
42
|
+
return { data };
|
|
43
|
+
} catch (ex) {
|
|
44
|
+
return this.handleError(ex);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async verify({
|
|
49
|
+
code,
|
|
50
|
+
}: VerifyInput): Promise<AuthsignalResponse<VerifyResponse>> {
|
|
51
|
+
await this.ensureModuleIsInitialized();
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const data = (await AuthsignalTOTPModule.verify(code)) as VerifyResponse;
|
|
55
|
+
|
|
56
|
+
return { data };
|
|
57
|
+
} catch (ex) {
|
|
58
|
+
return this.handleError(ex);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private async ensureModuleIsInitialized() {
|
|
63
|
+
if (this.initialized) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
await AuthsignalTOTPModule.initialize(this.tenantID, this.baseURL);
|
|
68
|
+
|
|
69
|
+
this.initialized = true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private handleError(ex: unknown) {
|
|
73
|
+
if (this.enableLogging) {
|
|
74
|
+
console.log(ex);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return handleErrorCodes(ex);
|
|
78
|
+
}
|
|
79
|
+
}
|
package/src/totp.web.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { getOrCreateWebClient } from './web-client';
|
|
2
|
+
import { handleErrorCodes } from './error';
|
|
3
|
+
import type { AuthsignalResponse, VerifyInput, VerifyResponse } from './types';
|
|
4
|
+
|
|
5
|
+
interface ConstructorArgs {
|
|
6
|
+
tenantID: string;
|
|
7
|
+
baseURL: string;
|
|
8
|
+
enableLogging: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface EnrollTotpResponse {
|
|
12
|
+
uri: string;
|
|
13
|
+
secret: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class AuthsignalTotp {
|
|
17
|
+
tenantID: string;
|
|
18
|
+
baseURL: string;
|
|
19
|
+
enableLogging: boolean;
|
|
20
|
+
|
|
21
|
+
constructor({ tenantID, baseURL, enableLogging }: ConstructorArgs) {
|
|
22
|
+
this.tenantID = tenantID;
|
|
23
|
+
this.baseURL = baseURL;
|
|
24
|
+
this.enableLogging = enableLogging;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async enroll(): Promise<AuthsignalResponse<EnrollTotpResponse>> {
|
|
28
|
+
try {
|
|
29
|
+
const client = this.getClient();
|
|
30
|
+
const result = await client.totp.enroll();
|
|
31
|
+
|
|
32
|
+
if (result.errorCode) {
|
|
33
|
+
return {
|
|
34
|
+
error: result.errorDescription ?? result.error,
|
|
35
|
+
errorCode: result.errorCode,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
data: result.data
|
|
41
|
+
? {
|
|
42
|
+
uri: result.data.uri,
|
|
43
|
+
secret: result.data.secret,
|
|
44
|
+
}
|
|
45
|
+
: undefined,
|
|
46
|
+
};
|
|
47
|
+
} catch (ex) {
|
|
48
|
+
return this.handleError(ex);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async verify({
|
|
53
|
+
code,
|
|
54
|
+
}: VerifyInput): Promise<AuthsignalResponse<VerifyResponse>> {
|
|
55
|
+
try {
|
|
56
|
+
const client = this.getClient();
|
|
57
|
+
const result = await client.totp.verify({ code });
|
|
58
|
+
|
|
59
|
+
if (result.errorCode) {
|
|
60
|
+
return {
|
|
61
|
+
error: result.errorDescription ?? result.error,
|
|
62
|
+
errorCode: result.errorCode,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
data: result.data
|
|
68
|
+
? {
|
|
69
|
+
isVerified: result.data.isVerified,
|
|
70
|
+
token: result.data.token,
|
|
71
|
+
failureReason: result.data.failureReason,
|
|
72
|
+
}
|
|
73
|
+
: undefined,
|
|
74
|
+
};
|
|
75
|
+
} catch (ex) {
|
|
76
|
+
return this.handleError(ex);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private getClient() {
|
|
81
|
+
return getOrCreateWebClient({
|
|
82
|
+
tenantID: this.tenantID,
|
|
83
|
+
baseURL: this.baseURL,
|
|
84
|
+
enableLogging: this.enableLogging,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private handleError(ex: unknown) {
|
|
89
|
+
if (this.enableLogging) {
|
|
90
|
+
console.log(ex);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return handleErrorCodes(ex);
|
|
94
|
+
}
|
|
95
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { ErrorCode } from './error';
|
|
2
|
+
|
|
3
|
+
export interface AuthsignalResponse<T> {
|
|
4
|
+
data?: T;
|
|
5
|
+
error?: string;
|
|
6
|
+
errorCode?: ErrorCode | string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface TokenPayload {
|
|
10
|
+
aud: string;
|
|
11
|
+
exp: number;
|
|
12
|
+
iat: number;
|
|
13
|
+
other: {
|
|
14
|
+
actionCode: string;
|
|
15
|
+
idempotencyKey: string;
|
|
16
|
+
publishableKey: string;
|
|
17
|
+
tenantId: string;
|
|
18
|
+
userId: string;
|
|
19
|
+
username: string;
|
|
20
|
+
};
|
|
21
|
+
scope?: string;
|
|
22
|
+
sub: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface SignUpResponse {
|
|
26
|
+
token: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface SignInResponse {
|
|
30
|
+
isVerified: boolean;
|
|
31
|
+
token?: string;
|
|
32
|
+
userId?: string;
|
|
33
|
+
userAuthenticatorId?: string;
|
|
34
|
+
username?: string;
|
|
35
|
+
displayName?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface VerifyInput {
|
|
39
|
+
code: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface VerifyResponse {
|
|
43
|
+
isVerified: boolean;
|
|
44
|
+
token?: string;
|
|
45
|
+
failureReason?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export enum AppAttestationProvider {
|
|
49
|
+
apple = 'apple',
|
|
50
|
+
playIntegrity = 'playIntegrity',
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface AppAttestation {
|
|
54
|
+
provider: AppAttestationProvider;
|
|
55
|
+
token: string;
|
|
56
|
+
keyId?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface AddCredentialInput {
|
|
60
|
+
token?: string;
|
|
61
|
+
requireUserAuthentication?: boolean;
|
|
62
|
+
keychainAccess?: KeychainAccess;
|
|
63
|
+
appAttestation?: AppAttestation;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface AppChallenge {
|
|
67
|
+
challengeId: string;
|
|
68
|
+
actionCode?: string;
|
|
69
|
+
idempotencyKey?: string;
|
|
70
|
+
userAgent?: string;
|
|
71
|
+
deviceId?: string;
|
|
72
|
+
ipAddress?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface AppCredential {
|
|
76
|
+
credentialId: string;
|
|
77
|
+
createdAt: string;
|
|
78
|
+
userId: string;
|
|
79
|
+
lastAuthenticatedAt?: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface ClaimChallengeInput {
|
|
83
|
+
challengeId: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface ClaimChallengeResponse {
|
|
87
|
+
success: boolean;
|
|
88
|
+
userAgent?: string;
|
|
89
|
+
ipAddress?: string;
|
|
90
|
+
actionCode?: string;
|
|
91
|
+
idempotencyKey?: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface UpdateChallengeInput {
|
|
95
|
+
challengeId: string;
|
|
96
|
+
approved: boolean;
|
|
97
|
+
verificationCode?: string | null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface InAppGetCredentialInput {
|
|
101
|
+
username?: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface InAppAddCredentialInput extends AddCredentialInput {
|
|
105
|
+
username?: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface InAppRemoveCredentialInput {
|
|
109
|
+
username?: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface InAppVerifyInput {
|
|
113
|
+
action?: string;
|
|
114
|
+
username?: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface InAppVerifyResponse {
|
|
118
|
+
token: string;
|
|
119
|
+
userId: string;
|
|
120
|
+
userAuthenticatorId: string;
|
|
121
|
+
username?: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface CreatePinInput {
|
|
125
|
+
pin: string;
|
|
126
|
+
username: string;
|
|
127
|
+
token?: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface VerifyPinInput {
|
|
131
|
+
pin: string;
|
|
132
|
+
username: string;
|
|
133
|
+
action?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface VerifyPinResponse {
|
|
137
|
+
isVerified: boolean;
|
|
138
|
+
token?: string;
|
|
139
|
+
userId?: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface DeletePinInput {
|
|
143
|
+
username: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface LaunchOptions {
|
|
147
|
+
mode?: 'popup' | 'redirect';
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export enum KeychainAccess {
|
|
151
|
+
afterFirstUnlock = 'afterFirstUnlock',
|
|
152
|
+
afterFirstUnlockThisDeviceOnly = 'afterFirstUnlockThisDeviceOnly',
|
|
153
|
+
whenUnlocked = 'whenUnlocked',
|
|
154
|
+
whenUnlockedThisDeviceOnly = 'whenUnlockedThisDeviceOnly',
|
|
155
|
+
whenPasscodeSetThisDeviceOnly = 'whenPasscodeSetThisDeviceOnly',
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export enum UserActionState {
|
|
159
|
+
ALLOW = 'ALLOW',
|
|
160
|
+
BLOCK = 'BLOCK',
|
|
161
|
+
CHALLENGE_REQUIRED = 'CHALLENGE_REQUIRED',
|
|
162
|
+
CHALLENGE_SUCCEEDED = 'CHALLENGE_SUCCEEDED',
|
|
163
|
+
CHALLENGE_FAILED = 'CHALLENGE_FAILED',
|
|
164
|
+
REVIEW_REQUIRED = 'REVIEW_REQUIRED',
|
|
165
|
+
REVIEW_SUCCEEDED = 'REVIEW_SUCCEEDED',
|
|
166
|
+
REVIEW_FAILED = 'REVIEW_FAILED',
|
|
167
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Authsignal as AuthsignalBrowser } from '@authsignal/browser';
|
|
2
|
+
|
|
3
|
+
let client: AuthsignalBrowser | null = null;
|
|
4
|
+
let currentTenantID: string | null = null;
|
|
5
|
+
let currentBaseURL: string | null = null;
|
|
6
|
+
|
|
7
|
+
interface WebClientConfig {
|
|
8
|
+
tenantID: string;
|
|
9
|
+
baseURL: string;
|
|
10
|
+
enableLogging?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getOrCreateWebClient({
|
|
14
|
+
tenantID,
|
|
15
|
+
baseURL,
|
|
16
|
+
enableLogging = false,
|
|
17
|
+
}: WebClientConfig): AuthsignalBrowser {
|
|
18
|
+
if (!client || tenantID !== currentTenantID || baseURL !== currentBaseURL) {
|
|
19
|
+
client = new AuthsignalBrowser({
|
|
20
|
+
tenantId: tenantID,
|
|
21
|
+
baseUrl: baseURL,
|
|
22
|
+
enableLogging,
|
|
23
|
+
});
|
|
24
|
+
currentTenantID = tenantID;
|
|
25
|
+
currentBaseURL = baseURL;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return client;
|
|
29
|
+
}
|
package/src/whatsapp.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { handleErrorCodes } from './error';
|
|
2
|
+
import { getNativeModule } from './getNativeModule';
|
|
3
|
+
import NativeAuthsignalWhatsappModule, {
|
|
4
|
+
type Spec as AuthsignalWhatsappModuleSpec,
|
|
5
|
+
} from './NativeAuthsignalWhatsappModule';
|
|
6
|
+
import type { AuthsignalResponse, VerifyInput, VerifyResponse } from './types';
|
|
7
|
+
|
|
8
|
+
interface ConstructorArgs {
|
|
9
|
+
tenantID: string;
|
|
10
|
+
baseURL: string;
|
|
11
|
+
enableLogging: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const AuthsignalWhatsappModule = getNativeModule<AuthsignalWhatsappModuleSpec>(
|
|
15
|
+
'AuthsignalWhatsappModule',
|
|
16
|
+
NativeAuthsignalWhatsappModule
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export class AuthsignalWhatsapp {
|
|
20
|
+
tenantID: string;
|
|
21
|
+
baseURL: string;
|
|
22
|
+
enableLogging: boolean;
|
|
23
|
+
private initialized = false;
|
|
24
|
+
|
|
25
|
+
constructor({ tenantID, baseURL, enableLogging }: ConstructorArgs) {
|
|
26
|
+
this.tenantID = tenantID;
|
|
27
|
+
this.baseURL = baseURL;
|
|
28
|
+
this.enableLogging = enableLogging;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async challenge(): Promise<AuthsignalResponse<void>> {
|
|
32
|
+
await this.ensureModuleIsInitialized();
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
await AuthsignalWhatsappModule.challenge();
|
|
36
|
+
|
|
37
|
+
return {};
|
|
38
|
+
} catch (ex) {
|
|
39
|
+
return this.handleError(ex);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async verify({
|
|
44
|
+
code,
|
|
45
|
+
}: VerifyInput): Promise<AuthsignalResponse<VerifyResponse>> {
|
|
46
|
+
await this.ensureModuleIsInitialized();
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const data = (await AuthsignalWhatsappModule.verify(
|
|
50
|
+
code
|
|
51
|
+
)) as VerifyResponse;
|
|
52
|
+
|
|
53
|
+
return { data };
|
|
54
|
+
} catch (ex) {
|
|
55
|
+
return this.handleError(ex);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private async ensureModuleIsInitialized() {
|
|
60
|
+
if (this.initialized) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
await AuthsignalWhatsappModule.initialize(this.tenantID, this.baseURL);
|
|
65
|
+
|
|
66
|
+
this.initialized = true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private handleError(ex: unknown) {
|
|
70
|
+
if (this.enableLogging) {
|
|
71
|
+
console.log(ex);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return handleErrorCodes(ex);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { getOrCreateWebClient } from './web-client';
|
|
2
|
+
import { handleErrorCodes } from './error';
|
|
3
|
+
import type { AuthsignalResponse, VerifyInput, VerifyResponse } from './types';
|
|
4
|
+
|
|
5
|
+
interface ConstructorArgs {
|
|
6
|
+
tenantID: string;
|
|
7
|
+
baseURL: string;
|
|
8
|
+
enableLogging: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class AuthsignalWhatsapp {
|
|
12
|
+
tenantID: string;
|
|
13
|
+
baseURL: string;
|
|
14
|
+
enableLogging: boolean;
|
|
15
|
+
|
|
16
|
+
constructor({ tenantID, baseURL, enableLogging }: ConstructorArgs) {
|
|
17
|
+
this.tenantID = tenantID;
|
|
18
|
+
this.baseURL = baseURL;
|
|
19
|
+
this.enableLogging = enableLogging;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async challenge(): Promise<AuthsignalResponse<void>> {
|
|
23
|
+
try {
|
|
24
|
+
const client = this.getClient();
|
|
25
|
+
const result = await client.whatsapp.challenge();
|
|
26
|
+
|
|
27
|
+
if (result.errorCode) {
|
|
28
|
+
return {
|
|
29
|
+
error: result.errorDescription ?? result.error,
|
|
30
|
+
errorCode: result.errorCode,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {};
|
|
35
|
+
} catch (ex) {
|
|
36
|
+
return this.handleError(ex);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async verify({
|
|
41
|
+
code,
|
|
42
|
+
}: VerifyInput): Promise<AuthsignalResponse<VerifyResponse>> {
|
|
43
|
+
try {
|
|
44
|
+
const client = this.getClient();
|
|
45
|
+
const result = await client.whatsapp.verify({ code });
|
|
46
|
+
|
|
47
|
+
if (result.errorCode) {
|
|
48
|
+
return {
|
|
49
|
+
error: result.errorDescription ?? result.error,
|
|
50
|
+
errorCode: result.errorCode,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
data: result.data
|
|
56
|
+
? {
|
|
57
|
+
isVerified: result.data.isVerified,
|
|
58
|
+
token: result.data.token,
|
|
59
|
+
failureReason: result.data.failureReason,
|
|
60
|
+
}
|
|
61
|
+
: undefined,
|
|
62
|
+
};
|
|
63
|
+
} catch (ex) {
|
|
64
|
+
return this.handleError(ex);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private getClient() {
|
|
69
|
+
return getOrCreateWebClient({
|
|
70
|
+
tenantID: this.tenantID,
|
|
71
|
+
baseURL: this.baseURL,
|
|
72
|
+
enableLogging: this.enableLogging,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private handleError(ex: unknown) {
|
|
77
|
+
if (this.enableLogging) {
|
|
78
|
+
console.log(ex);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return handleErrorCodes(ex);
|
|
82
|
+
}
|
|
83
|
+
}
|