@prove-identity/prove-auth 2.3.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/LICENSE +404 -0
- package/README.md +17 -0
- package/build/lib/index.d.ts +12 -0
- package/build/lib/index.js +47 -0
- package/build/lib/proveauth/auth-finish-step.d.ts +7 -0
- package/build/lib/proveauth/auth-finish-step.js +2 -0
- package/build/lib/proveauth/authenticator-builder.d.ts +42 -0
- package/build/lib/proveauth/authenticator-builder.js +126 -0
- package/build/lib/proveauth/authenticator.d.ts +12 -0
- package/build/lib/proveauth/authenticator.js +2 -0
- package/build/lib/proveauth/common/base64.d.ts +5 -0
- package/build/lib/proveauth/common/base64.js +19 -0
- package/build/lib/proveauth/common/cancelable-promise.d.ts +5 -0
- package/build/lib/proveauth/common/cancelable-promise.js +15 -0
- package/build/lib/proveauth/common/logger.d.ts +25 -0
- package/build/lib/proveauth/common/logger.js +85 -0
- package/build/lib/proveauth/instantlink.d.ts +4 -0
- package/build/lib/proveauth/instantlink.js +2 -0
- package/build/lib/proveauth/internal/auth-error.d.ts +7 -0
- package/build/lib/proveauth/internal/auth-error.js +27 -0
- package/build/lib/proveauth/internal/auth-message.d.ts +12 -0
- package/build/lib/proveauth/internal/auth-message.js +2 -0
- package/build/lib/proveauth/internal/auth-request.d.ts +90 -0
- package/build/lib/proveauth/internal/auth-request.js +2 -0
- package/build/lib/proveauth/internal/auth-response-status.d.ts +8 -0
- package/build/lib/proveauth/internal/auth-response-status.js +12 -0
- package/build/lib/proveauth/internal/auth-response.d.ts +61 -0
- package/build/lib/proveauth/internal/auth-response.js +2 -0
- package/build/lib/proveauth/internal/auth-session.d.ts +30 -0
- package/build/lib/proveauth/internal/auth-session.js +156 -0
- package/build/lib/proveauth/internal/auth-step.d.ts +5 -0
- package/build/lib/proveauth/internal/auth-step.js +2 -0
- package/build/lib/proveauth/internal/auth-token-claims.d.ts +46 -0
- package/build/lib/proveauth/internal/auth-token-claims.js +9 -0
- package/build/lib/proveauth/internal/base-authenticator.d.ts +28 -0
- package/build/lib/proveauth/internal/base-authenticator.js +129 -0
- package/build/lib/proveauth/internal/device-auth.d.ts +22 -0
- package/build/lib/proveauth/internal/device-auth.js +2 -0
- package/build/lib/proveauth/internal/device-passive-register-step.d.ts +10 -0
- package/build/lib/proveauth/internal/device-passive-register-step.js +97 -0
- package/build/lib/proveauth/internal/device-passive-silent-step.d.ts +10 -0
- package/build/lib/proveauth/internal/device-passive-silent-step.js +98 -0
- package/build/lib/proveauth/internal/device-passive-step.d.ts +17 -0
- package/build/lib/proveauth/internal/device-passive-step.js +133 -0
- package/build/lib/proveauth/internal/device-passive-stepup-step.d.ts +9 -0
- package/build/lib/proveauth/internal/device-passive-stepup-step.js +25 -0
- package/build/lib/proveauth/internal/device-passive-verify-step.d.ts +8 -0
- package/build/lib/proveauth/internal/device-passive-verify-step.js +54 -0
- package/build/lib/proveauth/internal/error-code.d.ts +9 -0
- package/build/lib/proveauth/internal/error-code.js +12 -0
- package/build/lib/proveauth/internal/mobile-instant-step.d.ts +15 -0
- package/build/lib/proveauth/internal/mobile-instant-step.js +100 -0
- package/build/lib/proveauth/internal/mobile-instantlink-step.d.ts +14 -0
- package/build/lib/proveauth/internal/mobile-instantlink-step.js +108 -0
- package/build/lib/proveauth/internal/mobile-otp-step.d.ts +14 -0
- package/build/lib/proveauth/internal/mobile-otp-step.js +141 -0
- package/build/lib/proveauth/internal/phone-number-input.d.ts +11 -0
- package/build/lib/proveauth/internal/phone-number-input.js +13 -0
- package/build/lib/proveauth/internal/platform.d.ts +45 -0
- package/build/lib/proveauth/internal/platform.js +20 -0
- package/build/lib/proveauth/internal/primary-authenticator.d.ts +14 -0
- package/build/lib/proveauth/internal/primary-authenticator.js +64 -0
- package/build/lib/proveauth/internal/report-error-step.d.ts +16 -0
- package/build/lib/proveauth/internal/report-error-step.js +88 -0
- package/build/lib/proveauth/internal/request-signer-v3.d.ts +10 -0
- package/build/lib/proveauth/internal/request-signer-v3.js +104 -0
- package/build/lib/proveauth/internal/scan-message-step.d.ts +11 -0
- package/build/lib/proveauth/internal/scan-message-step.js +45 -0
- package/build/lib/proveauth/internal/secondary-authenticator.d.ts +10 -0
- package/build/lib/proveauth/internal/secondary-authenticator.js +65 -0
- package/build/lib/proveauth/internal/settings.d.ts +18 -0
- package/build/lib/proveauth/internal/settings.js +50 -0
- package/build/lib/proveauth/internal/user-mobileactive-step.d.ts +7 -0
- package/build/lib/proveauth/internal/user-mobileactive-step.js +18 -0
- package/build/lib/proveauth/internal/user-present-step.d.ts +7 -0
- package/build/lib/proveauth/internal/user-present-step.js +18 -0
- package/build/lib/proveauth/internal/web-device-auth.d.ts +32 -0
- package/build/lib/proveauth/internal/web-device-auth.js +242 -0
- package/build/lib/proveauth/internal/web-platform.d.ts +30 -0
- package/build/lib/proveauth/internal/web-platform.js +160 -0
- package/build/lib/proveauth/otp.d.ts +23 -0
- package/build/lib/proveauth/otp.js +18 -0
- package/build/lib/proveauth/version.d.ts +3 -0
- package/build/lib/proveauth/version.js +6 -0
- package/package.json +75 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import CancelablePromise from './common/cancelable-promise';
|
|
2
|
+
export default interface Authenticator {
|
|
3
|
+
authenticate: (authToken: string) => CancelablePromise<void>;
|
|
4
|
+
isPasskeyRegistered: () => boolean;
|
|
5
|
+
isFidoSupported: () => boolean;
|
|
6
|
+
isDeviceRegistered: () => boolean;
|
|
7
|
+
isMobileWeb: () => boolean;
|
|
8
|
+
getDeviceId: () => string | null;
|
|
9
|
+
resetDeviceSettings: () => void;
|
|
10
|
+
unregisterDevice: () => Promise<void>;
|
|
11
|
+
unregisterPasskey: () => Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Base64 {
|
|
4
|
+
static stringToBase64(value) {
|
|
5
|
+
return (value.replace(/\-/g, '+').replace(/_/g, '/') +
|
|
6
|
+
'='.repeat(value.length % 4 ? 4 - (value.length % 4) : 0));
|
|
7
|
+
}
|
|
8
|
+
static bufferDecode(value) {
|
|
9
|
+
return Uint8Array.from(atob(Base64.stringToBase64(value)), (c) => c.charCodeAt(0));
|
|
10
|
+
}
|
|
11
|
+
static bufferEncode(value) {
|
|
12
|
+
const arrayValue = ArrayBuffer.isView(value) ? value.buffer : value;
|
|
13
|
+
return btoa(String.fromCharCode.apply(null, Array.from(new Uint8Array(arrayValue))))
|
|
14
|
+
.replace(/\+/g, '-')
|
|
15
|
+
.replace(/\//g, '_')
|
|
16
|
+
.replace(/=/g, '');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.default = Base64;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class CancelablePromise extends Promise {
|
|
4
|
+
constructor(executor) {
|
|
5
|
+
let onCancel = () => { };
|
|
6
|
+
super((resolve, reject) => executor(resolve, reject, (handler) => (onCancel = handler)));
|
|
7
|
+
this.onCancel = () => {
|
|
8
|
+
onCancel();
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
cancel() {
|
|
12
|
+
this.onCancel();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = CancelablePromise;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare enum LogLevel {
|
|
2
|
+
disabled = 0,
|
|
3
|
+
error = 1,
|
|
4
|
+
warn = 2,
|
|
5
|
+
info = 3,
|
|
6
|
+
debug = 4,
|
|
7
|
+
trace = 5
|
|
8
|
+
}
|
|
9
|
+
export interface LogWriter {
|
|
10
|
+
write: (level: LogLevel, ...args: any[]) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface Logger {
|
|
13
|
+
trace: (...args: any[]) => void;
|
|
14
|
+
debug: (...args: any[]) => void;
|
|
15
|
+
info: (...args: any[]) => void;
|
|
16
|
+
warn: (...args: any[]) => void;
|
|
17
|
+
error: (...args: any[]) => void;
|
|
18
|
+
}
|
|
19
|
+
export declare class LoggerFactory {
|
|
20
|
+
private static logWriter;
|
|
21
|
+
private static logLevel;
|
|
22
|
+
static setLogLevel(logLevel: LogLevel): void;
|
|
23
|
+
static setLogWriter(logWriter: LogWriter): void;
|
|
24
|
+
static getLogger(name: string): Logger;
|
|
25
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggerFactory = exports.LogLevel = void 0;
|
|
4
|
+
var LogLevel;
|
|
5
|
+
(function (LogLevel) {
|
|
6
|
+
LogLevel[LogLevel["disabled"] = 0] = "disabled";
|
|
7
|
+
LogLevel[LogLevel["error"] = 1] = "error";
|
|
8
|
+
LogLevel[LogLevel["warn"] = 2] = "warn";
|
|
9
|
+
LogLevel[LogLevel["info"] = 3] = "info";
|
|
10
|
+
LogLevel[LogLevel["debug"] = 4] = "debug";
|
|
11
|
+
LogLevel[LogLevel["trace"] = 5] = "trace";
|
|
12
|
+
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
|
|
13
|
+
class ConsoleLogger {
|
|
14
|
+
trace(...args) {
|
|
15
|
+
console.info(...args);
|
|
16
|
+
}
|
|
17
|
+
debug(...args) {
|
|
18
|
+
console.info(...args);
|
|
19
|
+
}
|
|
20
|
+
info(...args) {
|
|
21
|
+
console.info(...args);
|
|
22
|
+
}
|
|
23
|
+
warn(...args) {
|
|
24
|
+
console.warn(...args);
|
|
25
|
+
}
|
|
26
|
+
error(...args) {
|
|
27
|
+
console.error(...args);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
class ConsoleLogWriter {
|
|
31
|
+
write(level, ...args) {
|
|
32
|
+
switch (level) {
|
|
33
|
+
case LogLevel.trace:
|
|
34
|
+
console.debug(...args);
|
|
35
|
+
break;
|
|
36
|
+
case LogLevel.debug:
|
|
37
|
+
console.debug(...args);
|
|
38
|
+
break;
|
|
39
|
+
case LogLevel.info:
|
|
40
|
+
console.info(...args);
|
|
41
|
+
break;
|
|
42
|
+
case LogLevel.warn:
|
|
43
|
+
console.warn(...args);
|
|
44
|
+
break;
|
|
45
|
+
case LogLevel.error:
|
|
46
|
+
console.error(...args);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
class LoggerFactory {
|
|
52
|
+
static setLogLevel(logLevel) {
|
|
53
|
+
LoggerFactory.logLevel = logLevel;
|
|
54
|
+
}
|
|
55
|
+
static setLogWriter(logWriter) {
|
|
56
|
+
LoggerFactory.logWriter = logWriter;
|
|
57
|
+
}
|
|
58
|
+
static getLogger(name) {
|
|
59
|
+
return {
|
|
60
|
+
trace: (...args) => {
|
|
61
|
+
if (LoggerFactory.logLevel >= LogLevel.trace)
|
|
62
|
+
LoggerFactory.logWriter.write(LogLevel.trace, name + ': ', ...args);
|
|
63
|
+
},
|
|
64
|
+
debug: (...args) => {
|
|
65
|
+
if (LoggerFactory.logLevel >= LogLevel.debug)
|
|
66
|
+
LoggerFactory.logWriter.write(LogLevel.debug, name + ': ', ...args);
|
|
67
|
+
},
|
|
68
|
+
info: (...args) => {
|
|
69
|
+
if (LoggerFactory.logLevel >= LogLevel.info)
|
|
70
|
+
LoggerFactory.logWriter.write(LogLevel.info, name + ': ', ...args);
|
|
71
|
+
},
|
|
72
|
+
warn: (...args) => {
|
|
73
|
+
if (LoggerFactory.logLevel >= LogLevel.warn)
|
|
74
|
+
LoggerFactory.logWriter.write(LogLevel.warn, name + ': ', ...args);
|
|
75
|
+
},
|
|
76
|
+
error: (...args) => {
|
|
77
|
+
if (LoggerFactory.logLevel >= LogLevel.error)
|
|
78
|
+
LoggerFactory.logWriter.write(LogLevel.error, name + ': ', ...args);
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
LoggerFactory.logWriter = new ConsoleLogWriter();
|
|
84
|
+
LoggerFactory.logLevel = LogLevel.info;
|
|
85
|
+
exports.LoggerFactory = LoggerFactory;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export default class AuthError extends Error {
|
|
2
|
+
readonly code?: number;
|
|
3
|
+
readonly nextStep?: string;
|
|
4
|
+
readonly reportable: boolean;
|
|
5
|
+
constructor(message?: string, code?: number, nextStep?: string, reportable?: boolean);
|
|
6
|
+
static extractMessage(error: any): string;
|
|
7
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class AuthError extends Error {
|
|
4
|
+
constructor(message, code, nextStep, reportable) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.nextStep = nextStep;
|
|
8
|
+
this.reportable = reportable === undefined || reportable;
|
|
9
|
+
}
|
|
10
|
+
static extractMessage(error) {
|
|
11
|
+
let message = '';
|
|
12
|
+
if (error) {
|
|
13
|
+
const messageKey = 'message';
|
|
14
|
+
if (error[messageKey]) {
|
|
15
|
+
message = error[messageKey];
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
message = error.toString();
|
|
19
|
+
if (message === '[object Object]') {
|
|
20
|
+
message = JSON.stringify(error);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return message;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.default = AuthError;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export default interface AuthMessage {
|
|
2
|
+
title: string;
|
|
3
|
+
body: string;
|
|
4
|
+
confirmBtn: string;
|
|
5
|
+
denyBtn: string;
|
|
6
|
+
originatingIp?: string;
|
|
7
|
+
originatingIpLocation?: string;
|
|
8
|
+
originatingDevice?: string;
|
|
9
|
+
distanceFromOriginator?: number;
|
|
10
|
+
timestamp: number;
|
|
11
|
+
exp: number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { MobileAuthImplementation } from '../authenticator-builder';
|
|
2
|
+
import { AuthResponseStatus } from './auth-response-status';
|
|
3
|
+
export type AuthRequest = V1ClientDeviceFido2RegisterStart | V1ClientDeviceFido2RegisterFinish | V1ClientDeviceFido2VerifyStart | V1ClientDeviceFido2VerifyFinish | V1ClientDevicePassiveRegister | V1ClientDevicePassiveVerify | V1ClientUserResponse | V1ClientAnyError | V1ClientChallenge | V1ClientMobileInstantLinkStart | V1ClientMobileInstantStart | V1ClientMobileInstantFinish | V1ClientOtpStart | V1ClientOtpFinish;
|
|
4
|
+
export type AuthRegistration = PassiveRegistration | Fido2Registration;
|
|
5
|
+
export interface PublicKey {
|
|
6
|
+
id: string;
|
|
7
|
+
alg: string;
|
|
8
|
+
key: string;
|
|
9
|
+
uvLevel: 0;
|
|
10
|
+
}
|
|
11
|
+
export interface PassiveRegistration {
|
|
12
|
+
publicKey: PublicKey;
|
|
13
|
+
signature: string;
|
|
14
|
+
}
|
|
15
|
+
export interface WebAuthnCredentialResponse {
|
|
16
|
+
attestationObject: string;
|
|
17
|
+
clientDataJSON: string;
|
|
18
|
+
}
|
|
19
|
+
export interface WebAuthnCredential {
|
|
20
|
+
type: string;
|
|
21
|
+
id: string;
|
|
22
|
+
rawId: string;
|
|
23
|
+
response: WebAuthnCredentialResponse;
|
|
24
|
+
}
|
|
25
|
+
export interface Fido2Registration {
|
|
26
|
+
webAuthnCredential: WebAuthnCredential;
|
|
27
|
+
}
|
|
28
|
+
export interface V1ClientDeviceFido2RegisterStart {
|
|
29
|
+
displayName?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface V1ClientDeviceFido2RegisterFinish {
|
|
32
|
+
deviceName: string;
|
|
33
|
+
deviceCapabilities: string[];
|
|
34
|
+
registrations: AuthRegistration[];
|
|
35
|
+
}
|
|
36
|
+
export interface V1ClientDeviceFido2VerifyStart {
|
|
37
|
+
deviceId: string;
|
|
38
|
+
}
|
|
39
|
+
export interface WebAuthnAssertionResponse {
|
|
40
|
+
authenticatorData: string;
|
|
41
|
+
clientDataJSON: string;
|
|
42
|
+
signature: string;
|
|
43
|
+
userHandle?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface WebAuthnAssertion {
|
|
46
|
+
type: string;
|
|
47
|
+
id: string;
|
|
48
|
+
rawId: string;
|
|
49
|
+
response: WebAuthnAssertionResponse;
|
|
50
|
+
}
|
|
51
|
+
export interface V1ClientDeviceFido2VerifyFinish {
|
|
52
|
+
webAuthnAssertion: WebAuthnAssertion;
|
|
53
|
+
}
|
|
54
|
+
export interface V1ClientDevicePassiveRegister {
|
|
55
|
+
deviceName: string;
|
|
56
|
+
deviceCapabilities: string[];
|
|
57
|
+
registrations: PassiveRegistration[];
|
|
58
|
+
}
|
|
59
|
+
export interface V1ClientDevicePassiveVerify {
|
|
60
|
+
deviceId: string;
|
|
61
|
+
keyId: string;
|
|
62
|
+
signature: string;
|
|
63
|
+
}
|
|
64
|
+
export interface V1ClientUserResponse {
|
|
65
|
+
response: AuthResponseStatus;
|
|
66
|
+
}
|
|
67
|
+
export interface V1ClientAnyError {
|
|
68
|
+
code?: number;
|
|
69
|
+
message: string;
|
|
70
|
+
}
|
|
71
|
+
export interface V1ClientChallenge {
|
|
72
|
+
deviceId: string;
|
|
73
|
+
}
|
|
74
|
+
export interface V1ClientMobileInstantLinkStart {
|
|
75
|
+
sourceIp?: string | null;
|
|
76
|
+
mobileNumber?: string | null;
|
|
77
|
+
}
|
|
78
|
+
export interface V1ClientMobileInstantStart {
|
|
79
|
+
cellularIp?: string | null;
|
|
80
|
+
implementation?: MobileAuthImplementation;
|
|
81
|
+
}
|
|
82
|
+
export interface V1ClientMobileInstantFinish {
|
|
83
|
+
vfp: string;
|
|
84
|
+
}
|
|
85
|
+
export interface V1ClientOtpStart {
|
|
86
|
+
mobileNumber?: string | null;
|
|
87
|
+
}
|
|
88
|
+
export interface V1ClientOtpFinish {
|
|
89
|
+
otp: string;
|
|
90
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthResponseStatus = void 0;
|
|
4
|
+
var AuthResponseStatus;
|
|
5
|
+
(function (AuthResponseStatus) {
|
|
6
|
+
AuthResponseStatus["Accept"] = "accept";
|
|
7
|
+
AuthResponseStatus["Reject"] = "reject";
|
|
8
|
+
AuthResponseStatus["Cancel"] = "cancel";
|
|
9
|
+
AuthResponseStatus["Unexpected"] = "unexpected";
|
|
10
|
+
AuthResponseStatus["Timeout"] = "timeout";
|
|
11
|
+
AuthResponseStatus["Unknown"] = "unknown";
|
|
12
|
+
})(AuthResponseStatus = exports.AuthResponseStatus || (exports.AuthResponseStatus = {}));
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import AuthMessage from './auth-message';
|
|
2
|
+
export default interface AuthResponse {
|
|
3
|
+
next: string;
|
|
4
|
+
error?: AuthFailure;
|
|
5
|
+
refreshDeviceTrust?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface AuthFailure {
|
|
8
|
+
message: string;
|
|
9
|
+
code: number;
|
|
10
|
+
}
|
|
11
|
+
export interface RegisterStartAuthResponseData {
|
|
12
|
+
credCreateOptions: PublicKeyCredentialCreationOptions;
|
|
13
|
+
}
|
|
14
|
+
export interface RegisterStartAuthResponse extends AuthResponse {
|
|
15
|
+
data: RegisterStartAuthResponseData;
|
|
16
|
+
}
|
|
17
|
+
export interface RegisterFinishAuthResponseData {
|
|
18
|
+
deviceId: string;
|
|
19
|
+
}
|
|
20
|
+
export interface RegisterFinishAuthResponse extends AuthResponse {
|
|
21
|
+
data: RegisterFinishAuthResponseData;
|
|
22
|
+
}
|
|
23
|
+
export type DeviceRegisterAuthResponse = RegisterFinishAuthResponse;
|
|
24
|
+
export interface VerifyStartAuthResponseData {
|
|
25
|
+
credRequestOptions: PublicKeyCredentialRequestOptions;
|
|
26
|
+
}
|
|
27
|
+
export interface VerifyStartAuthResponse extends AuthResponse {
|
|
28
|
+
data: VerifyStartAuthResponseData;
|
|
29
|
+
}
|
|
30
|
+
export interface VerifyFinishAuthResponseData {
|
|
31
|
+
scanMessage?: AuthMessage;
|
|
32
|
+
}
|
|
33
|
+
export interface VerifyFinishAuthResponse extends AuthResponse {
|
|
34
|
+
data?: VerifyFinishAuthResponseData;
|
|
35
|
+
}
|
|
36
|
+
export interface ChallengeResponse extends AuthResponse {
|
|
37
|
+
deviceId?: string;
|
|
38
|
+
challenge?: string;
|
|
39
|
+
ttl?: number;
|
|
40
|
+
receivedAt?: number;
|
|
41
|
+
}
|
|
42
|
+
export interface MobileStartAuthResponseData {
|
|
43
|
+
redirectUrl?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface MobileStartAuthResponse extends AuthResponse {
|
|
46
|
+
data?: MobileStartAuthResponseData;
|
|
47
|
+
}
|
|
48
|
+
export interface OtpStartResponse extends AuthResponse {
|
|
49
|
+
data?: OtpResponseData;
|
|
50
|
+
}
|
|
51
|
+
export interface OtpFinishResponse extends AuthResponse {
|
|
52
|
+
data?: OtpResponseData;
|
|
53
|
+
}
|
|
54
|
+
export interface OtpResponseData {
|
|
55
|
+
code?: number;
|
|
56
|
+
message?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface InstantLinkStartResponse extends AuthResponse {
|
|
59
|
+
data?: InstantLinkResponseData;
|
|
60
|
+
}
|
|
61
|
+
export type InstantLinkResponseData = OtpResponseData;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="webappsec-credential-management" />
|
|
2
|
+
import AuthMessage from './auth-message';
|
|
3
|
+
import { AuthRequest } from './auth-request';
|
|
4
|
+
import AuthResponse from './auth-response';
|
|
5
|
+
import AuthTokenClaims, { UserVerificationLevel } from './auth-token-claims';
|
|
6
|
+
import { DeviceRegistration } from './device-auth';
|
|
7
|
+
import Platform, { AuthSessionIntegration, MessageChannel, RequestSigner } from './platform';
|
|
8
|
+
import Settings from './settings';
|
|
9
|
+
export default class AuthSession implements AuthSessionIntegration {
|
|
10
|
+
readonly platform: Platform;
|
|
11
|
+
readonly authToken?: string;
|
|
12
|
+
readonly claims?: AuthTokenClaims;
|
|
13
|
+
readonly settings: Settings;
|
|
14
|
+
readonly requestSigner: RequestSigner;
|
|
15
|
+
lastStep: string | null;
|
|
16
|
+
credential: CredentialType | null;
|
|
17
|
+
authMessage: AuthMessage | null;
|
|
18
|
+
uvLevel: UserVerificationLevel | null;
|
|
19
|
+
backendUrlOverride: string | null;
|
|
20
|
+
get namespace(): string;
|
|
21
|
+
get backendUrl(): string;
|
|
22
|
+
get authId(): string;
|
|
23
|
+
get challenge(): string;
|
|
24
|
+
get next(): string;
|
|
25
|
+
constructor(settings: Settings, platform: Platform, authToken?: string);
|
|
26
|
+
fetchFromBackend(query: string, body: AuthRequest): Promise<AuthResponse>;
|
|
27
|
+
createMessageChannel(endpointPath: string, onClose: () => void, onError: (message: string) => void, onMessage: (data: string) => void): MessageChannel;
|
|
28
|
+
getDeviceRegistration(): Promise<DeviceRegistration | null>;
|
|
29
|
+
private parseJwt;
|
|
30
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const logger_1 = require("../common/logger");
|
|
7
|
+
const version_1 = require("../version");
|
|
8
|
+
const auth_token_claims_1 = require("./auth-token-claims");
|
|
9
|
+
const error_code_1 = __importDefault(require("./error-code"));
|
|
10
|
+
class AuthSession {
|
|
11
|
+
get namespace() {
|
|
12
|
+
var _a;
|
|
13
|
+
return ((_a = this.claims) === null || _a === void 0 ? void 0 : _a.auth.ans) || this.settings.namespace;
|
|
14
|
+
}
|
|
15
|
+
get backendUrl() {
|
|
16
|
+
var _a;
|
|
17
|
+
return ((_a = this.claims) === null || _a === void 0 ? void 0 : _a.auth.endp) || this.backendUrlOverride;
|
|
18
|
+
}
|
|
19
|
+
get authId() {
|
|
20
|
+
var _a;
|
|
21
|
+
return (_a = this.claims) === null || _a === void 0 ? void 0 : _a.auth.id;
|
|
22
|
+
}
|
|
23
|
+
get challenge() {
|
|
24
|
+
var _a;
|
|
25
|
+
return (_a = this.claims) === null || _a === void 0 ? void 0 : _a.auth.chlg;
|
|
26
|
+
}
|
|
27
|
+
get next() {
|
|
28
|
+
var _a;
|
|
29
|
+
return (_a = this.claims) === null || _a === void 0 ? void 0 : _a.auth.next;
|
|
30
|
+
}
|
|
31
|
+
constructor(settings, platform, authToken) {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
this.lastStep = null;
|
|
34
|
+
this.credential = null;
|
|
35
|
+
this.authMessage = null;
|
|
36
|
+
this.uvLevel = null;
|
|
37
|
+
this.backendUrlOverride = null;
|
|
38
|
+
this.platform = platform;
|
|
39
|
+
this.authToken = authToken;
|
|
40
|
+
this.settings = settings;
|
|
41
|
+
if (authToken) {
|
|
42
|
+
this.claims = this.parseJwt(authToken);
|
|
43
|
+
this.settings.namespace = this.claims.auth.ans;
|
|
44
|
+
this.uvLevel =
|
|
45
|
+
((_b = (_a = this.claims.auth.subs.dev) === null || _a === void 0 ? void 0 : _a.auths.pasv) === null || _b === void 0 ? void 0 : _b.uvlvl) || auth_token_claims_1.UserVerificationLevel.Discouraged;
|
|
46
|
+
}
|
|
47
|
+
this.requestSigner = platform.createRequestSigner(this);
|
|
48
|
+
}
|
|
49
|
+
fetchFromBackend(query, body) {
|
|
50
|
+
const method = 'POST';
|
|
51
|
+
const contentType = 'application/json';
|
|
52
|
+
const bodyStr = JSON.stringify(body);
|
|
53
|
+
const querySplit = query.split('?');
|
|
54
|
+
const path = querySplit[0];
|
|
55
|
+
const params = querySplit.length > 1 ? querySplit[1] : '';
|
|
56
|
+
const headers = new Headers({
|
|
57
|
+
Accept: contentType,
|
|
58
|
+
'Content-Type': contentType,
|
|
59
|
+
'PA-Version': version_1.USER_AGENT_VERSIONS,
|
|
60
|
+
});
|
|
61
|
+
if (this.authToken) {
|
|
62
|
+
headers.set('Authorization', 'Bearer ' + this.authToken);
|
|
63
|
+
}
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
this.requestSigner
|
|
66
|
+
.sign(method, path, params, contentType, bodyStr)
|
|
67
|
+
.then((signature) => {
|
|
68
|
+
if (signature) {
|
|
69
|
+
headers.set('PA-Sig-Version', signature.version);
|
|
70
|
+
headers.set('PA-Challenge', signature.challenge);
|
|
71
|
+
headers.set('PA-KID', signature.keyId);
|
|
72
|
+
headers.set('PA-Signature', signature.signature);
|
|
73
|
+
}
|
|
74
|
+
this.platform
|
|
75
|
+
.fetch(this.backendUrl + query, {
|
|
76
|
+
mode: 'cors',
|
|
77
|
+
method: method,
|
|
78
|
+
headers: headers,
|
|
79
|
+
body: bodyStr,
|
|
80
|
+
})
|
|
81
|
+
.then((response) => response.json())
|
|
82
|
+
.then((response) => {
|
|
83
|
+
if (response.error) {
|
|
84
|
+
if (response.error.code === error_code_1.default.ERROR_NO_DEVICE_FOUND) {
|
|
85
|
+
this.settings.reset();
|
|
86
|
+
this.platform.deviceAuth.reset();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
resolve(response);
|
|
90
|
+
})
|
|
91
|
+
.catch(reject);
|
|
92
|
+
})
|
|
93
|
+
.catch(reject);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
createMessageChannel(endpointPath, onClose, onError, onMessage) {
|
|
97
|
+
if (!this.authToken) {
|
|
98
|
+
throw new Error('Authentication token is not initialized, cannot create MessageChannel');
|
|
99
|
+
}
|
|
100
|
+
const KEEP_ALIVE_INTERVAL = 30000;
|
|
101
|
+
const endpoint = this.backendUrl.replace(/^http/, 'ws');
|
|
102
|
+
const encodedAuthToken = encodeURIComponent(this.authToken);
|
|
103
|
+
const channel = this.platform.createMessageChannel(endpoint + endpointPath + '?token=' + encodedAuthToken);
|
|
104
|
+
const log = logger_1.LoggerFactory.getLogger('web-message-channel');
|
|
105
|
+
const keepAlive = setInterval(() => {
|
|
106
|
+
log.debug('Sending keep-alive message');
|
|
107
|
+
channel.send('');
|
|
108
|
+
}, KEEP_ALIVE_INTERVAL);
|
|
109
|
+
channel.addEventListener('close', (_) => {
|
|
110
|
+
if (keepAlive) {
|
|
111
|
+
clearInterval(keepAlive);
|
|
112
|
+
}
|
|
113
|
+
onClose();
|
|
114
|
+
});
|
|
115
|
+
channel.addEventListener('error', (event) => {
|
|
116
|
+
if ('message' in event) {
|
|
117
|
+
onError(event['message']);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
onError(event.toString());
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
channel.addEventListener('message', (event) => {
|
|
124
|
+
if ('origin' in event && event['origin'] !== endpoint) {
|
|
125
|
+
onError('Unexpected origin');
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
var data = event.data;
|
|
129
|
+
if (data && typeof data === 'string') {
|
|
130
|
+
onMessage(data);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
onMessage(event.toString());
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return channel;
|
|
138
|
+
}
|
|
139
|
+
getDeviceRegistration() {
|
|
140
|
+
return new Promise((resolve, reject) => {
|
|
141
|
+
this.platform.deviceAuth
|
|
142
|
+
.getRegistration(this.namespace)
|
|
143
|
+
.then((registration) => {
|
|
144
|
+
if (registration) {
|
|
145
|
+
this.backendUrlOverride = registration === null || registration === void 0 ? void 0 : registration.endpoint;
|
|
146
|
+
}
|
|
147
|
+
resolve(registration);
|
|
148
|
+
})
|
|
149
|
+
.catch(reject);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
parseJwt(token) {
|
|
153
|
+
return JSON.parse(atob(token.split('.')[1]));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.default = AuthSession;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare enum UserVerificationLevel {
|
|
2
|
+
Discouraged = "none",
|
|
3
|
+
Preferred = "pref",
|
|
4
|
+
Required = "req"
|
|
5
|
+
}
|
|
6
|
+
export interface PassiveAuthenticator {
|
|
7
|
+
cdt: boolean;
|
|
8
|
+
uvlvl?: UserVerificationLevel;
|
|
9
|
+
}
|
|
10
|
+
export interface InstantAuthenticator {
|
|
11
|
+
}
|
|
12
|
+
export interface InstantLinkAuthenticator {
|
|
13
|
+
mnp: boolean;
|
|
14
|
+
tme?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface OtpAuthenticator {
|
|
17
|
+
mnp: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface Authenticators {
|
|
20
|
+
pasv?: PassiveAuthenticator;
|
|
21
|
+
inst?: InstantAuthenticator;
|
|
22
|
+
inln?: InstantLinkAuthenticator;
|
|
23
|
+
otp?: OtpAuthenticator;
|
|
24
|
+
}
|
|
25
|
+
export interface DeviceAuthSubjectClaim {
|
|
26
|
+
auths: Authenticators;
|
|
27
|
+
}
|
|
28
|
+
export interface MobileAuthSubjectClaim {
|
|
29
|
+
auths: Authenticators;
|
|
30
|
+
}
|
|
31
|
+
export interface AuthSubjectsClaim {
|
|
32
|
+
dev?: DeviceAuthSubjectClaim;
|
|
33
|
+
mob?: MobileAuthSubjectClaim;
|
|
34
|
+
}
|
|
35
|
+
export interface AuthClaim {
|
|
36
|
+
id: string;
|
|
37
|
+
ans: string;
|
|
38
|
+
endp: string;
|
|
39
|
+
chlg: string;
|
|
40
|
+
subs: AuthSubjectsClaim;
|
|
41
|
+
next: string;
|
|
42
|
+
}
|
|
43
|
+
export default interface AuthTokenClaims {
|
|
44
|
+
rid: string;
|
|
45
|
+
auth: AuthClaim;
|
|
46
|
+
}
|