mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 23:03:32 +00:00
Add connector for mobile webauthn (#1154)
Adds a dedicated connector for handling WebAuthN for our mobile application. Which uses redirects instead of postMessage.
This commit is contained in:
19
src/connectors/webauthn-mobile.html
Normal file
19
src/connectors/webauthn-mobile.html
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||||
|
<meta name="HandheldFriendly" content="true">
|
||||||
|
<title>Bitwarden Mobile WebAuthn Connector</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body style="background: transparent;">
|
||||||
|
<img src="../images/u2fkey.jpg" class="rounded img-fluid mb-3">
|
||||||
|
<div class="text-center">
|
||||||
|
<button id="webauthn-button" class="btn btn-primary"></button>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -9,6 +9,7 @@ let webauthnJson: any;
|
|||||||
let btnText: string = null;
|
let btnText: string = null;
|
||||||
let parentUrl: string = null;
|
let parentUrl: string = null;
|
||||||
let parentOrigin: string = null;
|
let parentOrigin: string = null;
|
||||||
|
let callbackUri: string = null;
|
||||||
let stopWebAuthn = false;
|
let stopWebAuthn = false;
|
||||||
let sentSuccess = false;
|
let sentSuccess = false;
|
||||||
let obj: any = null;
|
let obj: any = null;
|
||||||
@@ -66,7 +67,7 @@ function parseParametersV1() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseParametersV2() {
|
function parseParametersV2() {
|
||||||
let dataObj: { data: any, btnText: string; } = null;
|
let dataObj: { data: any, btnText: string; callbackUri?: string } = null;
|
||||||
try {
|
try {
|
||||||
dataObj = JSON.parse(b64Decode(getQsParam('data')));
|
dataObj = JSON.parse(b64Decode(getQsParam('data')));
|
||||||
}
|
}
|
||||||
@@ -75,6 +76,7 @@ function parseParametersV2() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callbackUri = dataObj.callbackUri;
|
||||||
webauthnJson = dataObj.data;
|
webauthnJson = dataObj.data;
|
||||||
btnText = dataObj.btnText;
|
btnText = dataObj.btnText;
|
||||||
}
|
}
|
||||||
@@ -104,7 +106,7 @@ function start() {
|
|||||||
stopWebAuthn = false;
|
stopWebAuthn = false;
|
||||||
|
|
||||||
if (navigator.userAgent.indexOf(' Safari/') !== -1 && navigator.userAgent.indexOf('Chrome') === -1) {
|
if (navigator.userAgent.indexOf(' Safari/') !== -1 && navigator.userAgent.indexOf('Chrome') === -1) {
|
||||||
// TODO: Hide image, show button
|
// Safari blocks non-user initiated WebAuthn requests.
|
||||||
} else {
|
} else {
|
||||||
executeWebAuthn();
|
executeWebAuthn();
|
||||||
}
|
}
|
||||||
@@ -136,7 +138,11 @@ function onMessage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function error(message: string) {
|
function error(message: string) {
|
||||||
|
if (callbackUri) {
|
||||||
|
document.location.replace(callbackUri + '?error=' + encodeURIComponent(message));
|
||||||
|
} else {
|
||||||
parent.postMessage('error|' + message, parentUrl);
|
parent.postMessage('error|' + message, parentUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function success(assertedCredential: PublicKeyCredential) {
|
function success(assertedCredential: PublicKeyCredential) {
|
||||||
@@ -145,11 +151,21 @@ function success(assertedCredential: PublicKeyCredential) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dataString = buildDataString(assertedCredential);
|
const dataString = buildDataString(assertedCredential);
|
||||||
|
|
||||||
|
if (callbackUri) {
|
||||||
|
document.location.replace(callbackUri + '?data=' + encodeURIComponent(dataString));
|
||||||
|
} else {
|
||||||
parent.postMessage('success|' + dataString, parentUrl);
|
parent.postMessage('success|' + dataString, parentUrl);
|
||||||
|
}
|
||||||
|
|
||||||
sentSuccess = true;
|
sentSuccess = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function info(message: string) {
|
function info(message: string) {
|
||||||
|
if (callbackUri) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
parent.postMessage('info|' + message, parentUrl);
|
parent.postMessage('info|' + message, parentUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,11 @@ const plugins = [
|
|||||||
filename: 'webauthn-connector.html',
|
filename: 'webauthn-connector.html',
|
||||||
chunks: ['connectors/webauthn'],
|
chunks: ['connectors/webauthn'],
|
||||||
}),
|
}),
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
template: './src/connectors/webauthn-mobile.html',
|
||||||
|
filename: 'webauthn-mobile-connector.html',
|
||||||
|
chunks: ['connectors/webauthn'],
|
||||||
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: './src/connectors/webauthn-fallback.html',
|
template: './src/connectors/webauthn-fallback.html',
|
||||||
filename: 'webauthn-fallback-connector.html',
|
filename: 'webauthn-fallback-connector.html',
|
||||||
|
|||||||
Reference in New Issue
Block a user