@@ -22,13 +22,15 @@ function lengthFromGoogle(googleDigitsCount: number): TokenLength {
22
22
return TokenLength . SixDigits ;
23
23
}
24
24
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 } )` ;
29
31
}
30
32
31
- return googleName ;
33
+ return issuer || name ;
32
34
}
33
35
34
36
function tokenTypeFromGoogle ( str ?: string ) {
@@ -39,7 +41,7 @@ function tokenTypeFromGoogle(str?: string) {
39
41
40
42
export function importFromGoogleAuthenticator ( url : string | URL ) : TokenInfo [ ] {
41
43
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' ) {
43
45
throw Error ( 'Invalid import data URL' ) ;
44
46
}
45
47
const encodedData = uri . searchParams . get ( 'data' ) || '' ;
@@ -59,7 +61,7 @@ export function importFromGoogleAuthenticator(url: string | URL): TokenInfo[] {
59
61
p =>
60
62
new TokenInfo ( {
61
63
type : tokenTypeFromGoogle ( p . type ) ,
62
- name : nameFromGoogle ( p . name ) ,
64
+ name : nameFromGoogle ( p . issuer , p . name ) ,
63
65
secret : p . secret ,
64
66
secretEncoding : TokenSecretEncoding . Base64 ,
65
67
hashingAlgo : hashingAlgoFromGoogle ( p . algorithm ) ,
0 commit comments