Skip to content

Commit

Permalink
add per-page timeout for passwordless auth
Browse files Browse the repository at this point in the history
  • Loading branch information
cfbao committed Oct 22, 2024
1 parent 26b6476 commit ff10229
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/D2L.Bmx/OktaAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ The provided Okta user '{providedLogin}' does not match the system configured pa
var sessionIdTcs = new TaskCompletionSource<string?>( TaskCreationOptions.RunContinuationsAsynchronously );
cancellationTokenSource.Token.Register( () => sessionIdTcs.TrySetCanceled() );

// cancel the task if we're stuck on a page for 3 seconds
using var pageTimeoutTimer = new System.Timers.Timer( TimeSpan.FromSeconds( 3 ) ) { AutoReset = false };
pageTimeoutTimer.Elapsed += ( _, _ ) => sessionIdTcs.TrySetCanceled();

using var page = await browser.NewPageAsync().WaitAsync( cancellationTokenSource.Token );
int attempt = 1;

Expand All @@ -163,6 +167,12 @@ The provided Okta user '{providedLogin}' does not match the system configured pa
return await sessionIdTcs.Task;

async Task OnPageLoadAsync() {
// reset the per-page timeout on every page load
lock( pageTimeoutTimer ) {
pageTimeoutTimer.Stop();
pageTimeoutTimer.Start();
}

var url = new Uri( page.Url );
if( url.Host == orgUrl.Host ) {
string title = await page.GetTitleAsync().WaitAsync( cancellationTokenSource.Token );
Expand Down

0 comments on commit ff10229

Please sign in to comment.