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
71 changes: 39 additions & 32 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-19
* 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 @@ -7815,11 +7816,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 +7831,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,10 +7862,6 @@
);
}

function runArkose() {
globalForCaptchaProvider(ARKOSE_PROVIDER).run();
}

/**
*
* Renders the captcha challenge in the provided element.
Expand All @@ -7883,11 +7875,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 @@ -7917,7 +7907,16 @@
) {
handleCaptchaProvider(element, options, challenge);
}
done();
if (challenge.provider === ARKOSE_PROVIDER) {
done(null, {
triggerCaptcha: function (solvedCallback) {
globalForCaptchaProvider(challenge.provider).run();
captchaSolved = solvedCallback;
}
});
} else {
done();
}
});
}

Expand All @@ -7933,8 +7932,7 @@

return {
reload: load,
getValue: getValue,
runArkose: runArkose
getValue: getValue
};
}

Expand All @@ -7951,11 +7949,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 @@ -7985,7 +7981,16 @@
) {
handleCaptchaProvider(element, options, challenge);
}
done();
if (challenge.provider === ARKOSE_PROVIDER) {
done(null, {
triggerCaptcha: function (solvedCallback) {
globalForCaptchaProvider(challenge.provider).run();
captchaSolved = solvedCallback;
}
});
} else {
done();
}
});
}

Expand All @@ -8001,8 +8006,7 @@

return {
reload: load,
getValue: getValue,
runArkose: runArkose
getValue: getValue
};
}

Expand Down Expand Up @@ -9119,6 +9123,13 @@
});
};

/**
* @callback doneCallback
* @param {Error} [err] Error returned if request to get captcha challenge fails
* @param {Object} [apis] An object containing a callback to trigger the captcha (only if Arkose is the provider)
* @param {Function} [apis.triggerCaptcha] Triggers the captcha with the first parameter as a callback to be fired after it's solved
*/

/**
*
* Renders the captcha challenge in the provided element.
Expand All @@ -9133,12 +9144,10 @@
* @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
* @param {doneCallback} [callback] An optional callback called after captcha is loaded
* @memberof WebAuth.prototype
*/
WebAuth.prototype.renderCaptcha = function (element, options, callback) {
Expand All @@ -9159,12 +9168,10 @@
* @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
* @param {doneCallback} [callback] An optional callback called after captcha is loaded
* @memberof WebAuth.prototype
*/
WebAuth.prototype.renderPasswordlessCaptcha = function (
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-19
* 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.

50 changes: 27 additions & 23 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 @@ -255,11 +256,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 +271,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,10 +302,6 @@ function handleCaptchaProvider(element, options, challenge) {
);
}

function runArkose() {
globalForCaptchaProvider(ARKOSE_PROVIDER).run();
}

/**
*
* Renders the captcha challenge in the provided element.
Expand All @@ -323,11 +315,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 @@ -357,7 +347,16 @@ function render(auth0Client, element, options, callback) {
) {
handleCaptchaProvider(element, options, challenge);
}
done();
if (challenge.provider === ARKOSE_PROVIDER) {
done(null, {
triggerCaptcha: function (solvedCallback) {
globalForCaptchaProvider(challenge.provider).run();
captchaSolved = solvedCallback;
}
});
} else {
done();
}
});
}

Expand All @@ -373,8 +372,7 @@ function render(auth0Client, element, options, callback) {

return {
reload: load,
getValue: getValue,
runArkose: runArkose
getValue: getValue
};
}

Expand All @@ -391,11 +389,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 @@ -425,7 +421,16 @@ function renderPasswordless(auth0Client, element, options, callback) {
) {
handleCaptchaProvider(element, options, challenge);
}
done();
if (challenge.provider === ARKOSE_PROVIDER) {
done(null, {
triggerCaptcha: function (solvedCallback) {
globalForCaptchaProvider(challenge.provider).run();
captchaSolved = solvedCallback;
}
});
} else {
done();
}
});
}

Expand All @@ -441,8 +446,7 @@ function renderPasswordless(auth0Client, element, options, callback) {

return {
reload: load,
getValue: getValue,
runArkose: runArkose
getValue: getValue
};
}

Expand Down
19 changes: 11 additions & 8 deletions src/web-auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,13 @@ WebAuth.prototype.passwordlessVerify = function (options, cb) {
});
};

/**
* @callback doneCallback
srijonsaha marked this conversation as resolved.
Show resolved Hide resolved
* @param {Error} [err] Error returned if request to get captcha challenge fails
* @param {Object} [apis] An object containing a callback to trigger the captcha (only if Arkose is the provider)
srijonsaha marked this conversation as resolved.
Show resolved Hide resolved
* @param {Function} [apis.triggerCaptcha] Triggers the captcha with the first parameter as a callback to be fired after it's solved
srijonsaha marked this conversation as resolved.
Show resolved Hide resolved
*/

/**
*
* Renders the captcha challenge in the provided element.
Expand All @@ -1143,12 +1150,10 @@ 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
* @param {doneCallback} [callback] An optional callback called after captcha is loaded
srijonsaha marked this conversation as resolved.
Show resolved Hide resolved
* @memberof WebAuth.prototype
*/
WebAuth.prototype.renderCaptcha = function (element, options, callback) {
Expand All @@ -1169,12 +1174,10 @@ 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
* @param {doneCallback} [callback] An optional callback called after captcha is loaded
srijonsaha marked this conversation as resolved.
Show resolved Hide resolved
* @memberof WebAuth.prototype
*/
WebAuth.prototype.renderPasswordlessCaptcha = function (
Expand Down
Loading