mirror of https://github.com/keeweb/keeweb.git
fix: support for different otpauth url syntax
adds support for otpauth://totp? and otpauth://totp/
This commit is contained in:
parent
d0d163bf5e
commit
80370d128c
|
@ -467,6 +467,7 @@ class EntryModel extends Model {
|
||||||
if (otpUrl.isProtected) {
|
if (otpUrl.isProtected) {
|
||||||
otpUrl = otpUrl.getText();
|
otpUrl = otpUrl.getText();
|
||||||
}
|
}
|
||||||
|
// called only if secret provided, no formatted url
|
||||||
if (Otp.isSecret(otpUrl.replace(/\s/g, ''))) {
|
if (Otp.isSecret(otpUrl.replace(/\s/g, ''))) {
|
||||||
otpUrl = Otp.makeUrl(otpUrl.replace(/\s/g, '').toUpperCase());
|
otpUrl = Otp.makeUrl(otpUrl.replace(/\s/g, '').toUpperCase());
|
||||||
} else if (otpUrl.toLowerCase().lastIndexOf('otpauth:', 0) !== 0) {
|
} else if (otpUrl.toLowerCase().lastIndexOf('otpauth:', 0) !== 0) {
|
||||||
|
|
|
@ -135,12 +135,12 @@ Otp.leftPad = function (str, len) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Otp.parseUrl = function (url) {
|
Otp.parseUrl = function (url) {
|
||||||
const match = /^otpauth:\/\/(\w+)\/([^\?]+)\?(.*)/i.exec(url);
|
const match = /^otpauth:\/\/(\w+)(?:\/([^\?]+)\?|\?)(.*)/i.exec(url);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
throw 'Not OTP url';
|
throw 'Not OTP url';
|
||||||
}
|
}
|
||||||
const params = {};
|
const params = {};
|
||||||
const label = decodeURIComponent(match[2]);
|
const label = decodeURIComponent(match[2] ?? 'default');
|
||||||
if (label) {
|
if (label) {
|
||||||
const parts = label.split(':');
|
const parts = label.split(':');
|
||||||
params.issuer = parts[0].trim();
|
params.issuer = parts[0].trim();
|
||||||
|
@ -148,7 +148,8 @@ Otp.parseUrl = function (url) {
|
||||||
params.account = parts[1].trim();
|
params.account = parts[1].trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
params.type = match[1].toLowerCase();
|
params.type = match[1].toLowerCase(); // returns "totp"
|
||||||
|
// match[3] = secret=XXXXXXXXXXXXX&period=30&digits=6&algorithm=SHA1
|
||||||
match[3].split('&').forEach((part) => {
|
match[3].split('&').forEach((part) => {
|
||||||
const parts = part.split('=', 2);
|
const parts = part.split('=', 2);
|
||||||
params[parts[0].toLowerCase()] = decodeURIComponent(parts[1]);
|
params[parts[0].toLowerCase()] = decodeURIComponent(parts[1]);
|
||||||
|
|
Loading…
Reference in New Issue