|
| 1 | +/* |
| 2 | + * @forgerock/javascript-sdk |
| 3 | + * |
| 4 | + * response.webauthn.js |
| 5 | + * |
| 6 | + * Copyright (c) 2020 - 2025 Ping Identity Corporation. All rights reserved. |
| 7 | + * This software may be modified and distributed under the terms |
| 8 | + * of the MIT license. See the LICENSE file for details. |
| 9 | + */ |
| 10 | + |
| 11 | +/** |
| 12 | + * WebAuthn registration initialization response |
| 13 | + * Contains MetadataCallback for WebAuthn and HiddenValueCallback for credential |
| 14 | + */ |
| 15 | +export const webAuthnRegistrationInit = { |
| 16 | + authId: 'webauthn-registration-init', |
| 17 | + callbacks: [ |
| 18 | + { |
| 19 | + type: 'MetadataCallback', |
| 20 | + output: [ |
| 21 | + { |
| 22 | + name: 'data', |
| 23 | + value: { |
| 24 | + _type: 'WebAuthn', |
| 25 | + _action: 'webauthn_registration', |
| 26 | + challenge: 'dGVzdC1jaGFsbGVuZ2UtZm9yLXdlYmF1dGhu', |
| 27 | + relyingPartyId: 'localhost', |
| 28 | + relyingPartyName: 'ForgeRock', |
| 29 | + userId: 'dGVzdC11c2VyLWlk', |
| 30 | + userName: 'testuser', |
| 31 | + displayName: 'Test User', |
| 32 | + timeout: 60000, |
| 33 | + attestationPreference: 'none', |
| 34 | + authenticatorAttachment: 'platform', |
| 35 | + requireResidentKey: false, |
| 36 | + userVerification: 'preferred', |
| 37 | + pubKeyCredParams: [ |
| 38 | + { type: 'public-key', alg: -7 }, |
| 39 | + { type: 'public-key', alg: -257 }, |
| 40 | + ], |
| 41 | + }, |
| 42 | + }, |
| 43 | + ], |
| 44 | + }, |
| 45 | + { |
| 46 | + type: 'HiddenValueCallback', |
| 47 | + output: [ |
| 48 | + { |
| 49 | + name: 'value', |
| 50 | + value: '', |
| 51 | + }, |
| 52 | + { |
| 53 | + name: 'id', |
| 54 | + value: 'webAuthnOutcome', |
| 55 | + }, |
| 56 | + ], |
| 57 | + input: [ |
| 58 | + { |
| 59 | + name: 'IDToken2', |
| 60 | + value: '', |
| 61 | + }, |
| 62 | + ], |
| 63 | + }, |
| 64 | + ], |
| 65 | +}; |
| 66 | + |
| 67 | +/** |
| 68 | + * Returns the recovery codes display response |
| 69 | + * This simulates the step after WebAuthn registration where recovery codes are shown |
| 70 | + */ |
| 71 | +export function getRecoveryCodesDisplay() { |
| 72 | + const recoveryCodes = [ |
| 73 | + 'ABC123DEF4', |
| 74 | + 'GHI567JKL8', |
| 75 | + 'MNO901PQR2', |
| 76 | + 'STU345VWX6', |
| 77 | + 'YZA789BCD0', |
| 78 | + 'EFG123HIJ4', |
| 79 | + 'KLM567NOP8', |
| 80 | + 'QRS901TUV2', |
| 81 | + 'WXY345ZAB6', |
| 82 | + 'CDE789FGH0', |
| 83 | + ]; |
| 84 | + |
| 85 | + // Build the recovery codes HTML similar to what AM generates |
| 86 | + const codesHtml = recoveryCodes |
| 87 | + .map((code) => `"<div class=\\"text-center\\">\\n" +\n "${code}\\n" +\n "</div>\\n" +`) |
| 88 | + .join('\n '); |
| 89 | + |
| 90 | + const scriptValue = `/* |
| 91 | + * Copyright 2018 ForgeRock AS. All Rights Reserved |
| 92 | + * |
| 93 | + * Use of this code requires a commercial software license with ForgeRock AS. |
| 94 | + * or with one of its affiliates. All use shall be exclusively subject |
| 95 | + * to such license between the licensee and ForgeRock AS. |
| 96 | + */ |
| 97 | +
|
| 98 | +var newLocation = document.getElementById("wrapper"); |
| 99 | +var oldHtml = newLocation.getElementsByTagName("fieldset")[0].innerHTML; |
| 100 | +newLocation.getElementsByTagName("fieldset")[0].innerHTML = "<div class=\\"panel panel-default\\">\\n" + |
| 101 | + " <div class=\\"panel-body text-center\\">\\n" + |
| 102 | + " <h3>Your Recovery Codes</h3>\\n" + |
| 103 | + " <h4>You must make a copy of these recovery codes. They cannot be displayed again.</h4>\\n" + |
| 104 | + " </div>\\n" + |
| 105 | + ${codesHtml} |
| 106 | + "<div class=\\"panel-body text-center\\">\\n" + |
| 107 | + " <p>Use one of these codes to authenticate if you lose your device, which has been named: <em>New Security Key</em></p>\\n" + |
| 108 | + "</div>\\n" + |
| 109 | + "</div>" + oldHtml; |
| 110 | +document.body.appendChild(newLocation); |
| 111 | +`; |
| 112 | + |
| 113 | + return { |
| 114 | + authId: 'recovery-codes-display', |
| 115 | + callbacks: [ |
| 116 | + { |
| 117 | + type: 'TextOutputCallback', |
| 118 | + output: [ |
| 119 | + { |
| 120 | + name: 'message', |
| 121 | + value: scriptValue, |
| 122 | + }, |
| 123 | + { |
| 124 | + name: 'messageType', |
| 125 | + value: '4', |
| 126 | + }, |
| 127 | + ], |
| 128 | + }, |
| 129 | + { |
| 130 | + type: 'ConfirmationCallback', |
| 131 | + output: [ |
| 132 | + { |
| 133 | + name: 'prompt', |
| 134 | + value: '', |
| 135 | + }, |
| 136 | + { |
| 137 | + name: 'messageType', |
| 138 | + value: 0, |
| 139 | + }, |
| 140 | + { |
| 141 | + name: 'options', |
| 142 | + value: ['I have saved my recovery codes'], |
| 143 | + }, |
| 144 | + { |
| 145 | + name: 'optionType', |
| 146 | + value: -1, |
| 147 | + }, |
| 148 | + { |
| 149 | + name: 'defaultOption', |
| 150 | + value: 0, |
| 151 | + }, |
| 152 | + ], |
| 153 | + input: [ |
| 154 | + { |
| 155 | + name: 'IDToken2', |
| 156 | + value: 0, |
| 157 | + }, |
| 158 | + ], |
| 159 | + }, |
| 160 | + ], |
| 161 | + }; |
| 162 | +} |
| 163 | + |
| 164 | +/** |
| 165 | + * Auth success response for WebAuthn flow |
| 166 | + */ |
| 167 | +export const authSuccess = { |
| 168 | + tokenId: 'webauthn-session-token', |
| 169 | + successUrl: '/console', |
| 170 | + realm: '/', |
| 171 | +}; |
0 commit comments