Skip to content

Commit 6d61217

Browse files
committed
fix: Can't export keys from google Authentificator app Android (#44)
1 parent 579554c commit 6d61217

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/lib/import/google-auth.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ function lengthFromGoogle(googleDigitsCount: number): TokenLength {
2222
return TokenLength.SixDigits;
2323
}
2424

25-
function nameFromGoogle(googleName: string): string {
26-
const [issuer, account] = googleName.split(':', 2);
27-
if (issuer && account) {
28-
return `${issuer} (${account})`;
25+
function nameFromGoogle(issuer: string, name: string): string {
26+
if (!issuer && name) {
27+
([issuer, name] = name.split(':', 2));
28+
}
29+
if (issuer && name) {
30+
return `${issuer} (${name})`;
2931
}
3032

31-
return googleName;
33+
return issuer || name;
3234
}
3335

3436
function tokenTypeFromGoogle(str?: string) {
@@ -39,7 +41,7 @@ function tokenTypeFromGoogle(str?: string) {
3941

4042
export function importFromGoogleAuthenticator(url: string | URL): TokenInfo[] {
4143
const uri = url instanceof URL ? url : new URL(url);
42-
if (uri.protocol !== 'otpauth-migration:' || uri.pathname !== '//offline') {
44+
if (uri.protocol !== 'otpauth-migration:' || uri.host !== 'offline') {
4345
throw Error('Invalid import data URL');
4446
}
4547
const encodedData = uri.searchParams.get('data') || '';
@@ -59,7 +61,7 @@ export function importFromGoogleAuthenticator(url: string | URL): TokenInfo[] {
5961
p =>
6062
new TokenInfo({
6163
type: tokenTypeFromGoogle(p.type),
62-
name: nameFromGoogle(p.name),
64+
name: nameFromGoogle(p.issuer, p.name),
6365
secret: p.secret,
6466
secretEncoding: TokenSecretEncoding.Base64,
6567
hashingAlgo: hashingAlgoFromGoogle(p.algorithm),

src/routes/import/google/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<li>Tap the hamburger-menu icon located on the top left corner</li>
6565
<li>Select "Transfer accounts"</li>
6666
<li>Select "Export accounts" and enter your PIN code when prompted</li>
67-
<li>Select the accounts you want to transfer into your new phone and then tap "Next"</li>
67+
<li>Select the accounts you want to transfer and then tap "Next"</li>
6868
<li>The app will display a QR code</li>
6969
<li>Use two possible options to scan QR code:</li>
7070
</ol>

0 commit comments

Comments
 (0)