@passkeyme/auth 2.0.1 → 2.0.3
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.esm.js +177 -175
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +177 -175
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +177 -175
- package/dist/index.umd.js.map +1 -1
- package/dist/src/api-client.d.ts +1 -1
- package/dist/src/api-client.d.ts.map +1 -1
- package/dist/src/passkeyme-auth.d.ts +1 -1
- package/dist/src/passkeyme-auth.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -263,10 +263,11 @@ class PasskeymeApiClient {
|
|
|
263
263
|
this.appId = appId;
|
|
264
264
|
this.baseUrl = baseUrl.replace(/\/$/, ""); // Remove trailing slash
|
|
265
265
|
this.debug = debug;
|
|
266
|
+
this.log("API Client initialized with baseUrl:", this.baseUrl);
|
|
266
267
|
}
|
|
267
268
|
log(...args) {
|
|
268
269
|
if (this.debug) {
|
|
269
|
-
logger.debug("[
|
|
270
|
+
logger.debug("[PasskeymeApiClient]", ...args);
|
|
270
271
|
}
|
|
271
272
|
}
|
|
272
273
|
async request(endpoint, options = {}) {
|
|
@@ -449,6 +450,179 @@ class PasskeymeApiClient {
|
|
|
449
450
|
}
|
|
450
451
|
}
|
|
451
452
|
|
|
453
|
+
/**
|
|
454
|
+
* Platform SDK Interface for Passkeyme
|
|
455
|
+
*
|
|
456
|
+
* This interface abstracts platform-specific passkey operations,
|
|
457
|
+
* allowing the core SDK to work across web, React Native, and other platforms.
|
|
458
|
+
*/
|
|
459
|
+
/**
|
|
460
|
+
* No-op implementation for platforms without passkey support
|
|
461
|
+
*/
|
|
462
|
+
class NoOpPasskeySDK {
|
|
463
|
+
async register(_options) {
|
|
464
|
+
return {
|
|
465
|
+
success: false,
|
|
466
|
+
error: "Passkeys not supported on this platform",
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
async authenticate(_options) {
|
|
470
|
+
return {
|
|
471
|
+
success: false,
|
|
472
|
+
error: "Passkeys not supported on this platform",
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
isSupported() {
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
canUseDiscoverableCredentials() {
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
supportsBiometrics() {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Web Platform SDK Implementation
|
|
488
|
+
*
|
|
489
|
+
* Wraps the passkeyme-web-sdk to implement the PasskeySDK interface
|
|
490
|
+
*/
|
|
491
|
+
/**
|
|
492
|
+
* Web implementation of PasskeySDK using passkeyme-web-sdk
|
|
493
|
+
*
|
|
494
|
+
* This implementation should be used for web browsers that support WebAuthn.
|
|
495
|
+
* The actual passkeyme-web-sdk dependency should be provided by the consuming package.
|
|
496
|
+
*/
|
|
497
|
+
class WebPasskeySDK {
|
|
498
|
+
constructor(webSDK) {
|
|
499
|
+
this.webSDK = webSDK;
|
|
500
|
+
}
|
|
501
|
+
async register(options) {
|
|
502
|
+
try {
|
|
503
|
+
if (!this.webSDK) {
|
|
504
|
+
return {
|
|
505
|
+
success: false,
|
|
506
|
+
error: "Web SDK not available",
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
// Extract the challenge from the options
|
|
510
|
+
// The options object contains: { username, displayName, challenge, ...otherChallengeData }
|
|
511
|
+
const { username, displayName, challenge, ...otherData } = options;
|
|
512
|
+
// Pass the challenge data directly to the web SDK
|
|
513
|
+
const challengeData = challenge || otherData;
|
|
514
|
+
// Call the web SDK register method with the challenge
|
|
515
|
+
const result = await this.webSDK.passkeyRegister(challengeData);
|
|
516
|
+
return {
|
|
517
|
+
success: true,
|
|
518
|
+
credentialId: result.credentialId || result.id,
|
|
519
|
+
data: result,
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
catch (error) {
|
|
523
|
+
return {
|
|
524
|
+
success: false,
|
|
525
|
+
error: error.message || "Registration failed",
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
async authenticate(options) {
|
|
530
|
+
try {
|
|
531
|
+
if (!this.webSDK) {
|
|
532
|
+
return {
|
|
533
|
+
success: false,
|
|
534
|
+
error: "Web SDK not available",
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
// Extract the challenge from the options
|
|
538
|
+
// The options object contains: { username, challenge, ...otherChallengeData }
|
|
539
|
+
const { username, challenge, ...otherData } = options;
|
|
540
|
+
// Pass the challenge data directly to the web SDK
|
|
541
|
+
const challengeData = challenge || otherData;
|
|
542
|
+
// Call the web SDK authenticate method with the challenge
|
|
543
|
+
const result = await this.webSDK.passkeyAuthenticate(challengeData);
|
|
544
|
+
return {
|
|
545
|
+
success: true,
|
|
546
|
+
assertion: result,
|
|
547
|
+
data: result,
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
catch (error) {
|
|
551
|
+
return {
|
|
552
|
+
success: false,
|
|
553
|
+
error: error.message || "Authentication failed",
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
isSupported() {
|
|
558
|
+
// Check if we're in a browser environment with WebAuthn support
|
|
559
|
+
return (typeof window !== "undefined" &&
|
|
560
|
+
typeof navigator !== "undefined" &&
|
|
561
|
+
"credentials" in navigator &&
|
|
562
|
+
typeof navigator.credentials.create === "function");
|
|
563
|
+
}
|
|
564
|
+
async getAvailableAuthenticators() {
|
|
565
|
+
// This is a basic implementation - the web SDK might provide more detailed info
|
|
566
|
+
const authenticators = [];
|
|
567
|
+
if (this.isSupported()) {
|
|
568
|
+
// Basic platform authenticator info
|
|
569
|
+
authenticators.push({
|
|
570
|
+
type: "platform",
|
|
571
|
+
supportsBiometrics: true, // Assume platform authenticators support biometrics
|
|
572
|
+
supportsUserVerification: true,
|
|
573
|
+
});
|
|
574
|
+
// Basic cross-platform authenticator info
|
|
575
|
+
authenticators.push({
|
|
576
|
+
type: "cross-platform",
|
|
577
|
+
supportsBiometrics: false,
|
|
578
|
+
supportsUserVerification: true,
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
return authenticators;
|
|
582
|
+
}
|
|
583
|
+
canUseDiscoverableCredentials() {
|
|
584
|
+
// Check if the platform supports discoverable credentials (resident keys)
|
|
585
|
+
return this.isSupported();
|
|
586
|
+
}
|
|
587
|
+
supportsBiometrics() {
|
|
588
|
+
// On web, this depends on the platform authenticator availability
|
|
589
|
+
// This is a simplified check - a more sophisticated implementation
|
|
590
|
+
// would actually test for platform authenticator support
|
|
591
|
+
return (this.isSupported() &&
|
|
592
|
+
typeof window !== "undefined" &&
|
|
593
|
+
/Mac|Win|Linux/.test(navigator.platform));
|
|
594
|
+
}
|
|
595
|
+
async initialize(config) {
|
|
596
|
+
// Initialize the web SDK if it has an init method
|
|
597
|
+
if (this.webSDK && typeof this.webSDK.init === "function") {
|
|
598
|
+
await this.webSDK.init(config);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
async cleanup() {
|
|
602
|
+
// Cleanup if the web SDK has a cleanup method
|
|
603
|
+
if (this.webSDK && typeof this.webSDK.cleanup === "function") {
|
|
604
|
+
await this.webSDK.cleanup();
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Platform SDK exports
|
|
611
|
+
*/
|
|
612
|
+
// Conditionally export React Native SDK only in React Native environments
|
|
613
|
+
let ReactNativePasskeySDK = null;
|
|
614
|
+
try {
|
|
615
|
+
// Only try to load React Native SDK if we're actually in a React Native environment
|
|
616
|
+
if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
617
|
+
const { ReactNativePasskeySDK: RNPasskeySDK, } = require("./ReactNativePasskeySDK");
|
|
618
|
+
ReactNativePasskeySDK = RNPasskeySDK;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
catch (error) {
|
|
622
|
+
// React Native SDK not available or not in React Native environment
|
|
623
|
+
ReactNativePasskeySDK = null;
|
|
624
|
+
}
|
|
625
|
+
|
|
452
626
|
/**
|
|
453
627
|
* Browser storage implementation using localStorage or sessionStorage
|
|
454
628
|
*/
|
|
@@ -625,179 +799,6 @@ TokenStorage.REFRESH_TOKEN_KEY = "passkeyme_refresh_token";
|
|
|
625
799
|
TokenStorage.EXPIRES_AT_KEY = "passkeyme_expires_at";
|
|
626
800
|
TokenStorage.TOKEN_TYPE_KEY = "passkeyme_token_type";
|
|
627
801
|
|
|
628
|
-
/**
|
|
629
|
-
* Platform SDK Interface for Passkeyme
|
|
630
|
-
*
|
|
631
|
-
* This interface abstracts platform-specific passkey operations,
|
|
632
|
-
* allowing the core SDK to work across web, React Native, and other platforms.
|
|
633
|
-
*/
|
|
634
|
-
/**
|
|
635
|
-
* No-op implementation for platforms without passkey support
|
|
636
|
-
*/
|
|
637
|
-
class NoOpPasskeySDK {
|
|
638
|
-
async register(_options) {
|
|
639
|
-
return {
|
|
640
|
-
success: false,
|
|
641
|
-
error: "Passkeys not supported on this platform",
|
|
642
|
-
};
|
|
643
|
-
}
|
|
644
|
-
async authenticate(_options) {
|
|
645
|
-
return {
|
|
646
|
-
success: false,
|
|
647
|
-
error: "Passkeys not supported on this platform",
|
|
648
|
-
};
|
|
649
|
-
}
|
|
650
|
-
isSupported() {
|
|
651
|
-
return false;
|
|
652
|
-
}
|
|
653
|
-
canUseDiscoverableCredentials() {
|
|
654
|
-
return false;
|
|
655
|
-
}
|
|
656
|
-
supportsBiometrics() {
|
|
657
|
-
return false;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
/**
|
|
662
|
-
* Web Platform SDK Implementation
|
|
663
|
-
*
|
|
664
|
-
* Wraps the passkeyme-web-sdk to implement the PasskeySDK interface
|
|
665
|
-
*/
|
|
666
|
-
/**
|
|
667
|
-
* Web implementation of PasskeySDK using passkeyme-web-sdk
|
|
668
|
-
*
|
|
669
|
-
* This implementation should be used for web browsers that support WebAuthn.
|
|
670
|
-
* The actual passkeyme-web-sdk dependency should be provided by the consuming package.
|
|
671
|
-
*/
|
|
672
|
-
class WebPasskeySDK {
|
|
673
|
-
constructor(webSDK) {
|
|
674
|
-
this.webSDK = webSDK;
|
|
675
|
-
}
|
|
676
|
-
async register(options) {
|
|
677
|
-
try {
|
|
678
|
-
if (!this.webSDK) {
|
|
679
|
-
return {
|
|
680
|
-
success: false,
|
|
681
|
-
error: "Web SDK not available",
|
|
682
|
-
};
|
|
683
|
-
}
|
|
684
|
-
// Extract the challenge from the options
|
|
685
|
-
// The options object contains: { username, displayName, challenge, ...otherChallengeData }
|
|
686
|
-
const { username, displayName, challenge, ...otherData } = options;
|
|
687
|
-
// Pass the challenge data directly to the web SDK
|
|
688
|
-
const challengeData = challenge || otherData;
|
|
689
|
-
// Call the web SDK register method with the challenge
|
|
690
|
-
const result = await this.webSDK.passkeyRegister(challengeData);
|
|
691
|
-
return {
|
|
692
|
-
success: true,
|
|
693
|
-
credentialId: result.credentialId || result.id,
|
|
694
|
-
data: result,
|
|
695
|
-
};
|
|
696
|
-
}
|
|
697
|
-
catch (error) {
|
|
698
|
-
return {
|
|
699
|
-
success: false,
|
|
700
|
-
error: error.message || "Registration failed",
|
|
701
|
-
};
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
async authenticate(options) {
|
|
705
|
-
try {
|
|
706
|
-
if (!this.webSDK) {
|
|
707
|
-
return {
|
|
708
|
-
success: false,
|
|
709
|
-
error: "Web SDK not available",
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
// Extract the challenge from the options
|
|
713
|
-
// The options object contains: { username, challenge, ...otherChallengeData }
|
|
714
|
-
const { username, challenge, ...otherData } = options;
|
|
715
|
-
// Pass the challenge data directly to the web SDK
|
|
716
|
-
const challengeData = challenge || otherData;
|
|
717
|
-
// Call the web SDK authenticate method with the challenge
|
|
718
|
-
const result = await this.webSDK.passkeyAuthenticate(challengeData);
|
|
719
|
-
return {
|
|
720
|
-
success: true,
|
|
721
|
-
assertion: result,
|
|
722
|
-
data: result,
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
catch (error) {
|
|
726
|
-
return {
|
|
727
|
-
success: false,
|
|
728
|
-
error: error.message || "Authentication failed",
|
|
729
|
-
};
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
isSupported() {
|
|
733
|
-
// Check if we're in a browser environment with WebAuthn support
|
|
734
|
-
return (typeof window !== "undefined" &&
|
|
735
|
-
typeof navigator !== "undefined" &&
|
|
736
|
-
"credentials" in navigator &&
|
|
737
|
-
typeof navigator.credentials.create === "function");
|
|
738
|
-
}
|
|
739
|
-
async getAvailableAuthenticators() {
|
|
740
|
-
// This is a basic implementation - the web SDK might provide more detailed info
|
|
741
|
-
const authenticators = [];
|
|
742
|
-
if (this.isSupported()) {
|
|
743
|
-
// Basic platform authenticator info
|
|
744
|
-
authenticators.push({
|
|
745
|
-
type: "platform",
|
|
746
|
-
supportsBiometrics: true, // Assume platform authenticators support biometrics
|
|
747
|
-
supportsUserVerification: true,
|
|
748
|
-
});
|
|
749
|
-
// Basic cross-platform authenticator info
|
|
750
|
-
authenticators.push({
|
|
751
|
-
type: "cross-platform",
|
|
752
|
-
supportsBiometrics: false,
|
|
753
|
-
supportsUserVerification: true,
|
|
754
|
-
});
|
|
755
|
-
}
|
|
756
|
-
return authenticators;
|
|
757
|
-
}
|
|
758
|
-
canUseDiscoverableCredentials() {
|
|
759
|
-
// Check if the platform supports discoverable credentials (resident keys)
|
|
760
|
-
return this.isSupported();
|
|
761
|
-
}
|
|
762
|
-
supportsBiometrics() {
|
|
763
|
-
// On web, this depends on the platform authenticator availability
|
|
764
|
-
// This is a simplified check - a more sophisticated implementation
|
|
765
|
-
// would actually test for platform authenticator support
|
|
766
|
-
return (this.isSupported() &&
|
|
767
|
-
typeof window !== "undefined" &&
|
|
768
|
-
/Mac|Win|Linux/.test(navigator.platform));
|
|
769
|
-
}
|
|
770
|
-
async initialize(config) {
|
|
771
|
-
// Initialize the web SDK if it has an init method
|
|
772
|
-
if (this.webSDK && typeof this.webSDK.init === "function") {
|
|
773
|
-
await this.webSDK.init(config);
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
async cleanup() {
|
|
777
|
-
// Cleanup if the web SDK has a cleanup method
|
|
778
|
-
if (this.webSDK && typeof this.webSDK.cleanup === "function") {
|
|
779
|
-
await this.webSDK.cleanup();
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
/**
|
|
785
|
-
* Platform SDK exports
|
|
786
|
-
*/
|
|
787
|
-
// Conditionally export React Native SDK only in React Native environments
|
|
788
|
-
let ReactNativePasskeySDK = null;
|
|
789
|
-
try {
|
|
790
|
-
// Only try to load React Native SDK if we're actually in a React Native environment
|
|
791
|
-
if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
792
|
-
const { ReactNativePasskeySDK: RNPasskeySDK, } = require("./ReactNativePasskeySDK");
|
|
793
|
-
ReactNativePasskeySDK = RNPasskeySDK;
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
catch (error) {
|
|
797
|
-
// React Native SDK not available or not in React Native environment
|
|
798
|
-
ReactNativePasskeySDK = null;
|
|
799
|
-
}
|
|
800
|
-
|
|
801
802
|
/**
|
|
802
803
|
* Main Passkeyme Authentication SDK class
|
|
803
804
|
*/
|
|
@@ -818,7 +819,7 @@ class PasskeymeAuth {
|
|
|
818
819
|
? `${window.location.origin}/auth/callback`
|
|
819
820
|
: "http://localhost:3000/auth/callback";
|
|
820
821
|
// Support both baseUrl and apiUrl for flexibility
|
|
821
|
-
const serverUrl = config.
|
|
822
|
+
const serverUrl = config.baseUrl || "https://auth.passkeyme.com";
|
|
822
823
|
this.config = {
|
|
823
824
|
appId: config.appId,
|
|
824
825
|
baseUrl: serverUrl,
|
|
@@ -839,6 +840,7 @@ class PasskeymeAuth {
|
|
|
839
840
|
logger.enableDebug();
|
|
840
841
|
logger.debug("[DEBUG] Logger debug mode enabled, testing logger...");
|
|
841
842
|
logger.debug("[DEBUG] Logger config after enableDebug:", logger.getConfig());
|
|
843
|
+
logger.debug("config.baseUrl:", this.config.baseUrl);
|
|
842
844
|
logger.debug("Logger test message - if you see this, logger is working");
|
|
843
845
|
}
|
|
844
846
|
logger.debug("Initialized with config:", this.config);
|