@asgardeo/browser 0.1.21 → 0.1.22
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/__legacy__/client.d.ts +5 -0
- package/dist/cjs/index.js +157 -1
- package/dist/cjs/index.js.map +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +158 -1
- package/dist/index.js.map +4 -4
- package/dist/utils/handleWebAuthnAuthentication.d.ts +97 -0
- package/package.json +2 -2
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
|
|
3
|
+
*
|
|
4
|
+
* WSO2 LLC. licenses this file to you under the Apache License,
|
|
5
|
+
* Version 2.0 (the "License"); you may not use this file except
|
|
6
|
+
* in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing,
|
|
12
|
+
* software distributed under the License is distributed on an
|
|
13
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
* KIND, either express or implied. See the License for the
|
|
15
|
+
* specific language governing permissions and limitations
|
|
16
|
+
* under the License.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Handles WebAuthn/Passkey authentication flow for browser environments.
|
|
20
|
+
*
|
|
21
|
+
* This function processes a WebAuthn challenge, performs the authentication ceremony,
|
|
22
|
+
* and returns the authentication response that can be sent to the server for verification.
|
|
23
|
+
*
|
|
24
|
+
* The function handles various aspects of WebAuthn authentication including:
|
|
25
|
+
* - Browser compatibility checks for WebAuthn support
|
|
26
|
+
* - HTTPS requirement validation (except for localhost development)
|
|
27
|
+
* - Relying Party ID validation and domain compatibility
|
|
28
|
+
* - Challenge data decoding and credential request options processing
|
|
29
|
+
* - User authentication ceremony via navigator.credentials.get()
|
|
30
|
+
* - Response formatting for server consumption
|
|
31
|
+
*
|
|
32
|
+
* @param challengeData - Base64-encoded challenge data containing WebAuthn request options.
|
|
33
|
+
* This data typically includes the challenge, RP ID, allowed credentials,
|
|
34
|
+
* user verification requirements, and other authentication parameters.
|
|
35
|
+
*
|
|
36
|
+
* @returns Promise that resolves to a JSON string containing the WebAuthn authentication response.
|
|
37
|
+
* The response includes the credential ID, authenticator data, client data JSON,
|
|
38
|
+
* signature, and optional user handle that can be verified by the server.
|
|
39
|
+
*
|
|
40
|
+
* @throws {AsgardeoRuntimeError} When WebAuthn is not supported in the current browser
|
|
41
|
+
* @throws {AsgardeoRuntimeError} When the page is not served over HTTPS (except localhost)
|
|
42
|
+
* @throws {AsgardeoRuntimeError} When the user cancels or times out the authentication
|
|
43
|
+
* @throws {AsgardeoRuntimeError} When there's a domain/RP ID mismatch
|
|
44
|
+
* @throws {AsgardeoRuntimeError} When no valid passkey is found for the account
|
|
45
|
+
* @throws {AsgardeoRuntimeError} When WebAuthn is not supported on the device/browser
|
|
46
|
+
* @throws {AsgardeoRuntimeError} When there's a network error during authentication
|
|
47
|
+
* @throws {AsgardeoRuntimeError} For any other authentication failures
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* try {
|
|
52
|
+
* const challengeData = 'eyJwdWJsaWNLZXlDcmVkZW50aWFsUmVxdWVzdE9wdGlvbnMiOi4uLn0=';
|
|
53
|
+
* const authResponse = await handleWebAuthnAuthentication(challengeData);
|
|
54
|
+
*
|
|
55
|
+
* // Send the response to your server for verification
|
|
56
|
+
* const result = await fetch('/api/verify-webauthn', {
|
|
57
|
+
* method: 'POST',
|
|
58
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
59
|
+
* body: authResponse
|
|
60
|
+
* });
|
|
61
|
+
* } catch (error) {
|
|
62
|
+
* if (error instanceof AsgardeoRuntimeError) {
|
|
63
|
+
* console.error('WebAuthn authentication failed:', error.message);
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // Usage in an authentication flow
|
|
71
|
+
* const authenticateWithPasskey = async (challengeFromServer: string) => {
|
|
72
|
+
* try {
|
|
73
|
+
* const response = await handleWebAuthnAuthentication(challengeFromServer);
|
|
74
|
+
* return JSON.parse(response);
|
|
75
|
+
* } catch (error) {
|
|
76
|
+
* // Handle specific error cases
|
|
77
|
+
* if (error instanceof AsgardeoRuntimeError) {
|
|
78
|
+
* switch (error.code) {
|
|
79
|
+
* case 'browser-webauthn-not-supported':
|
|
80
|
+
* showFallbackAuth();
|
|
81
|
+
* break;
|
|
82
|
+
* case 'browser-webauthn-user-cancelled':
|
|
83
|
+
* showRetryOption();
|
|
84
|
+
* break;
|
|
85
|
+
* default:
|
|
86
|
+
* showGenericError();
|
|
87
|
+
* }
|
|
88
|
+
* }
|
|
89
|
+
* }
|
|
90
|
+
* };
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @see {@link https://webauthn.guide/} - WebAuthn specification guide
|
|
94
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API} - MDN WebAuthn API documentation
|
|
95
|
+
*/
|
|
96
|
+
declare const handleWebAuthnAuthentication: (challengeData: string) => Promise<string>;
|
|
97
|
+
export default handleWebAuthnAuthentication;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asgardeo/browser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
4
4
|
"description": "Browser-specific implementation of Asgardeo JavaScript SDK.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"asgardeo",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"randombytes": "^2.1.0",
|
|
61
61
|
"stream-browserify": "^3.0.0",
|
|
62
62
|
"tslib": "^2.8.1",
|
|
63
|
-
"@asgardeo/javascript": "^0.1.
|
|
63
|
+
"@asgardeo/javascript": "^0.1.21"
|
|
64
64
|
},
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"access": "public"
|