* Function to handle executing actions using the grecaptcha Object, * and sending the token back to the parent amp-recaptcha component * * Data Object will have the following fields * action {string} - action to be dispatched with grecaptcha.execute * id {number} - id given to us by a counter i
(win, grecaptcha, data)
| 145 | * @param {object} data |
| 146 | */ |
| 147 | function actionTypeHandler(win, grecaptcha, data) { |
| 148 | doesOriginDomainMatchIframeSrc(win, data) |
| 149 | .then(() => { |
| 150 | const executePromise = grecaptcha.execute(sitekey, { |
| 151 | action: data.action, |
| 152 | }); |
| 153 | |
| 154 | // .then() promise pollyfilled by recaptcha api script |
| 155 | executePromise./*OK*/ then( |
| 156 | function (token) { |
| 157 | iframeMessagingClient./*OK*/ sendMessage('amp-recaptcha-token', { |
| 158 | 'id': data.id, |
| 159 | 'token': token, |
| 160 | }); |
| 161 | }, |
| 162 | function (err) { |
| 163 | let message = |
| 164 | 'There was an error running ' + |
| 165 | 'execute() on the reCAPTCHA script.'; |
| 166 | if (err) { |
| 167 | message = err.toString(); |
| 168 | } |
| 169 | user().error(TAG, '%s', message); |
| 170 | iframeMessagingClient./*OK*/ sendMessage('amp-recaptcha-error', { |
| 171 | 'id': data.id, |
| 172 | 'error': message, |
| 173 | }); |
| 174 | } |
| 175 | ); |
| 176 | }) |
| 177 | .catch((error) => { |
| 178 | dev().error(TAG, '%s', error.message); |
| 179 | }); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Function to verify our origin domain from the |
nothing calls this directly
no test coverage detected