react-native-authsignal 2.6.1 → 2.8.0-alpha.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/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 +61 -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 +41 -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.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.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 +5 -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 +161 -0
- package/src/web-client.ts +29 -0
- package/src/whatsapp.ts +76 -0
- package/src/whatsapp.web.ts +83 -0
package/src/email.web.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
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 EnrollEmailInput {
|
|
12
|
+
email: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class AuthsignalEmail {
|
|
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({ email }: EnrollEmailInput): Promise<AuthsignalResponse<void>> {
|
|
27
|
+
try {
|
|
28
|
+
const client = this.getClient();
|
|
29
|
+
const result = await client.email.enroll({ email });
|
|
30
|
+
|
|
31
|
+
if (result.errorCode) {
|
|
32
|
+
return {
|
|
33
|
+
error: result.errorDescription ?? result.error,
|
|
34
|
+
errorCode: result.errorCode,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {};
|
|
39
|
+
} catch (ex) {
|
|
40
|
+
return this.handleError(ex);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async challenge(): Promise<AuthsignalResponse<void>> {
|
|
45
|
+
try {
|
|
46
|
+
const client = this.getClient();
|
|
47
|
+
const result = await client.email.challenge();
|
|
48
|
+
|
|
49
|
+
if (result.errorCode) {
|
|
50
|
+
return {
|
|
51
|
+
error: result.errorDescription ?? result.error,
|
|
52
|
+
errorCode: result.errorCode,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {};
|
|
57
|
+
} catch (ex) {
|
|
58
|
+
return this.handleError(ex);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async verify({
|
|
63
|
+
code,
|
|
64
|
+
}: VerifyInput): Promise<AuthsignalResponse<VerifyResponse>> {
|
|
65
|
+
try {
|
|
66
|
+
const client = this.getClient();
|
|
67
|
+
const result = await client.email.verify({ code });
|
|
68
|
+
|
|
69
|
+
if (result.errorCode) {
|
|
70
|
+
return {
|
|
71
|
+
error: result.errorDescription ?? result.error,
|
|
72
|
+
errorCode: result.errorCode,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
data: result.data
|
|
78
|
+
? {
|
|
79
|
+
isVerified: result.data.isVerified,
|
|
80
|
+
token: result.data.token,
|
|
81
|
+
failureReason: result.data.failureReason,
|
|
82
|
+
}
|
|
83
|
+
: undefined,
|
|
84
|
+
};
|
|
85
|
+
} catch (ex) {
|
|
86
|
+
return this.handleError(ex);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private getClient() {
|
|
91
|
+
return getOrCreateWebClient({
|
|
92
|
+
tenantID: this.tenantID,
|
|
93
|
+
baseURL: this.baseURL,
|
|
94
|
+
enableLogging: this.enableLogging,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private handleError(ex: unknown) {
|
|
99
|
+
if (this.enableLogging) {
|
|
100
|
+
console.log(ex);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return handleErrorCodes(ex);
|
|
104
|
+
}
|
|
105
|
+
}
|
package/src/error.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export const LINKING_ERROR =
|
|
4
|
+
`The package 'react-native-authsignal' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
6
|
+
'- You rebuilt the app after installing the package\n' +
|
|
7
|
+
'- You are not using Expo Go\n';
|
|
8
|
+
|
|
9
|
+
export enum ErrorCode {
|
|
10
|
+
user_canceled = 'user_canceled',
|
|
11
|
+
no_credential = 'no_credential',
|
|
12
|
+
matched_excluded_credential = 'matched_excluded_credential',
|
|
13
|
+
token_not_set = 'token_not_set',
|
|
14
|
+
token_required = 'token_required',
|
|
15
|
+
token_invalid = 'token_invalid',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function handleErrorCodes(ex: any) {
|
|
19
|
+
return {
|
|
20
|
+
error: ex.message,
|
|
21
|
+
errorCode: ex.code,
|
|
22
|
+
} as ErrorResponse;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface ErrorResponse {
|
|
26
|
+
error: string;
|
|
27
|
+
errorCode: string;
|
|
28
|
+
}
|
package/src/error.web.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export enum ErrorCode {
|
|
2
|
+
token_not_set = 'token_not_set',
|
|
3
|
+
token_required = 'token_required',
|
|
4
|
+
token_invalid = 'token_invalid',
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function handleErrorCodes(ex: any) {
|
|
8
|
+
const message =
|
|
9
|
+
ex?.errorDescription ?? ex?.message ?? ex?.error ?? String(ex);
|
|
10
|
+
const code = ex?.errorCode ?? ex?.code ?? undefined;
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
error: message,
|
|
14
|
+
errorCode: code,
|
|
15
|
+
} as ErrorResponse;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface ErrorResponse {
|
|
19
|
+
error: string;
|
|
20
|
+
errorCode: string;
|
|
21
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { NativeModules } from 'react-native';
|
|
2
|
+
import { LINKING_ERROR } from './error';
|
|
3
|
+
|
|
4
|
+
export function getNativeModule<Spec>(
|
|
5
|
+
moduleName: string,
|
|
6
|
+
turboModule: Spec | null
|
|
7
|
+
): Spec {
|
|
8
|
+
if (turboModule != null) {
|
|
9
|
+
return turboModule;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const legacyModule = (NativeModules as Record<string, Spec | undefined>)[
|
|
13
|
+
moduleName
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
if (legacyModule != null) {
|
|
17
|
+
return legacyModule;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return new Proxy(
|
|
21
|
+
{},
|
|
22
|
+
{
|
|
23
|
+
get() {
|
|
24
|
+
throw new Error(LINKING_ERROR);
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
) as Spec;
|
|
28
|
+
}
|
package/src/inapp.ts
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { handleErrorCodes } from './error';
|
|
2
|
+
import { getNativeModule } from './getNativeModule';
|
|
3
|
+
import NativeAuthsignalInAppModule, {
|
|
4
|
+
type Spec as AuthsignalInAppModuleSpec,
|
|
5
|
+
} from './NativeAuthsignalInAppModule';
|
|
6
|
+
import type {
|
|
7
|
+
AuthsignalResponse,
|
|
8
|
+
AppCredential,
|
|
9
|
+
InAppVerifyInput,
|
|
10
|
+
InAppVerifyResponse,
|
|
11
|
+
InAppAddCredentialInput,
|
|
12
|
+
InAppGetCredentialInput,
|
|
13
|
+
InAppRemoveCredentialInput,
|
|
14
|
+
CreatePinInput,
|
|
15
|
+
VerifyPinInput,
|
|
16
|
+
VerifyPinResponse,
|
|
17
|
+
DeletePinInput,
|
|
18
|
+
} from './types';
|
|
19
|
+
|
|
20
|
+
interface ConstructorArgs {
|
|
21
|
+
tenantID: string;
|
|
22
|
+
baseURL: string;
|
|
23
|
+
enableLogging: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const AuthsignalInAppModule = getNativeModule<AuthsignalInAppModuleSpec>(
|
|
27
|
+
'AuthsignalInAppModule',
|
|
28
|
+
NativeAuthsignalInAppModule
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export class AuthsignalInApp {
|
|
32
|
+
tenantID: string;
|
|
33
|
+
baseURL: string;
|
|
34
|
+
enableLogging: boolean;
|
|
35
|
+
private initialized = false;
|
|
36
|
+
|
|
37
|
+
constructor({ tenantID, baseURL, enableLogging }: ConstructorArgs) {
|
|
38
|
+
this.tenantID = tenantID;
|
|
39
|
+
this.baseURL = baseURL;
|
|
40
|
+
this.enableLogging = enableLogging;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async getCredential({
|
|
44
|
+
username,
|
|
45
|
+
}: InAppGetCredentialInput): Promise<
|
|
46
|
+
AuthsignalResponse<AppCredential | undefined>
|
|
47
|
+
> {
|
|
48
|
+
await this.ensureModuleIsInitialized();
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const data = (await AuthsignalInAppModule.getCredential(
|
|
52
|
+
username ?? null
|
|
53
|
+
)) as AppCredential | undefined;
|
|
54
|
+
|
|
55
|
+
return { data };
|
|
56
|
+
} catch (ex) {
|
|
57
|
+
if (this.enableLogging) {
|
|
58
|
+
console.log(ex);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return handleErrorCodes(ex);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async addCredential({
|
|
66
|
+
token,
|
|
67
|
+
requireUserAuthentication = false,
|
|
68
|
+
keychainAccess,
|
|
69
|
+
username,
|
|
70
|
+
appAttestation,
|
|
71
|
+
}: InAppAddCredentialInput = {}): Promise<AuthsignalResponse<AppCredential>> {
|
|
72
|
+
await this.ensureModuleIsInitialized();
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const data = (await AuthsignalInAppModule.addCredential(
|
|
76
|
+
token ?? null,
|
|
77
|
+
requireUserAuthentication,
|
|
78
|
+
keychainAccess ?? null,
|
|
79
|
+
username ?? null,
|
|
80
|
+
appAttestation ?? null
|
|
81
|
+
)) as AppCredential;
|
|
82
|
+
|
|
83
|
+
return { data };
|
|
84
|
+
} catch (ex) {
|
|
85
|
+
if (this.enableLogging) {
|
|
86
|
+
console.log(ex);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return handleErrorCodes(ex);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async removeCredential({
|
|
94
|
+
username,
|
|
95
|
+
}: InAppRemoveCredentialInput): Promise<AuthsignalResponse<boolean>> {
|
|
96
|
+
await this.ensureModuleIsInitialized();
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const data = await AuthsignalInAppModule.removeCredential(
|
|
100
|
+
username ?? null
|
|
101
|
+
);
|
|
102
|
+
return { data };
|
|
103
|
+
} catch (ex) {
|
|
104
|
+
if (this.enableLogging) {
|
|
105
|
+
console.log(ex);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return handleErrorCodes(ex);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async verify({ action, username }: InAppVerifyInput = {}): Promise<
|
|
113
|
+
AuthsignalResponse<InAppVerifyResponse>
|
|
114
|
+
> {
|
|
115
|
+
await this.ensureModuleIsInitialized();
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
const data = (await AuthsignalInAppModule.verify(
|
|
119
|
+
action ?? null,
|
|
120
|
+
username ?? null
|
|
121
|
+
)) as InAppVerifyResponse;
|
|
122
|
+
|
|
123
|
+
return { data };
|
|
124
|
+
} catch (ex) {
|
|
125
|
+
if (this.enableLogging) {
|
|
126
|
+
console.log(ex);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return handleErrorCodes(ex);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async createPin({
|
|
134
|
+
pin,
|
|
135
|
+
username,
|
|
136
|
+
token,
|
|
137
|
+
}: CreatePinInput): Promise<AuthsignalResponse<AppCredential>> {
|
|
138
|
+
await this.ensureModuleIsInitialized();
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
const data = (await AuthsignalInAppModule.createPin(
|
|
142
|
+
pin,
|
|
143
|
+
username,
|
|
144
|
+
token ?? null
|
|
145
|
+
)) as AppCredential;
|
|
146
|
+
return { data };
|
|
147
|
+
} catch (ex) {
|
|
148
|
+
if (this.enableLogging) {
|
|
149
|
+
console.log(ex);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return handleErrorCodes(ex);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async verifyPin({
|
|
157
|
+
pin,
|
|
158
|
+
username,
|
|
159
|
+
action,
|
|
160
|
+
}: VerifyPinInput): Promise<AuthsignalResponse<VerifyPinResponse>> {
|
|
161
|
+
await this.ensureModuleIsInitialized();
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
const data = (await AuthsignalInAppModule.verifyPin(
|
|
165
|
+
pin,
|
|
166
|
+
username,
|
|
167
|
+
action ?? null
|
|
168
|
+
)) as VerifyPinResponse;
|
|
169
|
+
return { data };
|
|
170
|
+
} catch (ex) {
|
|
171
|
+
if (this.enableLogging) {
|
|
172
|
+
console.log(ex);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return handleErrorCodes(ex);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async deletePin({
|
|
180
|
+
username,
|
|
181
|
+
}: DeletePinInput): Promise<AuthsignalResponse<boolean>> {
|
|
182
|
+
await this.ensureModuleIsInitialized();
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
const data = await AuthsignalInAppModule.deletePin(username);
|
|
186
|
+
return { data };
|
|
187
|
+
} catch (ex) {
|
|
188
|
+
if (this.enableLogging) {
|
|
189
|
+
console.log(ex);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return handleErrorCodes(ex);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async getAllPinUsernames(): Promise<AuthsignalResponse<string[]>> {
|
|
197
|
+
await this.ensureModuleIsInitialized();
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
const data = await AuthsignalInAppModule.getAllPinUsernames();
|
|
201
|
+
return { data };
|
|
202
|
+
} catch (ex) {
|
|
203
|
+
if (this.enableLogging) {
|
|
204
|
+
console.log(ex);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return handleErrorCodes(ex);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private async ensureModuleIsInitialized() {
|
|
212
|
+
if (this.initialized) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
await AuthsignalInAppModule.initialize(this.tenantID, this.baseURL);
|
|
217
|
+
|
|
218
|
+
this.initialized = true;
|
|
219
|
+
}
|
|
220
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { getNativeModule } from './getNativeModule';
|
|
2
|
+
import NativeAuthsignalModule, {
|
|
3
|
+
type Spec as AuthsignalModuleSpec,
|
|
4
|
+
} from './NativeAuthsignalModule';
|
|
5
|
+
import { AuthsignalEmail } from './email';
|
|
6
|
+
import { AuthsignalPasskey } from './passkey';
|
|
7
|
+
import { AuthsignalPush } from './push';
|
|
8
|
+
import { AuthsignalSms } from './sms';
|
|
9
|
+
import { AuthsignalTotp } from './totp';
|
|
10
|
+
import { AuthsignalQrCode } from './qr';
|
|
11
|
+
import { AuthsignalWhatsapp } from './whatsapp';
|
|
12
|
+
import { AuthsignalInApp } from './inapp';
|
|
13
|
+
import type { LaunchOptions } from './types';
|
|
14
|
+
|
|
15
|
+
export * from './types';
|
|
16
|
+
export { ErrorCode } from './error';
|
|
17
|
+
|
|
18
|
+
const AuthsignalModule = getNativeModule<AuthsignalModuleSpec>(
|
|
19
|
+
'AuthsignalModule',
|
|
20
|
+
NativeAuthsignalModule
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
interface ConstructorArgs {
|
|
24
|
+
tenantID: string;
|
|
25
|
+
baseURL?: string;
|
|
26
|
+
deviceID?: string;
|
|
27
|
+
enableLogging?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class Authsignal {
|
|
31
|
+
tenantID: string;
|
|
32
|
+
baseURL: string;
|
|
33
|
+
enableLogging: boolean;
|
|
34
|
+
|
|
35
|
+
email: AuthsignalEmail;
|
|
36
|
+
passkey: AuthsignalPasskey;
|
|
37
|
+
push: AuthsignalPush;
|
|
38
|
+
qr: AuthsignalQrCode;
|
|
39
|
+
inapp: AuthsignalInApp;
|
|
40
|
+
sms: AuthsignalSms;
|
|
41
|
+
totp: AuthsignalTotp;
|
|
42
|
+
whatsapp: AuthsignalWhatsapp;
|
|
43
|
+
|
|
44
|
+
constructor({
|
|
45
|
+
tenantID,
|
|
46
|
+
baseURL = 'https://api.authsignal.com/v1',
|
|
47
|
+
deviceID,
|
|
48
|
+
enableLogging = __DEV__,
|
|
49
|
+
}: ConstructorArgs) {
|
|
50
|
+
this.tenantID = tenantID;
|
|
51
|
+
this.baseURL = baseURL;
|
|
52
|
+
this.enableLogging = enableLogging;
|
|
53
|
+
|
|
54
|
+
const input = { tenantID, baseURL, deviceID, enableLogging };
|
|
55
|
+
|
|
56
|
+
this.passkey = new AuthsignalPasskey(input);
|
|
57
|
+
this.email = new AuthsignalEmail(input);
|
|
58
|
+
this.push = new AuthsignalPush(input);
|
|
59
|
+
this.qr = new AuthsignalQrCode(input);
|
|
60
|
+
this.inapp = new AuthsignalInApp(input);
|
|
61
|
+
this.sms = new AuthsignalSms(input);
|
|
62
|
+
this.totp = new AuthsignalTotp(input);
|
|
63
|
+
this.whatsapp = new AuthsignalWhatsapp(input);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async setToken(token: string): Promise<void> {
|
|
67
|
+
await AuthsignalModule.setToken(token);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async launch(url: string, _options?: LaunchOptions): Promise<string | null> {
|
|
71
|
+
return await launch(url);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function launch(
|
|
76
|
+
url: string,
|
|
77
|
+
_options?: LaunchOptions
|
|
78
|
+
): Promise<string | null> {
|
|
79
|
+
return AuthsignalModule.launch(url);
|
|
80
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { getOrCreateWebClient } from './web-client';
|
|
2
|
+
import { AuthsignalEmail } from './email';
|
|
3
|
+
import { AuthsignalPasskey } from './passkey';
|
|
4
|
+
import { AuthsignalSms } from './sms';
|
|
5
|
+
import { AuthsignalTotp } from './totp';
|
|
6
|
+
import { AuthsignalWhatsapp } from './whatsapp';
|
|
7
|
+
import type { LaunchOptions } from './types';
|
|
8
|
+
|
|
9
|
+
export * from './types';
|
|
10
|
+
export { ErrorCode } from './error';
|
|
11
|
+
|
|
12
|
+
interface ConstructorArgs {
|
|
13
|
+
tenantID: string;
|
|
14
|
+
baseURL?: string;
|
|
15
|
+
deviceID?: string;
|
|
16
|
+
enableLogging?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let _lastClient: {
|
|
20
|
+
tenantID: string;
|
|
21
|
+
baseURL: string;
|
|
22
|
+
enableLogging: boolean;
|
|
23
|
+
} | null = null;
|
|
24
|
+
|
|
25
|
+
export class Authsignal {
|
|
26
|
+
tenantID: string;
|
|
27
|
+
baseURL: string;
|
|
28
|
+
enableLogging: boolean;
|
|
29
|
+
|
|
30
|
+
email: AuthsignalEmail;
|
|
31
|
+
passkey: AuthsignalPasskey;
|
|
32
|
+
sms: AuthsignalSms;
|
|
33
|
+
totp: AuthsignalTotp;
|
|
34
|
+
whatsapp: AuthsignalWhatsapp;
|
|
35
|
+
|
|
36
|
+
constructor({
|
|
37
|
+
tenantID,
|
|
38
|
+
baseURL = 'https://api.authsignal.com/v1',
|
|
39
|
+
deviceID,
|
|
40
|
+
enableLogging = false,
|
|
41
|
+
}: ConstructorArgs) {
|
|
42
|
+
this.tenantID = tenantID;
|
|
43
|
+
this.baseURL = baseURL;
|
|
44
|
+
this.enableLogging = enableLogging;
|
|
45
|
+
|
|
46
|
+
_lastClient = { tenantID, baseURL, enableLogging };
|
|
47
|
+
|
|
48
|
+
const input = { tenantID, baseURL, enableLogging };
|
|
49
|
+
|
|
50
|
+
this.passkey = new AuthsignalPasskey({ ...input, deviceID });
|
|
51
|
+
this.email = new AuthsignalEmail(input);
|
|
52
|
+
this.sms = new AuthsignalSms(input);
|
|
53
|
+
this.totp = new AuthsignalTotp(input);
|
|
54
|
+
this.whatsapp = new AuthsignalWhatsapp(input);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async setToken(token: string): Promise<void> {
|
|
58
|
+
const client = getOrCreateWebClient({
|
|
59
|
+
tenantID: this.tenantID,
|
|
60
|
+
baseURL: this.baseURL,
|
|
61
|
+
enableLogging: this.enableLogging,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
client.setToken(token);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async launch(url: string, options?: LaunchOptions): Promise<string | null> {
|
|
68
|
+
return await launch(url, options);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function launch(
|
|
73
|
+
url: string,
|
|
74
|
+
options?: LaunchOptions
|
|
75
|
+
): Promise<string | null> {
|
|
76
|
+
if (_lastClient) {
|
|
77
|
+
const client = getOrCreateWebClient({
|
|
78
|
+
tenantID: _lastClient.tenantID,
|
|
79
|
+
baseURL: _lastClient.baseURL,
|
|
80
|
+
enableLogging: _lastClient.enableLogging,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
if (options?.mode === 'redirect') {
|
|
84
|
+
client.launch(url, { mode: 'redirect' });
|
|
85
|
+
return Promise.resolve(null);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return client.launch(url, { mode: 'popup' }).then((result) => {
|
|
89
|
+
return result?.token ?? null;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Fallback if no Authsignal instance has been created yet
|
|
94
|
+
if (typeof window !== 'undefined') {
|
|
95
|
+
window.open(url, '_blank');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return Promise.resolve(null);
|
|
99
|
+
}
|