Skip to content

Commit

Permalink
Merge pull request #46 from VPKSoft/fix_url_generation
Browse files Browse the repository at this point in the history
Fix otpauth-URI generation makeOtpAuthKey function.
  • Loading branch information
Petteri Kautonen authored Dec 28, 2023
2 parents 99bcfad + fc5e287 commit e67ec20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gauth-decode",
"version": "0.1.0",
"version": "0.1.1",
"description": "A package to decode Google Authenticator export data",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
10 changes: 9 additions & 1 deletion src/auth_exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,15 @@ const decode = async (data: string) => {
*/
const makeOtpAuthKey = (otpData: OtpDataWithBase32, useBase32Secret: boolean = true) => {
// TODO::Proper URI builder for OTP!
return `otpauth://totp/${otpData.name}?secret=${useBase32Secret ? otpData.secretBase32 : otpData.secret}&issuer=${otpData.issuer}`;

// The name part should contain the issuer also, to fix this lets just change the issuer if they differ.
let issuerFromName = otpData.issuer;
const nameData = otpData.name.split(":");
if (nameData.length === 2 && nameData[0] !== otpData.issuer) {
issuerFromName = nameData[0];
}

return `otpauth://totp/${otpData.name}?secret=${useBase32Secret ? otpData.secretBase32 : otpData.secret}&issuer=${issuerFromName}`;
};

export type { OtpDataWithBase32 };
Expand Down

0 comments on commit e67ec20

Please sign in to comment.