Skip to content

Commit 48fb2d9

Browse files
authored
Merge e18344a into 0df93b4
2 parents 0df93b4 + e18344a commit 48fb2d9

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

common/api-review/auth.api.md

+1
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ export interface TotpMultiFactorInfo extends MultiFactorInfo {
767767
export class TotpSecret {
768768
readonly codeIntervalSeconds: number;
769769
readonly codeLength: number;
770+
readonly enrollmentCompletionDeadline: string;
770771
// Warning: (ae-forgotten-export) The symbol "StartTotpMfaEnrollmentResponse" needs to be exported by the entry point index.d.ts
771772
//
772773
// @internal (undocumented)

packages/auth/demo/public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@
530530
</button>
531531
<br>
532532
<p hidden class="totp-text" id="totp-text"> Please scan the QR code below in a TOTP app </p>
533-
<br>
533+
<p hidden class="totp-deadline" id="totp-deadline"></p>
534534
<img hidden class="totp-qr-image" id="totp-qr-image"/>
535535
<br>
536536
<input type="text" id="enroll-mfa-totp-verification-code"

packages/auth/demo/public/style.css

+6
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ input + .form,
180180
.totp-text {
181181
font-family: 'Courier New', Courier;
182182
}
183+
184+
.totp-deadline {
185+
font-family: 'Courier New', Courier;
186+
color: #d9534f;
187+
}
188+
183189
.totp-qr-image {
184190
height: 120px;
185191
margin-right: 10px;

packages/auth/demo/src/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,27 @@ async function onStartEnrollWithTotpMultiFactor() {
675675
);
676676
const url = totpSecret.generateQrCodeUrl('test', 'testissuer');
677677
console.log('TOTP URL is ' + url);
678+
console.log(
679+
'Finalize sign in by ' + totpSecret.enrollmentCompletionDeadline
680+
);
681+
// display the numbr of seconds left to enroll.
682+
$('p.totp-deadline').show();
683+
var id = setInterval(function () {
684+
var deadline = new Date(totpSecret.enrollmentCompletionDeadline);
685+
var t = deadline - new Date().getTime();
686+
if (t < 0) {
687+
clearInterval(id);
688+
document.getElementById('totp-deadline').innerText =
689+
'TOTP enrollment expired!';
690+
} else {
691+
var minutes = Math.floor(t / (1000 * 60));
692+
var seconds = Math.floor((t % (60 * 1000)) / 1000);
693+
// accessing the field using $ does not work here.
694+
document.getElementById(
695+
'totp-deadline'
696+
).innerText = `Time left - ${minutes} minutes, ${seconds} seconds.`;
697+
}
698+
}, 1000);
678699
// Use the QRServer API documented at https://goqr.me/api/doc/
679700
const qrCodeUrl = `https://api.qrserver.com/v1/create-qr-code/?data=${url}&amp;size=30x30`;
680701
$('img.totp-qr-image').attr('src', qrCodeUrl).show();

packages/auth/src/mfa/assertions/totp.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -199,25 +199,27 @@ export class TotpSecret {
199199
* The interval (in seconds) when the OTP codes should change.
200200
*/
201201
readonly codeIntervalSeconds: number;
202-
// TODO(prameshj) - make this public after API review.
202+
/**
203+
* The timestamp(UTC string) by which TOTP enrollment should be completed.
204+
*/
203205
// This can be used by callers to show a countdown of when to enter OTP code by.
204-
private readonly finalizeEnrollmentBy: string;
206+
readonly enrollmentCompletionDeadline: string;
205207

206208
// The public members are declared outside the constructor so the docs can be generated.
207209
private constructor(
208210
secretKey: string,
209211
hashingAlgorithm: string,
210212
codeLength: number,
211213
codeIntervalSeconds: number,
212-
finalizeEnrollmentBy: string,
214+
enrollmentCompletionDeadline: string,
213215
private readonly sessionInfo: string,
214216
private readonly auth: AuthInternal
215217
) {
216218
this.secretKey = secretKey;
217219
this.hashingAlgorithm = hashingAlgorithm;
218220
this.codeLength = codeLength;
219221
this.codeIntervalSeconds = codeIntervalSeconds;
220-
this.finalizeEnrollmentBy = finalizeEnrollmentBy;
222+
this.enrollmentCompletionDeadline = enrollmentCompletionDeadline;
221223
}
222224

223225
/** @internal */

0 commit comments

Comments
 (0)