mirror of
https://github.com/bitwarden/browser
synced 2025-01-23 09:42:06 +01:00
add captcha connector (#1042)
* add captcha connector * Update src/connectors/captcha.html Co-authored-by: Addison Beck <abeck@bitwarden.com> * Update src/connectors/captcha.scss Co-authored-by: Addison Beck <abeck@bitwarden.com> Co-authored-by: Addison Beck <abeck@bitwarden.com>
This commit is contained in:
parent
f8a7439675
commit
f74c296ad5
14
src/connectors/captcha.html
Normal file
14
src/connectors/captcha.html
Normal file
@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Bitwarden Captcha Connector</title>
|
||||
<script src="https://hcaptcha.com/1/api.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="captcha"></div>
|
||||
</body>
|
||||
|
||||
</html>
|
6
src/connectors/captcha.scss
Normal file
6
src/connectors/captcha.scss
Normal file
@ -0,0 +1,6 @@
|
||||
body {
|
||||
min-width: 0px !important;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
background: transparent;
|
||||
}
|
85
src/connectors/captcha.ts
Normal file
85
src/connectors/captcha.ts
Normal file
@ -0,0 +1,85 @@
|
||||
import { getQsParam } from './common';
|
||||
|
||||
declare var hcaptcha: any;
|
||||
|
||||
// tslint:disable-next-line
|
||||
require('./captcha.scss');
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
init();
|
||||
});
|
||||
|
||||
(window as any).captchaSuccess = captchaSuccess;
|
||||
(window as any).captchaError = captchaError;
|
||||
|
||||
let parentUrl: string = null;
|
||||
let parentOrigin: string = null;
|
||||
let sentSuccess = false;
|
||||
|
||||
function init() {
|
||||
start();
|
||||
onMessage();
|
||||
info('ready');
|
||||
}
|
||||
|
||||
function start() {
|
||||
sentSuccess = false;
|
||||
|
||||
const data = getQsParam('data');
|
||||
if (!data) {
|
||||
error('No data.');
|
||||
return;
|
||||
}
|
||||
|
||||
parentUrl = getQsParam('parent');
|
||||
if (!parentUrl) {
|
||||
error('No parent.');
|
||||
return;
|
||||
} else {
|
||||
parentUrl = decodeURIComponent(parentUrl);
|
||||
parentOrigin = new URL(parentUrl).origin;
|
||||
}
|
||||
|
||||
hcaptcha.render('captcha', {
|
||||
sitekey: 'bc38c8a2-5311-4e8c-9dfc-49e99f6df417',
|
||||
callback: 'captchaSuccess',
|
||||
'error-callback': 'captchaError',
|
||||
});
|
||||
}
|
||||
|
||||
function captchaSuccess(response: string) {
|
||||
success(response);
|
||||
}
|
||||
|
||||
function captchaError() {
|
||||
error('An error occurred with the captcha. Try again.');
|
||||
}
|
||||
|
||||
function onMessage() {
|
||||
window.addEventListener('message', event => {
|
||||
if (!event.origin || event.origin === '' || event.origin !== parentOrigin) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.data === 'start') {
|
||||
start();
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
||||
function error(message: string) {
|
||||
parent.postMessage('error|' + message, parentUrl);
|
||||
}
|
||||
|
||||
function success(data: string) {
|
||||
if (sentSuccess) {
|
||||
return;
|
||||
}
|
||||
parent.postMessage('success|' + data, parentUrl);
|
||||
sentSuccess = true;
|
||||
}
|
||||
|
||||
function info(message: string) {
|
||||
parent.postMessage('info|' + message, parentUrl);
|
||||
}
|
||||
|
@ -107,6 +107,11 @@ const plugins = [
|
||||
filename: 'sso-connector.html',
|
||||
chunks: ['connectors/sso'],
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
template: './src/connectors/captcha.html',
|
||||
filename: 'captcha-connector.html',
|
||||
chunks: ['connectors/captcha'],
|
||||
}),
|
||||
new CopyWebpackPlugin({
|
||||
patterns:[
|
||||
{ from: './src/.nojekyll' },
|
||||
@ -198,6 +203,7 @@ const webpackConfig = {
|
||||
'connectors/webauthn-fallback': './src/connectors/webauthn-fallback.ts',
|
||||
'connectors/duo': './src/connectors/duo.ts',
|
||||
'connectors/sso': './src/connectors/sso.ts',
|
||||
'connectors/captcha': './src/connectors/captcha.ts',
|
||||
},
|
||||
externals: {
|
||||
'u2f': 'u2f',
|
||||
|
Loading…
Reference in New Issue
Block a user