mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-06-20 13:00:39 +00:00
feat: add support for steam:// secrets in TOTP handling and corresponding tests
This commit is contained in:
@@ -171,10 +171,23 @@ function normalizeTotpSecret(secret: string): string {
|
||||
return secret.toUpperCase().replace(/[\s-]/g, '').replace(/=+$/g, '');
|
||||
}
|
||||
|
||||
function parseSteamSecret(raw: string): string {
|
||||
const match = raw.trim().match(/^steam:\/\/([^/?#]+)(?:[/?#].*)?$/i);
|
||||
if (!match?.[1]) return '';
|
||||
try {
|
||||
return normalizeTotpSecret(decodeURIComponent(match[1]));
|
||||
} catch {
|
||||
return normalizeTotpSecret(match[1]);
|
||||
}
|
||||
}
|
||||
|
||||
function parseTotpConfig(raw: string): { secret: string; steam: boolean } {
|
||||
if (!raw) return { secret: '', steam: false };
|
||||
const s = raw.trim();
|
||||
if (!s) return { secret: '', steam: false };
|
||||
if (/^steam:\/\//i.test(s)) {
|
||||
return { secret: parseSteamSecret(s), steam: true };
|
||||
}
|
||||
if (/^otpauth:\/\//i.test(s)) {
|
||||
try {
|
||||
const u = new URL(s);
|
||||
|
||||
Reference in New Issue
Block a user