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

Call done callback once Arkose is ready #1433

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
676 changes: 482 additions & 194 deletions dist/auth0.js

Large diffs are not rendered by default.

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.

624 changes: 451 additions & 173 deletions dist/cordova-auth0-plugin.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

44 changes: 27 additions & 17 deletions src/web-auth/captcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ function globalForCaptchaProvider(provider) {
return window.arkose;
case AUTH0_V2_CAPTCHA_PROVIDER:
return window.turnstile;
/* istanbul ignore next */
default:
throw new Error('Unknown captcha provider');
}
Expand Down Expand Up @@ -163,7 +162,7 @@ function removeScript(url) {
});
}

function injectCaptchaScript(element, opts, callback, setValue) {
function injectCaptchaScript(opts, callback, setValue, done) {
var callbackName =
opts.provider + 'Callback_' + Math.floor(Math.random() * 1000001);
var attributes = {
Expand Down Expand Up @@ -191,6 +190,7 @@ function injectCaptchaScript(element, opts, callback, setValue) {
return;
}
removeScript(scriptSrc);
done(new Error(opts.provider + ' failed to load'));
// Optimzation to tell auth0 to fail open if Arkose/auth0_v2 is configured to fail open
setValue('BYPASS_CAPTCHA');
};
Expand All @@ -210,7 +210,7 @@ function injectCaptchaScript(element, opts, callback, setValue) {
loadScript(scriptSrc, attributes);
}

function handleCaptchaProvider(element, options, challenge) {
function handleCaptchaProvider(element, options, challenge, done) {
var widgetId =
element.hasAttribute('data-wid') && element.getAttribute('data-wid');

Expand Down Expand Up @@ -265,7 +265,6 @@ function handleCaptchaProvider(element, options, challenge) {
var captchaDiv = element.querySelector(captchaClass);

injectCaptchaScript(
element,
{
lang: options.lang,
provider: challenge.provider,
Expand All @@ -276,12 +275,24 @@ function handleCaptchaProvider(element, options, challenge) {
var global = globalForCaptchaProvider(challenge.provider);
if (challenge.provider === ARKOSE_PROVIDER) {
var retryCount = 0;
var arkoseLoaded = false;
arkose.setConfig({
onReady: function () {
if (!arkoseLoaded) {
srijonsaha marked this conversation as resolved.
Show resolved Hide resolved
done(null, {
triggerCaptcha: function (solvedCallback) {
arkose.run();
captchaSolved = solvedCallback;
}
});
arkoseLoaded = true;
}
},
srijonsaha marked this conversation as resolved.
Show resolved Hide resolved
onCompleted: function (response) {
setValue(response.token);
captchaSolved();
},
onError: function () {
onError: function (response) {
if (retryCount < MAX_RETRY) {
setValue();
arkose.reset();
Expand All @@ -291,6 +302,10 @@ function handleCaptchaProvider(element, options, challenge) {
}, 500);
retryCount++;
} else {
if (!arkoseLoaded) {
done(new Error(response.error.error));
arkoseLoaded = true;
}
// Optimzation to tell auth0 to fail open if Arkose is configured to fail open
setValue('BYPASS_CAPTCHA');
}
Expand All @@ -307,6 +322,7 @@ function handleCaptchaProvider(element, options, challenge) {
setValue();
}
});
done();
} else {
var renderParams = {
callback: setValue,
Expand Down Expand Up @@ -338,9 +354,11 @@ function handleCaptchaProvider(element, options, challenge) {
}
widgetId = global.render(captchaDiv, renderParams);
element.setAttribute('data-wid', widgetId);
done();
}
},
setValue
setValue,
done
);
}

Expand Down Expand Up @@ -382,6 +400,7 @@ function render(auth0Client, flow, element, options, callback) {
element.style.display = '';
if (challenge.provider === AUTH0_PROVIDER) {
handleAuth0Provider(element, options, challenge, load);
done();
} else if (
challenge.provider === RECAPTCHA_V2_PROVIDER ||
challenge.provider === RECAPTCHA_ENTERPRISE_PROVIDER ||
Expand All @@ -390,19 +409,10 @@ function render(auth0Client, flow, element, options, callback) {
challenge.provider === ARKOSE_PROVIDER ||
challenge.provider === AUTH0_V2_CAPTCHA_PROVIDER
) {
handleCaptchaProvider(element, options, challenge);
}
if (challenge.provider === ARKOSE_PROVIDER) {
done(null, {
triggerCaptcha: function (solvedCallback) {
globalForCaptchaProvider(challenge.provider).run();
captchaSolved = solvedCallback;
}
});
} else {
done();
handleCaptchaProvider(element, options, challenge, done);
}
}

if (flow === Flow.PASSWORDLESS) {
auth0Client.passwordless.getChallenge(challengeCallback);
} else if (flow === Flow.PASSWORD_RESET) {
Expand Down
Loading
Loading