Skip to content

Add timeout mechanism to device code flow polling using expires_in - #6

Closed
adamLiveware with Copilot wants to merge 3 commits into
device-code-flow-bulk-login-15901970604348367866from
copilot/sub-pr-1
Closed

Add timeout mechanism to device code flow polling using expires_in#6
adamLiveware with Copilot wants to merge 3 commits into
device-code-flow-bulk-login-15901970604348367866from
copilot/sub-pr-1

Conversation

Copilot AI commented Jan 6, 2026

Copy link
Copy Markdown

Device code flow polling continued indefinitely if users never completed authentication. OAuth2 device code responses include expires_in (typically 900s) which should terminate polling.

Changes

  • D4PDeviceAuthHelper.codeunit.al: Extract expires_in from device code response, default to 900s if missing
  • D4PBulkDeviceLogin.page.al: Pass expiresIn through to JavaScript control
  • D4PBulkLoginControl.controladdin.al: Add ExpiresIn parameter to StartLoginProcess signature
  • Script.js:
    • Track timeouts in pollTimeouts object alongside pollIntervals
    • setTimeout() stops polling after expiration, shows "Login timed out. The code has expired."
    • Re-enables login button with "Try Again" text
    • Clear both interval and timeout on successful auth
// Before: polling continues forever
pollIntervals[tenantId] = setInterval(function() {
    Microsoft.Dynamics.NAV.InvokeExtensibilityMethod('PollToken', [...]);
}, 5000);

// After: auto-terminate after expires_in
pollTimeouts[tenantId] = setTimeout(function() {
    clearInterval(pollIntervals[tenantId]);
    document.getElementById('status-message').innerText = 'Login timed out. The code has expired.';
}, expiresInMs);

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 6, 2026 10:02
Co-authored-by: adamLiveware <25444589+adamLiveware@users.noreply.github.com>
Co-authored-by: adamLiveware <25444589+adamLiveware@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on device code flow authentication and bulk login Add timeout mechanism to device code flow polling using expires_in Jan 6, 2026
Copilot AI requested a review from adamLiveware January 6, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants