@loginid/websdk3 1.1.1 → 1.3.0

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/dist/index.d.cts CHANGED
@@ -49,6 +49,40 @@ declare abstract class BaseHttpRequest {
49
49
  abstract request<T>(options: ApiRequestOptions): CancelablePromise<T>;
50
50
  }
51
51
 
52
+ type AuthCode = {
53
+ /**
54
+ * Generated code
55
+ */
56
+ code: string;
57
+ /**
58
+ * Expiration time of the code
59
+ */
60
+ expiresAt: string;
61
+ };
62
+
63
+ type UserLogin = {
64
+ /**
65
+ * Username
66
+ */
67
+ username: string;
68
+ /**
69
+ * Username type
70
+ */
71
+ usernameType: 'email' | 'phone';
72
+ };
73
+
74
+ type AuthCodeRequestSMSRequestBody = {
75
+ user: UserLogin;
76
+ };
77
+
78
+ type AuthCodeVerifyRequestBody = {
79
+ /**
80
+ * Authentication code
81
+ */
82
+ authCode: string;
83
+ user: UserLogin;
84
+ };
85
+
52
86
  type AuthenticatorAssertionResponse = {
53
87
  /**
54
88
  * This attribute contains the authenticator data returned by the authenticator.
@@ -137,6 +171,10 @@ type PublicKeyCredentialRequestOptions = {
137
171
 
138
172
  type AuthInit = {
139
173
  assertionOptions: PublicKeyCredentialRequestOptions;
174
+ /**
175
+ * List of fallback methods (in priority order) available to this client.
176
+ */
177
+ fallbackOptions?: Array<'otp:client' | 'otp:email' | 'otp:sms'>;
140
178
  /**
141
179
  * An opaque object containing session data.
142
180
  */
@@ -202,28 +240,25 @@ type DeviceInfo = {
202
240
  screenWidth?: number;
203
241
  };
204
242
 
205
- type User = {
206
- /**
207
- * Display Name
208
- */
209
- displayName?: string;
243
+ type AuthInitRequestBody = {
244
+ app: Application;
245
+ deviceInfo: DeviceInfo;
246
+ user?: UserLogin;
247
+ };
248
+
249
+ type CodeResult = {
210
250
  /**
211
- * Username
251
+ * Generated code
212
252
  */
213
- username: string;
253
+ code: string;
214
254
  /**
215
- * Username type
255
+ * Expiration time of the code
216
256
  */
217
- usernameType: 'email' | 'phone';
218
- };
219
-
220
- type AuthInitRequestBody = {
221
- app: Application;
222
- deviceInfo: DeviceInfo;
223
- user?: User;
257
+ expiresAt: string;
224
258
  };
225
259
 
226
260
  type JWT = {
261
+ code?: CodeResult;
227
262
  /**
228
263
  * JWT access token
229
264
  */
@@ -253,6 +288,95 @@ declare class AuthService {
253
288
  */
254
289
  userAgent?: string;
255
290
  }): CancelablePromise<AuthInit>;
291
+ /**
292
+ * Request OTP code by an authenticated user
293
+ * An authenticated user can request an authentication code directly using this
294
+ * method. The code can be used for authentication from another device.
295
+ * @returns AuthCode OK response.
296
+ * @throws ApiError
297
+ */
298
+ authAuthCodeRequest({ authorization, }: {
299
+ /**
300
+ * JWT Authorization header
301
+ */
302
+ authorization?: string;
303
+ }): CancelablePromise<AuthCode>;
304
+ /**
305
+ * Request OTP code to be sent via email.
306
+ * Send authentication code to the provided email. The SMS will only be sent
307
+ * if the email address is known to the application, however, this method will
308
+ * return success regardless.
309
+ * @returns void
310
+ * @throws ApiError
311
+ */
312
+ authAuthCodeRequestEmail({ requestBody, }: {
313
+ requestBody: AuthCodeRequestSMSRequestBody;
314
+ }): CancelablePromise<void>;
315
+ /**
316
+ * Request OTP code to be sent via SMS.
317
+ * Send authentication code to the provided phone number. The SMS will only be
318
+ * sent if the phone is registered with the application, however, it will return
319
+ * success regardless.
320
+ * @returns void
321
+ * @throws ApiError
322
+ */
323
+ authAuthCodeRequestSms({ requestBody, }: {
324
+ requestBody: AuthCodeRequestSMSRequestBody;
325
+ }): CancelablePromise<void>;
326
+ /**
327
+ * Verify authentication code and return JWT access token with appropriate scopes
328
+ * @returns JWT OK response.
329
+ * @throws ApiError
330
+ */
331
+ authAuthCodeVerify({ requestBody, }: {
332
+ requestBody: AuthCodeVerifyRequestBody;
333
+ }): CancelablePromise<JWT>;
334
+ }
335
+
336
+ type GrantCreateRequestBody = {
337
+ /**
338
+ * List of requested grants
339
+ */
340
+ grants: Array<'passkey:read' | 'passkey:write' | 'profile:read' | 'profile:write' | 'self:write'>;
341
+ /**
342
+ * User identifier
343
+ */
344
+ username?: string;
345
+ };
346
+
347
+ type GrantCreateResponseBody = {
348
+ /**
349
+ * Base64 encoded authorization token
350
+ */
351
+ token: string;
352
+ };
353
+
354
+ type TokenVerifyRequestBody = {
355
+ /**
356
+ * JWT access token
357
+ */
358
+ jwtAccess: string;
359
+ };
360
+
361
+ declare class MgmtService {
362
+ readonly httpRequest: BaseHttpRequest;
363
+ constructor(httpRequest: BaseHttpRequest);
364
+ /**
365
+ * Create an authorization token with requested scopes
366
+ * @returns GrantCreateResponseBody OK response.
367
+ * @throws ApiError
368
+ */
369
+ mgmtGrantCreate({ requestBody, }: {
370
+ requestBody: GrantCreateRequestBody;
371
+ }): CancelablePromise<GrantCreateResponseBody>;
372
+ /**
373
+ * Validate JWT Access Token
374
+ * @returns void
375
+ * @throws ApiError
376
+ */
377
+ mgmtTokenVerify({ requestBody, }: {
378
+ requestBody: TokenVerifyRequestBody;
379
+ }): CancelablePromise<void>;
256
380
  }
257
381
 
258
382
  type Passkey = {
@@ -291,8 +415,11 @@ declare class PasskeysService {
291
415
  * @returns PasskeyCollection OK response.
292
416
  * @throws ApiError
293
417
  */
294
- passkeysPasskeysList({ authorization }: {
295
- authorization: string;
418
+ passkeysPasskeysList({ authorization, }: {
419
+ /**
420
+ * JWT Authorization header
421
+ */
422
+ authorization?: string;
296
423
  }): CancelablePromise<PasskeyCollection>;
297
424
  /**
298
425
  * Delete passkey
@@ -304,20 +431,134 @@ declare class PasskeysService {
304
431
  * Internal passkey identifier
305
432
  */
306
433
  id: string;
307
- authorization: string;
434
+ /**
435
+ * JWT Authorization header
436
+ */
437
+ authorization?: string;
308
438
  }): CancelablePromise<void>;
309
439
  /**
310
440
  * Rename passkey
311
441
  * @returns void
312
442
  * @throws ApiError
313
443
  */
314
- passkeysPasskeyRename({ id, requestBody, authorization }: {
444
+ passkeysPasskeyRename({ id, requestBody, authorization, }: {
315
445
  /**
316
446
  * Internal passkey identifier
317
447
  */
318
448
  id: string;
319
449
  requestBody: PasskeyRenameRequestBody;
320
- authorization: string;
450
+ /**
451
+ * JWT Authorization header
452
+ */
453
+ authorization?: string;
454
+ }): CancelablePromise<void>;
455
+ }
456
+
457
+ type ProfileEmailUpdateRequestBody = {
458
+ /**
459
+ * Email address
460
+ */
461
+ email: string;
462
+ /**
463
+ * Whether to update the email address immediately or send an authorization code
464
+ * to verify.
465
+ */
466
+ requestVerification?: boolean;
467
+ };
468
+
469
+ type ProfilePhoneUpdateRequestBody = {
470
+ /**
471
+ * Whether the user consents to receiving SMS messages on this number. The phone
472
+ * will not be used for sending messages if no consent is provided.
473
+ */
474
+ messagingConsent?: boolean;
475
+ /**
476
+ * Phone number
477
+ */
478
+ phoneNumber: string;
479
+ /**
480
+ * Whether to update the phone number immediately or send an authorization code
481
+ * to verify. This method will fail if verification is requested but no consent
482
+ * is provided.
483
+ */
484
+ requestVerification?: boolean;
485
+ };
486
+
487
+ type ProfilePhoneVerifyRequestBody = {
488
+ /**
489
+ * Verification code
490
+ */
491
+ authCode: string;
492
+ /**
493
+ * Username associated with the code
494
+ */
495
+ username: string;
496
+ };
497
+
498
+ declare class ProfileService {
499
+ readonly httpRequest: BaseHttpRequest;
500
+ constructor(httpRequest: BaseHttpRequest);
501
+ /**
502
+ * Delete a user profile and all associated passkey
503
+ * @returns void
504
+ * @throws ApiError
505
+ */
506
+ profileProfileDelete({ id, }: {
507
+ /**
508
+ * Internal user identifier
509
+ */
510
+ id: string;
511
+ }): CancelablePromise<void>;
512
+ /**
513
+ * Update profile email address
514
+ * @returns void
515
+ * @throws ApiError
516
+ */
517
+ profileProfileEmailUpdate({ id, requestBody, }: {
518
+ /**
519
+ * Internal user identifier
520
+ */
521
+ id: string;
522
+ requestBody: ProfileEmailUpdateRequestBody;
523
+ }): CancelablePromise<void>;
524
+ /**
525
+ * Delete phone from the profile
526
+ * @returns void
527
+ * @throws ApiError
528
+ */
529
+ profileProfilePhoneDelete({ id, }: {
530
+ /**
531
+ * Internal user identifier
532
+ */
533
+ id: string;
534
+ }): CancelablePromise<void>;
535
+ /**
536
+ * Update the profile phone number
537
+ * @returns void
538
+ * @throws ApiError
539
+ */
540
+ profileProfilePhoneUpdate({ id, requestBody, }: {
541
+ /**
542
+ * Internal user identifier
543
+ */
544
+ id: string;
545
+ requestBody: ProfilePhoneUpdateRequestBody;
546
+ }): CancelablePromise<void>;
547
+ /**
548
+ * Verify phone number with received authorization code
549
+ * @returns void
550
+ * @throws ApiError
551
+ */
552
+ profileProfileEmailVerify({ requestBody, }: {
553
+ requestBody: ProfilePhoneVerifyRequestBody;
554
+ }): CancelablePromise<void>;
555
+ /**
556
+ * Verify phone number with received authorization code
557
+ * @returns void
558
+ * @throws ApiError
559
+ */
560
+ profileProfilePhoneVerify({ requestBody, }: {
561
+ requestBody: ProfilePhoneVerifyRequestBody;
321
562
  }): CancelablePromise<void>;
322
563
  }
323
564
 
@@ -467,18 +708,33 @@ type RegInit = {
467
708
  session: string;
468
709
  };
469
710
 
711
+ type User = {
712
+ /**
713
+ * Display Name
714
+ */
715
+ displayName?: string;
716
+ /**
717
+ * Username
718
+ */
719
+ username: string;
720
+ /**
721
+ * Username type
722
+ */
723
+ usernameType: 'email' | 'phone';
724
+ };
725
+
470
726
  type RegInitRequestBody = {
471
727
  app: Application;
472
728
  deviceInfo: DeviceInfo;
473
729
  /**
474
- * Set of authentication factors:
475
- * - Single factor: Username (i.e. email or phone) + FIDO2 credential;
476
- * - Two factor: Username + password + FIDO2 credential;
477
- * - Passwordless: FIDO2 discoverable credentials;
478
- * - Passwordless + MFA: FIDO2 discoverable credentials + PIN;
730
+ * An opaque object containing user data. It is used in place of "user" attribute
731
+ * for creating passkeys for pre-authorized users ("user" attribute is ignored if
732
+ * session is present). The value of this attribute is generated by this service
733
+ * and require backend integration for obtaining it. This value is time sensitive
734
+ * and has rather short expiry.
479
735
  */
480
- mfa?: Array<'fido2' | 'email' | 'phone' | 'password' | 'pin'>;
481
- user: User;
736
+ session?: string;
737
+ user?: User;
482
738
  };
483
739
 
484
740
  declare class RegService {
@@ -497,35 +753,19 @@ declare class RegService {
497
753
  * @returns RegInit OK response.
498
754
  * @throws ApiError
499
755
  */
500
- regRegInit({ requestBody, userAgent, }: {
756
+ regRegInit({ requestBody, userAgent, authorization, }: {
501
757
  requestBody: RegInitRequestBody;
502
758
  /**
503
759
  * Raw user-agent header as set by a browser
504
760
  */
505
761
  userAgent?: string;
762
+ /**
763
+ * JWT Authorization header
764
+ */
765
+ authorization?: string;
506
766
  }): CancelablePromise<RegInit>;
507
767
  }
508
768
 
509
- type TokenVerifyRequestBody = {
510
- /**
511
- * JWT access token
512
- */
513
- jwtAccess: string;
514
- };
515
-
516
- declare class TokenService {
517
- readonly httpRequest: BaseHttpRequest;
518
- constructor(httpRequest: BaseHttpRequest);
519
- /**
520
- * Validate JWT Access Token
521
- * @returns void
522
- * @throws ApiError
523
- */
524
- tokenTokenVerify({ requestBody, }: {
525
- requestBody: TokenVerifyRequestBody;
526
- }): CancelablePromise<void>;
527
- }
528
-
529
769
  type TxComplete = {
530
770
  authCred?: Passkey;
531
771
  /**
@@ -657,9 +897,10 @@ declare class VersionService {
657
897
  type HttpRequestConstructor = new (config: OpenAPIConfig) => BaseHttpRequest;
658
898
  declare class LoginIDService {
659
899
  readonly auth: AuthService;
900
+ readonly mgmt: MgmtService;
660
901
  readonly passkeys: PasskeysService;
902
+ readonly profile: ProfileService;
661
903
  readonly reg: RegService;
662
- readonly token: TokenService;
663
904
  readonly tx: TxService;
664
905
  readonly version: VersionService;
665
906
  readonly request: BaseHttpRequest;
@@ -685,7 +926,6 @@ declare class ApiError extends Error {
685
926
 
686
927
  type UsernameType = User['usernameType'];
687
928
  type DeviceInfoRequestBody = DeviceInfo;
688
- type MFA = RegInitRequestBody['mfa'];
689
929
  type Transports = CreationResult['transports'];
690
930
  interface LoginIDConfig {
691
931
  baseUrl: string;
@@ -696,14 +936,25 @@ interface PasskeyOptions {
696
936
  displayName?: string;
697
937
  usernameType?: UsernameType;
698
938
  }
939
+ interface PasskeyManagementOptions {
940
+ token?: string;
941
+ }
942
+ interface ListPasskeysOptions extends PasskeyManagementOptions {
943
+ }
944
+ interface RenamePasskeyOptions extends PasskeyManagementOptions {
945
+ }
946
+ interface DeletePasskeyOptions extends PasskeyManagementOptions {
947
+ }
699
948
  interface AuthenticateWithPasskeysOptions extends PasskeyOptions {
700
949
  autoFill?: boolean;
701
950
  abortSignal?: AbortSignal;
702
951
  }
703
952
  interface RegisterWithPasskeyOptions extends PasskeyOptions {
704
- mfa?: MFA;
953
+ session?: string;
705
954
  }
706
- interface ConfirmTransactionOptions extends Partial<Pick<TxInitRequestBody, 'txType'>> {
955
+ interface ConfirmTransactionOptions extends PasskeyOptions {
956
+ txType?: string;
957
+ nonce?: string;
707
958
  }
708
959
  interface PasskeyResult {
709
960
  jwtAccess: string;
@@ -727,13 +978,38 @@ declare class LoginIDBase {
727
978
  * @param {LoginIDConfig} config Configuration object for LoginID API, including the base URL.
728
979
  */
729
980
  constructor(config: LoginIDConfig);
981
+ getToken(options: PasskeyOptions): string;
982
+ /**
983
+ *
984
+ * @returns {string} The name of the cookie
985
+ */
986
+ getJwtCookieName(): string;
987
+ /**
988
+ * Set jwt token to localstorage
989
+ * @param {string} jwt Configuration object for LoginID API, including the base URL.
990
+ */
991
+ setJwtCookie(jwt: string): void;
992
+ /**
993
+ * Retrieves the JWT access token.
994
+ * @returns {string | undefined} The JWT access token.
995
+ */
996
+ getJwtCookie(): string | undefined;
997
+ /**
998
+ * checks if the user is logged in.
999
+ * @returns {boolean}
1000
+ */
1001
+ isLoggedIn(): boolean;
1002
+ /**
1003
+ * deletes the jwt cookie.
1004
+ * @returns {boolean}
1005
+ */
1006
+ signout(): void;
730
1007
  }
731
1008
 
732
1009
  /**
733
1010
  * Extends LoginIDBase to support creation, registration, and authentication of passkeys.
734
1011
  */
735
1012
  declare class Passkeys extends LoginIDBase {
736
- private jwtAccess;
737
1013
  /**
738
1014
  * Initializes a new Passkeys instance with the provided configuration.
739
1015
  * @param {LoginIDConfig} config Configuration object for LoginID.
@@ -766,6 +1042,36 @@ declare class Passkeys extends LoginIDBase {
766
1042
  * @returns {Promise<any>} Result of the authentication operation.
767
1043
  */
768
1044
  authenticateWithPasskey(username?: string, options?: AuthenticateWithPasskeysOptions): Promise<PasskeyResult>;
1045
+ /**
1046
+ * Generates a code with passkey.
1047
+ * @param {string} username Username to authenticate.
1048
+ * @param {AuthenticateWithPasskeysOptions} options Additional authentication options.
1049
+ * @returns {Promise<AuthCode>} Code and expiry.
1050
+ */
1051
+ generateCodeWithPasskey(username: string, options?: AuthenticateWithPasskeysOptions): Promise<AuthCode>;
1052
+ /**
1053
+ * Authenticate with a code.
1054
+ * @param {string} username Username to authenticate.
1055
+ * @param {string} code code to authenticate.
1056
+ * @param {AuthenticateWithPasskeysOptions} options Additional authentication options.
1057
+ * @returns {Promise<any>} Result of the authentication operation.
1058
+ */
1059
+ authenticateWithCode(username: string, code: string, options?: AuthenticateWithPasskeysOptions): Promise<JWT>;
1060
+ /**
1061
+ * Add passkey
1062
+ * @param username Username to authenticate.
1063
+ * @param options Additional authentication options.
1064
+ * @returns {Promise<PasskeyResult>} Result of the add passkey operation.
1065
+ */
1066
+ addPasskey(username: string, options?: PasskeyOptions): Promise<PasskeyResult>;
1067
+ /**
1068
+ * Add passkey with code
1069
+ * @param username Username to authenticate.
1070
+ * @param code Code to authenticate.
1071
+ * @param options Additional authentication options.
1072
+ * @returns @returns {Promise<PasskeyResult>} Result of the add passkey with code operation.
1073
+ */
1074
+ addPasskeyWithCode(username: string, code: string, options?: PasskeyOptions): Promise<PasskeyResult>;
769
1075
  /**
770
1076
  * Confirms a transaction using a passkey.
771
1077
  *
@@ -782,12 +1088,7 @@ declare class Passkeys extends LoginIDBase {
782
1088
  * @returns {Promise<any>} A promise that resolves with the result of the transaction confirmation operation.
783
1089
  * The result includes details about the transaction's details and includes a new JWT access token.
784
1090
  */
785
- confirmTransaction(username: string, txPayload: string, nonce: string, options?: ConfirmTransactionOptions): Promise<TxComplete>;
786
- /**
787
- * Retrieves the JWT access token.
788
- * @returns {string} The JWT access token.
789
- */
790
- getJWTAccess(): string;
1091
+ confirmTransaction(username: string, txPayload: string, options?: ConfirmTransactionOptions): Promise<TxComplete>;
791
1092
  }
792
1093
 
793
1094
  /**
@@ -804,7 +1105,7 @@ declare class PasskeyManager extends LoginIDBase {
804
1105
  * @param {string} authToken Authorization token to authenticate the request.
805
1106
  * @returns {Promise<PasskeysPasskeyResponseCollection>} A collection of passkeys.
806
1107
  */
807
- listPasskeys(authToken: string): Promise<PasskeyCollection>;
1108
+ listPasskeys(options?: ListPasskeysOptions): Promise<PasskeyCollection>;
808
1109
  /**
809
1110
  * Renames a specified passkey.
810
1111
  * @param {string} authToken Authorization token to authenticate the request.
@@ -812,14 +1113,14 @@ declare class PasskeyManager extends LoginIDBase {
812
1113
  * @param {string} name The new name for the passkey.
813
1114
  * @returns {Promise<null>} A promise that resolves to null upon successful completion.
814
1115
  */
815
- renamePasskey(authToken: string, id: string, name: string): Promise<null>;
1116
+ renamePasskey(id: string, name: string, options?: RenamePasskeyOptions): Promise<null>;
816
1117
  /**
817
1118
  * Deletes a specified passkey.
818
1119
  * @param {string} authToken Authorization token to authenticate the request.
819
1120
  * @param {string} id The ID of the passkey to delete.
820
1121
  * @returns {Promise<null>} A promise that resolves to null upon successful deletion.
821
1122
  */
822
- deletePasskey(authToken: string, id: string): Promise<null>;
1123
+ deletePasskey(id: string, options?: DeletePasskeyOptions): Promise<null>;
823
1124
  }
824
1125
 
825
1126
  interface LoginIDWebSDK extends Passkeys, PasskeyManager {
@@ -878,4 +1179,4 @@ interface DoesDeviceSupportPasskeysResponse {
878
1179
  */
879
1180
  declare function doesDeviceSupportPasskeys(): Promise<DoesDeviceSupportPasskeysResponse>;
880
1181
 
881
- export { ApiError, type AuthenticateWithPasskeysOptions, type ConfirmTransactionOptions, type DeviceInfoRequestBody, type DoesDeviceSupportPasskeysResponse, type LoginIDConfig, LoginIDWebSDK, type MFA, PasskeyError, type PasskeyOptions, type PasskeyResult, type RegisterWithPasskeyOptions, type Transports, type UsernameType, createPasskeyCredential, LoginIDWebSDK as default, doesDeviceSupportPasskeys, getPasskeyCredential, isConditionalUIAvailable, isPlatformAuthenticatorAvailable };
1182
+ export { ApiError, type AuthenticateWithPasskeysOptions, type ConfirmTransactionOptions, type DeletePasskeyOptions, type DeviceInfoRequestBody, type DoesDeviceSupportPasskeysResponse, type ListPasskeysOptions, type LoginIDConfig, LoginIDWebSDK, PasskeyError, type PasskeyManagementOptions, type PasskeyOptions, type PasskeyResult, type RegisterWithPasskeyOptions, type RenamePasskeyOptions, type Transports, type UsernameType, createPasskeyCredential, LoginIDWebSDK as default, doesDeviceSupportPasskeys, getPasskeyCredential, isConditionalUIAvailable, isPlatformAuthenticatorAvailable };