Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IAMRISK-2817] Update API for Arkose to use a callback based API #1349

Merged
merged 11 commits into from
Oct 19, 2023
42 changes: 19 additions & 23 deletions dist/auth0.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* auth0-js v9.23.0
* Author: Auth0
* Date: 2023-10-06
* Date: 2023-10-17
* License: MIT
*/

Expand Down Expand Up @@ -7563,6 +7563,7 @@
// eslint-disable-next-line no-unused-vars

var noop = function () {};
var captchaSolved = noop;

var RECAPTCHA_V2_PROVIDER = 'recaptcha_v2';
var RECAPTCHA_ENTERPRISE_PROVIDER = 'recaptcha_enterprise';
Expand Down Expand Up @@ -7721,6 +7722,7 @@
);
if (opts.provider === ARKOSE_PROVIDER) {
var retryCount = 0;
window.requiresTrigger = true;
attributes['data-callback'] = callbackName;
attributes['onerror'] = function () {
if (retryCount < MAX_RETRY) {
Expand Down Expand Up @@ -7815,11 +7817,9 @@
arkose.setConfig({
onCompleted: function (response) {
setValue(response.token);
if (options.callbacks && options.callbacks.onSolved) {
options.callbacks.onSolved();
}
captchaSolved();
},
onError: function (response) {
onError: function () {
if (retryCount < MAX_RETRY) {
setValue();
arkose.reset();
Expand All @@ -7832,9 +7832,6 @@
// Optimzation to tell auth0 to fail open if Arkose is configured to fail open
setValue('BYPASS_CAPTCHA');
}
if (options.callbacks && options.callbacks.onError) {
options.callbacks.onError(response.error);
}
}
});
} else if (challenge.provider === FRIENDLY_CAPTCHA_PROVIDER) {
Expand Down Expand Up @@ -7866,8 +7863,13 @@
);
}

function runArkose() {
function triggerCaptcha(callback) {
globalForCaptchaProvider(ARKOSE_PROVIDER).run();
captchaSolved = callback;
}

function requiresTrigger() {
return window.requiresTrigger || false;
}

/**
Expand All @@ -7883,11 +7885,9 @@
* @param {Function} [options.templates.recaptcha_enterprise] template function receiving the challenge and returning a string
* @param {Function} [options.templates.hcaptcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.friendly_captcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.arkose] template function receiving the challenge and returning a string
* @param {Function} [options.templates.error] template function returning a custom error message when the challenge could not be fetched, receives the error as first argument
* @param {String} [options.lang=en] the ISO code of the language for recaptcha
* @param {Object} [options.callbacks] An optional object containing callbacks called after captcha events (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onSolved] An optional callback called after the captcha is solved (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onError] An optional callback called after the captcha encounters an error with the error passed as the first argument (only for Arkose captcha provider)
* @param {Function} [callback] An optional callback called after captcha is loaded
* @ignore
*/
Expand Down Expand Up @@ -7934,7 +7934,8 @@
return {
reload: load,
getValue: getValue,
runArkose: runArkose
triggerCaptcha: triggerCaptcha,
requiresTrigger: requiresTrigger
};
}

Expand All @@ -7951,11 +7952,9 @@
* @param {Function} [options.templates.recaptcha_enterprise] template function receiving the challenge and returning a string
* @param {Function} [options.templates.hcaptcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.friendly_captcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.arkose] template function receiving the challenge and returning a string
* @param {Function} [options.templates.error] template function returning a custom error message when the challenge could not be fetched, receives the error as first argument
* @param {String} [options.lang=en] the ISO code of the language for recaptcha
* @param {Object} [options.callbacks] An optional object containing callbacks called after captcha events (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onSolved] An optional callback called after the captcha is solved (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onError] An optional callback called after the captcha encounters an error with the error passed as the first argument (only for Arkose captcha provider)
* @param {Function} [callback] An optional callback called after captcha is loaded
* @ignore
*/
Expand Down Expand Up @@ -8002,7 +8001,8 @@
return {
reload: load,
getValue: getValue,
runArkose: runArkose
triggerCaptcha: triggerCaptcha,
requiresTrigger: requiresTrigger
};
}

Expand Down Expand Up @@ -9133,11 +9133,9 @@
* @param {Function} [options.templates.recaptcha_enterprise] template function receiving the challenge and returning a string
* @param {Function} [options.templates.hcaptcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.friendly_captcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.arkose] template function receiving the challenge and returning a string
* @param {Function} [options.templates.error] template function returning a custom error message when the challenge could not be fetched, receives the error as first argument
* @param {String} [options.lang=en] the ISO code of the language for the captcha provider
* @param {Object} [options.callbacks] An optional object containing callbacks called after captcha events (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onSolved] An optional callback called after the captcha is solved (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onError] An optional callback called after the captcha encounters an error with the error passed as the first argument (only for Arkose captcha provider)
* @param {Function} [callback] An optional callback called after captcha is loaded
* @memberof WebAuth.prototype
*/
Expand All @@ -9159,11 +9157,9 @@
* @param {Function} [options.templates.recaptcha_enterprise] template function receiving the challenge and returning a string
* @param {Function} [options.templates.hcaptcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.friendly_captcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.arkose] template function receiving the challenge and returning a string
* @param {Function} [options.templates.error] template function returning a custom error message when the challenge could not be fetched, receives the error as first argument
* @param {String} [options.lang=en] the ISO code of the language for the captcha provider
* @param {Object} [options.callbacks] An optional object containing callbacks called after captcha events (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onSolved] An optional callback called after the captcha is solved (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onError] An optional callback called after the captcha encounters an error with the error passed as the first argument (only for Arkose captcha provider)
* @param {Function} [callback] An optional callback called after captcha is loaded
* @memberof WebAuth.prototype
*/
Expand Down
4 changes: 2 additions & 2 deletions dist/auth0.min.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/auth0.min.esm.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/auth0.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/auth0.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cordova-auth0-plugin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* auth0-js v9.23.0
* Author: Auth0
* Date: 2023-10-06
* Date: 2023-10-17
* License: MIT
*/

Expand Down
2 changes: 1 addition & 1 deletion dist/cordova-auth0-plugin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions src/web-auth/captcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Authentication from '../authentication';
import object from '../helper/object';

var noop = function () {};
var captchaSolved = noop;

var RECAPTCHA_V2_PROVIDER = 'recaptcha_v2';
var RECAPTCHA_ENTERPRISE_PROVIDER = 'recaptcha_enterprise';
Expand Down Expand Up @@ -161,6 +162,7 @@ function injectCaptchaScript(element, opts, callback, setValue) {
);
if (opts.provider === ARKOSE_PROVIDER) {
var retryCount = 0;
window.requiresTrigger = true;
srijonsaha marked this conversation as resolved.
Show resolved Hide resolved
attributes['data-callback'] = callbackName;
attributes['onerror'] = function () {
if (retryCount < MAX_RETRY) {
Expand Down Expand Up @@ -255,11 +257,9 @@ function handleCaptchaProvider(element, options, challenge) {
arkose.setConfig({
onCompleted: function (response) {
setValue(response.token);
if (options.callbacks && options.callbacks.onSolved) {
options.callbacks.onSolved();
}
captchaSolved();
},
onError: function (response) {
onError: function () {
if (retryCount < MAX_RETRY) {
setValue();
arkose.reset();
Expand All @@ -272,9 +272,6 @@ function handleCaptchaProvider(element, options, challenge) {
// Optimzation to tell auth0 to fail open if Arkose is configured to fail open
setValue('BYPASS_CAPTCHA');
}
if (options.callbacks && options.callbacks.onError) {
options.callbacks.onError(response.error);
}
}
});
} else if (challenge.provider === FRIENDLY_CAPTCHA_PROVIDER) {
Expand Down Expand Up @@ -306,8 +303,13 @@ function handleCaptchaProvider(element, options, challenge) {
);
}

function runArkose() {
function triggerCaptcha(callback) {
srijonsaha marked this conversation as resolved.
Show resolved Hide resolved
globalForCaptchaProvider(ARKOSE_PROVIDER).run();
captchaSolved = callback;
srijonsaha marked this conversation as resolved.
Show resolved Hide resolved
}

function requiresTrigger() {
return window.requiresTrigger || false;
}

/**
Expand All @@ -323,11 +325,9 @@ function runArkose() {
* @param {Function} [options.templates.recaptcha_enterprise] template function receiving the challenge and returning a string
* @param {Function} [options.templates.hcaptcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.friendly_captcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.arkose] template function receiving the challenge and returning a string
* @param {Function} [options.templates.error] template function returning a custom error message when the challenge could not be fetched, receives the error as first argument
* @param {String} [options.lang=en] the ISO code of the language for recaptcha
* @param {Object} [options.callbacks] An optional object containing callbacks called after captcha events (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onSolved] An optional callback called after the captcha is solved (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onError] An optional callback called after the captcha encounters an error with the error passed as the first argument (only for Arkose captcha provider)
* @param {Function} [callback] An optional callback called after captcha is loaded
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

callback -> captchaLoadedCallback right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, that's an internal module, not the public interface 👍

Copy link
Member

@frederikprijck frederikprijck Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callback is typed as captchaLoadedCallback in jsDocs, but the argument name is still callback, or done, or whatever is used in the specific case where we use callbacks. The argument shouldnt be named the same as the type, regardless of internal of public interface.

* @ignore
frederikprijck marked this conversation as resolved.
Show resolved Hide resolved
*/
Expand Down Expand Up @@ -374,7 +374,8 @@ function render(auth0Client, element, options, callback) {
return {
reload: load,
getValue: getValue,
runArkose: runArkose
triggerCaptcha: triggerCaptcha,
requiresTrigger: requiresTrigger
};
}

Expand All @@ -391,11 +392,9 @@ function render(auth0Client, element, options, callback) {
* @param {Function} [options.templates.recaptcha_enterprise] template function receiving the challenge and returning a string
* @param {Function} [options.templates.hcaptcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.friendly_captcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.arkose] template function receiving the challenge and returning a string
* @param {Function} [options.templates.error] template function returning a custom error message when the challenge could not be fetched, receives the error as first argument
* @param {String} [options.lang=en] the ISO code of the language for recaptcha
* @param {Object} [options.callbacks] An optional object containing callbacks called after captcha events (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onSolved] An optional callback called after the captcha is solved (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onError] An optional callback called after the captcha encounters an error with the error passed as the first argument (only for Arkose captcha provider)
* @param {Function} [callback] An optional callback called after captcha is loaded
* @ignore
*/
Expand Down Expand Up @@ -442,7 +441,8 @@ function renderPasswordless(auth0Client, element, options, callback) {
return {
reload: load,
getValue: getValue,
runArkose: runArkose
triggerCaptcha: triggerCaptcha,
requiresTrigger: requiresTrigger
};
}

Expand Down
8 changes: 2 additions & 6 deletions src/web-auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1143,11 +1143,9 @@ WebAuth.prototype.passwordlessVerify = function (options, cb) {
* @param {Function} [options.templates.recaptcha_enterprise] template function receiving the challenge and returning a string
* @param {Function} [options.templates.hcaptcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.friendly_captcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.arkose] template function receiving the challenge and returning a string
* @param {Function} [options.templates.error] template function returning a custom error message when the challenge could not be fetched, receives the error as first argument
* @param {String} [options.lang=en] the ISO code of the language for the captcha provider
* @param {Object} [options.callbacks] An optional object containing callbacks called after captcha events (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onSolved] An optional callback called after the captcha is solved (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onError] An optional callback called after the captcha encounters an error with the error passed as the first argument (only for Arkose captcha provider)
* @param {Function} [callback] An optional callback called after captcha is loaded
* @memberof WebAuth.prototype
*/
Expand All @@ -1169,11 +1167,9 @@ WebAuth.prototype.renderCaptcha = function (element, options, callback) {
* @param {Function} [options.templates.recaptcha_enterprise] template function receiving the challenge and returning a string
* @param {Function} [options.templates.hcaptcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.friendly_captcha] template function receiving the challenge and returning a string
* @param {Function} [options.templates.arkose] template function receiving the challenge and returning a string
* @param {Function} [options.templates.error] template function returning a custom error message when the challenge could not be fetched, receives the error as first argument
* @param {String} [options.lang=en] the ISO code of the language for the captcha provider
* @param {Object} [options.callbacks] An optional object containing callbacks called after captcha events (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onSolved] An optional callback called after the captcha is solved (only for Arkose captcha provider)
* @param {Function} [options.callbacks.onError] An optional callback called after the captcha encounters an error with the error passed as the first argument (only for Arkose captcha provider)
* @param {Function} [callback] An optional callback called after captcha is loaded
* @memberof WebAuth.prototype
*/
Expand Down
Loading