@dfns/sdk 0.1.0-alpha.1 → 0.1.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/baseAuthApi.d.ts +29 -4
- package/baseAuthApi.js +17 -1
- package/dfnsApiClient.d.ts +2 -2
- package/dfnsAuthenticator.d.ts +9 -3
- package/dfnsAuthenticator.js +14 -3
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/signer.d.ts +22 -27
- package/store.d.ts +79 -0
- package/store.js +2 -0
- package/utils/fetch.js +3 -3
package/baseAuthApi.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FirstFactorAttestation, RecoveryFactorAttestation, SecondFactorAttestation, UserRegistrationChallenge } from './store';
|
|
2
|
+
import { AllowCredential, CredentialKind, FirstFactorAssertion, SecondFactorAssertion } from './signer';
|
|
2
3
|
import { HttpMethod } from './utils/fetch';
|
|
3
4
|
export type DfnsBaseApiOptions = {
|
|
4
5
|
appId: string;
|
|
@@ -12,7 +13,6 @@ export type CreateUserActionChallengeRequest = {
|
|
|
12
13
|
userActionHttpPath: string;
|
|
13
14
|
userActionServerKind: 'Api';
|
|
14
15
|
};
|
|
15
|
-
export type CredentialKind = 'Key' | 'Fido2' | 'Password' | 'Totp';
|
|
16
16
|
export type CredentialFactor = 'first' | 'second' | 'either';
|
|
17
17
|
export type UserActionChallengeResponse = {
|
|
18
18
|
supportedCredentialKinds: {
|
|
@@ -41,13 +41,38 @@ export type CreateUserLoginChallengeRequest = {
|
|
|
41
41
|
orgId: string;
|
|
42
42
|
};
|
|
43
43
|
export type UserLoginChallengeResponse = UserActionChallengeResponse;
|
|
44
|
-
export type
|
|
44
|
+
export type CreateUserLoginRequest = SignUserActionChallengeRequest;
|
|
45
45
|
export type UserLoginResponse = {
|
|
46
46
|
token: string;
|
|
47
47
|
};
|
|
48
|
+
export type CreateUserRegistrationChallengeRequest = {
|
|
49
|
+
orgId: string;
|
|
50
|
+
username: string;
|
|
51
|
+
registrationCode: string;
|
|
52
|
+
};
|
|
53
|
+
export type UserRegistrationChallengeResponse = UserRegistrationChallenge;
|
|
54
|
+
export type CreateUserRegistrationRequest = {
|
|
55
|
+
firstFactorCredential: FirstFactorAttestation;
|
|
56
|
+
secondFactorCredential?: SecondFactorAttestation;
|
|
57
|
+
recoveryCredential?: RecoveryFactorAttestation;
|
|
58
|
+
};
|
|
59
|
+
export type UserRegistrationResponse = {
|
|
60
|
+
credential: {
|
|
61
|
+
uuid: string;
|
|
62
|
+
kind: CredentialKind;
|
|
63
|
+
name: string;
|
|
64
|
+
};
|
|
65
|
+
user: {
|
|
66
|
+
id: string;
|
|
67
|
+
username: string;
|
|
68
|
+
orgId: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
48
71
|
export declare class BaseAuthApi {
|
|
49
72
|
static createUserActionChallenge(request: CreateUserActionChallengeRequest, options: DfnsBaseApiOptions): Promise<UserActionChallengeResponse>;
|
|
50
73
|
static signUserActionChallenge(request: SignUserActionChallengeRequest, options: DfnsBaseApiOptions): Promise<UserActionResponse>;
|
|
51
74
|
static createUserLoginChallenge(request: CreateUserLoginChallengeRequest, options: DfnsBaseApiOptions): Promise<UserLoginChallengeResponse>;
|
|
52
|
-
static
|
|
75
|
+
static createUserLogin(request: CreateUserLoginRequest, options: DfnsBaseApiOptions): Promise<UserLoginResponse>;
|
|
76
|
+
static createUserRegistrationChallenge(request: CreateUserRegistrationChallengeRequest, options: DfnsBaseApiOptions): Promise<UserRegistrationChallengeResponse>;
|
|
77
|
+
static createUserRegistration(request: CreateUserRegistrationRequest, options: DfnsBaseApiOptions): Promise<UserRegistrationResponse>;
|
|
53
78
|
}
|
package/baseAuthApi.js
CHANGED
|
@@ -27,7 +27,7 @@ class BaseAuthApi {
|
|
|
27
27
|
});
|
|
28
28
|
return response.json();
|
|
29
29
|
}
|
|
30
|
-
static async
|
|
30
|
+
static async createUserLogin(request, options) {
|
|
31
31
|
const response = await (0, fetch_1.simpleFetch)('/auth/login', {
|
|
32
32
|
method: 'POST',
|
|
33
33
|
body: request,
|
|
@@ -35,5 +35,21 @@ class BaseAuthApi {
|
|
|
35
35
|
});
|
|
36
36
|
return response.json();
|
|
37
37
|
}
|
|
38
|
+
static async createUserRegistrationChallenge(request, options) {
|
|
39
|
+
const response = await (0, fetch_1.simpleFetch)('/auth/registration/init', {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
body: request,
|
|
42
|
+
apiOptions: options,
|
|
43
|
+
});
|
|
44
|
+
return response.json();
|
|
45
|
+
}
|
|
46
|
+
static async createUserRegistration(request, options) {
|
|
47
|
+
const response = await (0, fetch_1.simpleFetch)('/auth/registration', {
|
|
48
|
+
method: 'POST',
|
|
49
|
+
body: request,
|
|
50
|
+
apiOptions: options,
|
|
51
|
+
});
|
|
52
|
+
return response.json();
|
|
53
|
+
}
|
|
38
54
|
}
|
|
39
55
|
exports.BaseAuthApi = BaseAuthApi;
|
package/dfnsApiClient.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ import { PolicyExecutionClient } from './codegen/PolicyExecution';
|
|
|
8
8
|
import { PolicyManagementClient } from './codegen/PolicyManagement';
|
|
9
9
|
import { PublicKeysClient } from './codegen/PublicKeys';
|
|
10
10
|
import { WalletsClient } from './codegen/Wallets';
|
|
11
|
-
import {
|
|
11
|
+
import { CredentialSigner } from './signer';
|
|
12
12
|
export type DfnsApiClientOptions = DfnsBaseApiOptions & {
|
|
13
|
-
signer:
|
|
13
|
+
signer: CredentialSigner;
|
|
14
14
|
};
|
|
15
15
|
export declare class DfnsApiClient {
|
|
16
16
|
private apiOptions;
|
package/dfnsAuthenticator.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CredentialStore } from './store';
|
|
2
|
+
import { CredentialSigner } from './signer';
|
|
3
|
+
import { CreateUserLoginChallengeRequest, CreateUserRegistrationChallengeRequest, DfnsBaseApiOptions, UserLoginResponse, UserRegistrationResponse } from './baseAuthApi';
|
|
3
4
|
export type LoginRequest = CreateUserLoginChallengeRequest;
|
|
4
5
|
export type LoginResponse = UserLoginResponse;
|
|
5
|
-
export type
|
|
6
|
+
export type RegisterRequest = CreateUserRegistrationChallengeRequest;
|
|
7
|
+
export type RegisterResponse = UserRegistrationResponse;
|
|
8
|
+
export type DfnsAuthenticatorOptions = Omit<DfnsBaseApiOptions, 'accessToken'> & {
|
|
9
|
+
signer: CredentialSigner & Partial<CredentialStore>;
|
|
10
|
+
};
|
|
6
11
|
export declare class DfnsAuthenticator {
|
|
7
12
|
private apiOptions;
|
|
8
13
|
private api;
|
|
9
14
|
constructor(apiOptions: DfnsAuthenticatorOptions);
|
|
10
15
|
login(request: LoginRequest): Promise<LoginResponse>;
|
|
16
|
+
register(request: RegisterRequest): Promise<RegisterResponse>;
|
|
11
17
|
}
|
package/dfnsAuthenticator.js
CHANGED
|
@@ -8,11 +8,22 @@ class DfnsAuthenticator {
|
|
|
8
8
|
}
|
|
9
9
|
async login(request) {
|
|
10
10
|
const { challenge, challengeIdentifier, allowCredentials } = await baseAuthApi_1.BaseAuthApi.createUserLoginChallenge(request, this.apiOptions);
|
|
11
|
-
const
|
|
12
|
-
return baseAuthApi_1.BaseAuthApi.
|
|
11
|
+
const assertion = await this.apiOptions.signer.sign(challenge, allowCredentials);
|
|
12
|
+
return baseAuthApi_1.BaseAuthApi.createUserLogin({
|
|
13
13
|
challengeIdentifier,
|
|
14
|
-
|
|
14
|
+
firstFactor: assertion,
|
|
15
15
|
}, this.apiOptions);
|
|
16
16
|
}
|
|
17
|
+
async register(request) {
|
|
18
|
+
if (!this.apiOptions.signer.create) {
|
|
19
|
+
throw new Error(`Provided signer does not implement 'create'`);
|
|
20
|
+
}
|
|
21
|
+
const challenge = await baseAuthApi_1.BaseAuthApi.createUserRegistrationChallenge(request, this.apiOptions);
|
|
22
|
+
const attestation = await this.apiOptions.signer.create(challenge);
|
|
23
|
+
return baseAuthApi_1.BaseAuthApi.createUserRegistration({ firstFactorCredential: attestation }, {
|
|
24
|
+
...this.apiOptions,
|
|
25
|
+
accessToken: challenge.temporaryAuthenticationToken,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
17
28
|
}
|
|
18
29
|
exports.DfnsAuthenticator = DfnsAuthenticator;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./dfnsApiClient"), exports);
|
|
18
18
|
__exportStar(require("./dfnsAuthenticator"), exports);
|
|
19
|
+
__exportStar(require("./dfnsDelegatedApiClient"), exports);
|
|
19
20
|
__exportStar(require("./dfnsError"), exports);
|
package/package.json
CHANGED
package/signer.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type CredentialKind = 'Key' | 'Fido2' | 'Password' | 'Totp' | 'RecoveryKey';
|
|
1
2
|
export type CredentialTransport = 'usb' | 'nfc' | 'ble' | 'internal';
|
|
2
3
|
export type AllowCredential = {
|
|
3
4
|
type: 'public-key';
|
|
@@ -5,43 +6,37 @@ export type AllowCredential = {
|
|
|
5
6
|
transports: CredentialTransport[];
|
|
6
7
|
};
|
|
7
8
|
export type KeyAssertion = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
kind: 'Key';
|
|
10
|
+
credentialAssertion: {
|
|
11
|
+
credId: string;
|
|
12
|
+
clientData: string;
|
|
13
|
+
signature: string;
|
|
14
|
+
};
|
|
11
15
|
};
|
|
12
16
|
export type Fido2Assertion = {
|
|
13
|
-
credId: string;
|
|
14
|
-
clientData: string;
|
|
15
|
-
authenticatorData: string;
|
|
16
|
-
signature: string;
|
|
17
|
-
userHandle?: string;
|
|
18
|
-
};
|
|
19
|
-
export type FirstFactorAssertion = {
|
|
20
|
-
kind: 'Key';
|
|
21
|
-
credentialAssertion: KeyAssertion;
|
|
22
|
-
} | {
|
|
23
17
|
kind: 'Fido2';
|
|
24
|
-
credentialAssertion:
|
|
25
|
-
|
|
18
|
+
credentialAssertion: {
|
|
19
|
+
credId: string;
|
|
20
|
+
clientData: string;
|
|
21
|
+
authenticatorData: string;
|
|
22
|
+
signature: string;
|
|
23
|
+
userHandle?: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type PasswordAssertion = {
|
|
26
27
|
kind: 'Password';
|
|
27
28
|
password: string;
|
|
28
29
|
};
|
|
29
|
-
export type
|
|
30
|
-
kind: 'Key';
|
|
31
|
-
credentialAssertion: KeyAssertion;
|
|
32
|
-
} | {
|
|
33
|
-
kind: 'Fido2';
|
|
34
|
-
credentialAssertion: Fido2Assertion;
|
|
35
|
-
} | {
|
|
30
|
+
export type TotpAssertion = {
|
|
36
31
|
kind: 'Totp';
|
|
37
32
|
otpCode: string;
|
|
38
33
|
};
|
|
39
|
-
export
|
|
34
|
+
export type FirstFactorAssertion = KeyAssertion | Fido2Assertion | PasswordAssertion;
|
|
35
|
+
export type SecondFactorAssertion = KeyAssertion | Fido2Assertion | TotpAssertion;
|
|
36
|
+
export type CredentialAssertion = KeyAssertion | Fido2Assertion | PasswordAssertion | TotpAssertion;
|
|
37
|
+
export interface CredentialSigner<T extends CredentialAssertion = FirstFactorAssertion> {
|
|
40
38
|
sign(challenge: string, allowCredentials: {
|
|
41
39
|
key: AllowCredential[];
|
|
42
40
|
webauthn: AllowCredential[];
|
|
43
|
-
}): Promise<
|
|
44
|
-
firstFactor: FirstFactorAssertion;
|
|
45
|
-
secondFactor?: SecondFactorAssertion;
|
|
46
|
-
}>;
|
|
41
|
+
}): Promise<T>;
|
|
47
42
|
}
|
package/store.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { AllowCredential, CredentialKind } from './signer';
|
|
2
|
+
export type AuthenticatorAttachment = 'platform' | 'cross-platform';
|
|
3
|
+
export type ResidentKeyRequirement = 'required' | 'preferred' | 'discouraged';
|
|
4
|
+
export type UserVerificationRequirement = 'required' | 'preferred' | 'discouraged';
|
|
5
|
+
export type AttestationConveyancePreference = 'none' | 'indirect' | 'direct' | 'enterprise';
|
|
6
|
+
export type UserRegistrationChallenge = {
|
|
7
|
+
temporaryAuthenticationToken: string;
|
|
8
|
+
rp: {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
};
|
|
12
|
+
user: {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
displayName: string;
|
|
16
|
+
};
|
|
17
|
+
supportedCredentialKinds: {
|
|
18
|
+
firstFactor: CredentialKind[];
|
|
19
|
+
secondFactor: CredentialKind[];
|
|
20
|
+
};
|
|
21
|
+
otpUrl: string;
|
|
22
|
+
challenge: string;
|
|
23
|
+
authenticatorSelection: {
|
|
24
|
+
authenticatorAttachment?: AuthenticatorAttachment;
|
|
25
|
+
requireResidentKey: boolean;
|
|
26
|
+
residentKey: ResidentKeyRequirement;
|
|
27
|
+
userVerification: UserVerificationRequirement;
|
|
28
|
+
};
|
|
29
|
+
attestation: AttestationConveyancePreference;
|
|
30
|
+
pubKeyCredParams: {
|
|
31
|
+
type: 'public-key';
|
|
32
|
+
alg: number;
|
|
33
|
+
}[];
|
|
34
|
+
excludeCredentials: AllowCredential[];
|
|
35
|
+
};
|
|
36
|
+
export type KeyAttestation = {
|
|
37
|
+
credentialKind: 'Key';
|
|
38
|
+
credentialInfo: {
|
|
39
|
+
credId: string;
|
|
40
|
+
clientData: string;
|
|
41
|
+
attestationData: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export type Fido2Attestation = {
|
|
45
|
+
credentialKind: 'Fido2';
|
|
46
|
+
credentialInfo: {
|
|
47
|
+
credId: string;
|
|
48
|
+
clientData: string;
|
|
49
|
+
attestationData: string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export type PasswordAttestation = {
|
|
53
|
+
credentialKind: 'Password';
|
|
54
|
+
credentialInfo: {
|
|
55
|
+
password: string;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export type TotpAttestation = {
|
|
59
|
+
credentialKind: 'Totp';
|
|
60
|
+
credentialInfo: {
|
|
61
|
+
otpCode: string;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export type FirstFactorAttestation = KeyAttestation | Fido2Attestation | PasswordAttestation;
|
|
65
|
+
export type SecondFactorAttestation = KeyAttestation | Fido2Attestation | TotpAttestation;
|
|
66
|
+
export type RecoveryKeyAttestation = {
|
|
67
|
+
credentialKind: 'RecoveryKey';
|
|
68
|
+
credentialInfo: {
|
|
69
|
+
credId: string;
|
|
70
|
+
clientData: string;
|
|
71
|
+
attestationData: string;
|
|
72
|
+
};
|
|
73
|
+
encryptedPrivateKey?: string;
|
|
74
|
+
};
|
|
75
|
+
export type RecoveryFactorAttestation = RecoveryKeyAttestation;
|
|
76
|
+
export type CredentialAttestation = KeyAttestation | Fido2Attestation | PasswordAttestation | TotpAttestation | RecoveryKeyAttestation;
|
|
77
|
+
export interface CredentialStore<T extends CredentialAttestation = FirstFactorAttestation> {
|
|
78
|
+
create(challenge: UserRegistrationChallenge): Promise<T>;
|
|
79
|
+
}
|
package/store.js
ADDED
package/utils/fetch.js
CHANGED
|
@@ -33,7 +33,7 @@ const errorHandler = (fetch) => {
|
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
35
|
const body = await response.json();
|
|
36
|
-
throw new dfnsError_1.DfnsError(response.status, body.message, body);
|
|
36
|
+
throw new dfnsError_1.DfnsError(response.status, body.error.message, body.error);
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
};
|
|
@@ -72,10 +72,10 @@ const userAction = (fetch) => {
|
|
|
72
72
|
userActionServerKind: 'Api',
|
|
73
73
|
}, options.apiOptions);
|
|
74
74
|
const { signer } = options.apiOptions;
|
|
75
|
-
const
|
|
75
|
+
const assertion = await signer.sign(challenge, allowCredentials);
|
|
76
76
|
const { userAction } = await baseAuthApi_1.BaseAuthApi.signUserActionChallenge({
|
|
77
77
|
challengeIdentifier,
|
|
78
|
-
|
|
78
|
+
firstFactor: assertion,
|
|
79
79
|
}, options.apiOptions);
|
|
80
80
|
options.headers = {
|
|
81
81
|
'x-dfns-useraction': userAction,
|