Skip to content

Expose enrollmentCompletionDeadline field in TotpSecret. #6870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/api-review/auth.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ export interface TotpMultiFactorInfo extends MultiFactorInfo {
export class TotpSecret {
readonly codeIntervalSeconds: number;
readonly codeLength: number;
readonly enrollmentCompletionDeadline: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't understand why it was changed to this instead of finalizeEnrollmentBy

Copy link
Contributor Author

@prameshj prameshj Dec 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still pending API review, but IMO enrollmentCompletionDeadline sounds slightly clearer. Modified the naming since users of SDK will now see this field name.

// Warning: (ae-forgotten-export) The symbol "StartTotpMfaEnrollmentResponse" needs to be exported by the entry point index.d.ts
//
// @internal (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/demo/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@
</button>
<br>
<p hidden class="totp-text" id="totp-text"> Please scan the QR code below in a TOTP app </p>
<br>
<p hidden class="totp-deadline" id="totp-deadline"></p>
<img hidden class="totp-qr-image" id="totp-qr-image"/>
<br>
<input type="text" id="enroll-mfa-totp-verification-code"
Expand Down
6 changes: 6 additions & 0 deletions packages/auth/demo/public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ input + .form,
.totp-text {
font-family: 'Courier New', Courier;
}

.totp-deadline {
font-family: 'Courier New', Courier;
color: #d9534f;
}

.totp-qr-image {
height: 120px;
margin-right: 10px;
Expand Down
21 changes: 21 additions & 0 deletions packages/auth/demo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,27 @@ async function onStartEnrollWithTotpMultiFactor() {
);
const url = totpSecret.generateQrCodeUrl('test', 'testissuer');
console.log('TOTP URL is ' + url);
console.log(
'Finalize sign in by ' + totpSecret.enrollmentCompletionDeadline
);
// display the numbr of seconds left to enroll.
$('p.totp-deadline').show();
var id = setInterval(function () {
var deadline = new Date(totpSecret.enrollmentCompletionDeadline);
var t = deadline - new Date().getTime();
if (t < 0) {
clearInterval(id);
document.getElementById('totp-deadline').innerText =
'TOTP enrollment expired!';
} else {
var minutes = Math.floor(t / (1000 * 60));
var seconds = Math.floor((t % (60 * 1000)) / 1000);
// accessing the field using $ does not work here.
document.getElementById(
'totp-deadline'
).innerText = `Time left - ${minutes} minutes, ${seconds} seconds.`;
}
}, 1000);
// Use the QRServer API documented at https://goqr.me/api/doc/
const qrCodeUrl = `https://api.qrserver.com/v1/create-qr-code/?data=${url}&amp;size=30x30`;
$('img.totp-qr-image').attr('src', qrCodeUrl).show();
Expand Down
10 changes: 6 additions & 4 deletions packages/auth/src/mfa/assertions/totp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,25 +199,27 @@ export class TotpSecret {
* The interval (in seconds) when the OTP codes should change.
*/
readonly codeIntervalSeconds: number;
// TODO(prameshj) - make this public after API review.
/**
* The timestamp(UTC string) by which TOTP enrollment should be completed.
*/
// This can be used by callers to show a countdown of when to enter OTP code by.
private readonly finalizeEnrollmentBy: string;
readonly enrollmentCompletionDeadline: string;

// The public members are declared outside the constructor so the docs can be generated.
private constructor(
secretKey: string,
hashingAlgorithm: string,
codeLength: number,
codeIntervalSeconds: number,
finalizeEnrollmentBy: string,
enrollmentCompletionDeadline: string,
private readonly sessionInfo: string,
private readonly auth: AuthInternal
) {
this.secretKey = secretKey;
this.hashingAlgorithm = hashingAlgorithm;
this.codeLength = codeLength;
this.codeIntervalSeconds = codeIntervalSeconds;
this.finalizeEnrollmentBy = finalizeEnrollmentBy;
this.enrollmentCompletionDeadline = enrollmentCompletionDeadline;
}

/** @internal */
Expand Down