File tree 5 files changed +35
-5
lines changed
5 files changed +35
-5
lines changed Original file line number Diff line number Diff line change @@ -767,6 +767,7 @@ export interface TotpMultiFactorInfo extends MultiFactorInfo {
767
767
export class TotpSecret {
768
768
readonly codeIntervalSeconds: number ;
769
769
readonly codeLength: number ;
770
+ readonly enrollmentCompletionDeadline: string ;
770
771
// Warning: (ae-forgotten-export) The symbol "StartTotpMfaEnrollmentResponse" needs to be exported by the entry point index.d.ts
771
772
//
772
773
// @internal (undocumented)
Original file line number Diff line number Diff line change 534
534
</ button >
535
535
< br >
536
536
< p hidden class ="totp-text " id ="totp-text "> Please scan the QR code below in a TOTP app </ p >
537
- < br >
537
+ < p hidden class =" totp-deadline " id =" totp-deadline " > </ p >
538
538
< img hidden class ="totp-qr-image " id ="totp-qr-image "/>
539
539
< br >
540
540
< input type ="text " id ="enroll-mfa-totp-verification-code "
Original file line number Diff line number Diff line change @@ -180,6 +180,12 @@ input + .form,
180
180
.totp-text {
181
181
font-family : 'Courier New' , Courier;
182
182
}
183
+
184
+ .totp-deadline {
185
+ font-family : 'Courier New' , Courier;
186
+ color : # d9534f ;
187
+ }
188
+
183
189
.totp-qr-image {
184
190
height : 120px ;
185
191
margin-right : 10px ;
Original file line number Diff line number Diff line change @@ -710,6 +710,27 @@ async function onStartEnrollWithTotpMultiFactor() {
710
710
) ;
711
711
const url = totpSecret . generateQrCodeUrl ( 'test' , 'testissuer' ) ;
712
712
console . log ( 'TOTP URL is ' + url ) ;
713
+ console . log (
714
+ 'Finalize sign in by ' + totpSecret . enrollmentCompletionDeadline
715
+ ) ;
716
+ // display the numbr of seconds left to enroll.
717
+ $ ( 'p.totp-deadline' ) . show ( ) ;
718
+ var id = setInterval ( function ( ) {
719
+ var deadline = new Date ( totpSecret . enrollmentCompletionDeadline ) ;
720
+ var t = deadline - new Date ( ) . getTime ( ) ;
721
+ if ( t < 0 ) {
722
+ clearInterval ( id ) ;
723
+ document . getElementById ( 'totp-deadline' ) . innerText =
724
+ 'TOTP enrollment expired!' ;
725
+ } else {
726
+ var minutes = Math . floor ( t / ( 1000 * 60 ) ) ;
727
+ var seconds = Math . floor ( ( t % ( 60 * 1000 ) ) / 1000 ) ;
728
+ // accessing the field using $ does not work here.
729
+ document . getElementById (
730
+ 'totp-deadline'
731
+ ) . innerText = `Time left - ${ minutes } minutes, ${ seconds } seconds.` ;
732
+ }
733
+ } , 1000 ) ;
713
734
// Use the QRServer API documented at https://goqr.me/api/doc/
714
735
const qrCodeUrl = `https://api.qrserver.com/v1/create-qr-code/?data=${ url } &size=30x30` ;
715
736
$ ( 'img.totp-qr-image' ) . attr ( 'src' , qrCodeUrl ) . show ( ) ;
Original file line number Diff line number Diff line change @@ -199,25 +199,27 @@ export class TotpSecret {
199
199
* The interval (in seconds) when the OTP codes should change.
200
200
*/
201
201
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
+ */
203
205
// 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 ;
205
207
206
208
// The public members are declared outside the constructor so the docs can be generated.
207
209
private constructor (
208
210
secretKey : string ,
209
211
hashingAlgorithm : string ,
210
212
codeLength : number ,
211
213
codeIntervalSeconds : number ,
212
- finalizeEnrollmentBy : string ,
214
+ enrollmentCompletionDeadline : string ,
213
215
private readonly sessionInfo : string ,
214
216
private readonly auth : AuthInternal
215
217
) {
216
218
this . secretKey = secretKey ;
217
219
this . hashingAlgorithm = hashingAlgorithm ;
218
220
this . codeLength = codeLength ;
219
221
this . codeIntervalSeconds = codeIntervalSeconds ;
220
- this . finalizeEnrollmentBy = finalizeEnrollmentBy ;
222
+ this . enrollmentCompletionDeadline = enrollmentCompletionDeadline ;
221
223
}
222
224
223
225
/** @internal */
You can’t perform that action at this time.
0 commit comments