Skip to content

Commit

Permalink
hand parsing url as chrome and safari is parsing it differently
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao Leonardo Pereira committed Jul 21, 2024
1 parent 98b9866 commit e0361f7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/app/models/account2FA.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@ export class Account2FA implements IAccount2FA {
}

static fromOTPAuthURL(url: string): Account2FA {
const urlObj = new URL(url);
const params = new URLSearchParams(urlObj.search);
//otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30

const pathComponents = urlObj.pathname.split('/').filter(e=>!!e).map(decodeURIComponent);
const urlObj = new URL(url);

if(!urlObj.protocol.startsWith('otpauth:')) {
throw new Error('Invalid OTPAuth URL');
}

const params = new URLSearchParams(urlObj.search)
const pathComponents = url.replace('otpauth://', '')
.split('/')
.filter(e=>!!e)
.map(decodeURIComponent)
.map(e=>e.replace(/\?.*/, ''))
const type = pathComponents[0];

console.log({url})
if (type !== 'totp') {
throw new Error('Only TOTP is supported');
Expand Down

0 comments on commit e0361f7

Please sign in to comment.