Skip to content

Commit e67ec20

Browse files
author
Petteri Kautonen
authored
Merge pull request #46 from VPKSoft/fix_url_generation
Fix otpauth-URI generation makeOtpAuthKey function.
2 parents 99bcfad + fc5e287 commit e67ec20

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gauth-decode",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "A package to decode Google Authenticator export data",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

src/auth_exporter.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,15 @@ const decode = async (data: string) => {
124124
*/
125125
const makeOtpAuthKey = (otpData: OtpDataWithBase32, useBase32Secret: boolean = true) => {
126126
// TODO::Proper URI builder for OTP!
127-
return `otpauth://totp/${otpData.name}?secret=${useBase32Secret ? otpData.secretBase32 : otpData.secret}&issuer=${otpData.issuer}`;
127+
128+
// The name part should contain the issuer also, to fix this lets just change the issuer if they differ.
129+
let issuerFromName = otpData.issuer;
130+
const nameData = otpData.name.split(":");
131+
if (nameData.length === 2 && nameData[0] !== otpData.issuer) {
132+
issuerFromName = nameData[0];
133+
}
134+
135+
return `otpauth://totp/${otpData.name}?secret=${useBase32Secret ? otpData.secretBase32 : otpData.secret}&issuer=${issuerFromName}`;
128136
};
129137

130138
export type { OtpDataWithBase32 };

0 commit comments

Comments
 (0)