mirror of
https://github.com/LanceGin/jsotp.git
synced 2024-10-06 06:22:08 +08:00
upd: finish url_gen function
This commit is contained in:
parent
cf1ee2b8f0
commit
62c23f4208
13
src/hotp.js
13
src/hotp.js
@ -56,4 +56,17 @@ export class HOTP extends OTP {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a url with HOTP instance.
|
||||
*
|
||||
* @param {issuer}
|
||||
* @type {String}
|
||||
* @desc maybe it is the Service name
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
url_gen(issuer="") {
|
||||
return super.url_gen(issuer, "hotp");
|
||||
}
|
||||
}
|
16
src/otp.js
16
src/otp.js
@ -77,5 +77,21 @@ export class OTP {
|
||||
return str_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a url with TOTP or HOTP instance.
|
||||
*
|
||||
* @param {issuer}
|
||||
* @type {String}
|
||||
* @desc maybe it is the Service name
|
||||
*
|
||||
* @param {type}
|
||||
* @type {String}
|
||||
* @desc type of OTP instance
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
url_gen(issuer, type) {
|
||||
return `otpauth://${type}/SK?secret=${this.secret}&issuer=${issuer}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
13
src/totp.js
13
src/totp.js
@ -81,4 +81,17 @@ export class TOTP extends OTP {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a url with TOTP instance.
|
||||
*
|
||||
* @param {issuer}
|
||||
* @type {String}
|
||||
* @desc maybe it is the Service name
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
url_gen(issuer="") {
|
||||
return super.url_gen(issuer, "totp");
|
||||
}
|
||||
}
|
@ -17,5 +17,11 @@ describe('HOTP module test', function() {
|
||||
assert.equal(true, a.verify(a.at(0), 0));
|
||||
assert.equal(false, a.verify(a.at(0), 1));
|
||||
})
|
||||
});
|
||||
|
||||
describe('url_gen() function', function() {
|
||||
it("should return string", function() {
|
||||
assert.equal("string", typeof(a.url_gen()));
|
||||
})
|
||||
})
|
||||
});
|
||||
|
@ -16,5 +16,11 @@ describe('TOTP module test', function() {
|
||||
it("should verify the digit", function() {
|
||||
assert.equal(true, a.verify(a.now()));
|
||||
})
|
||||
});
|
||||
|
||||
describe('url_gen() function', function() {
|
||||
it("should return string", function() {
|
||||
assert.equal("string", typeof(a.url_gen()));
|
||||
})
|
||||
})
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user