feat(iframe-app): Add Easy Auth detection and improve authentication flow#8754
feat(iframe-app): Add Easy Auth detection and improve authentication flow#8754ccastrotrejo merged 7 commits intomainfrom
Conversation
- Add isEasyAuthConfigured to AuthInformation interface to detect Easy Auth status - Return isEasyAuthConfigured: false when /.auth/me returns 404 (not configured) - Remove fallback to DEFAULT_IDENTITY_PROVIDERS - undefined means no sign-in required - Update IframeWrapper auth flow: - Easy Auth configured + no identity providers → show chat directly - Easy Auth configured + identity providers → show sign-in UI - No Easy Auth + apiKey → show chat - No Easy Auth + no apiKey → let it fail naturally - Update tests to reflect new authentication flow behavior
🤖 AI PR Validation ReportPR Review ResultsThank you for your submission! Here's detailed feedback on your PR title and body compliance:✅ PR Title
✅ Commit Type
✅ Risk Level
✅ What & Why
✅ Impact of Change
✅ Test Plan
|
| Section | Status | Recommendation |
|---|---|---|
| Title | ✅ | Keep as-is. |
| Commit Type | ✅ | Correct selection (feature). |
| Risk Level | ✅ | Medium is appropriate. |
| What & Why | ✅ | Clear and concise. |
| Impact of Change | ✅ | Good; consider adding a migration note. |
| Test Plan | ✅ | Matches diff; ensure CI e2e pass. |
| Contributors | Add contributors or a short "none" statement. | |
| Screenshots/Videos | N/A is acceptable; add visuals only if helpful. |
Final note: This PR passes the PR title/body checklist. The change set touches authentication flows and tests and the advised risk level is risk:medium, which matches the label in the PR. No additional risk escalation is necessary.
Please update the Contributors section (optional) and add a short migration/operational note in Impact if any downstream servers or deployments must explicitly inject window.IDENTITY_PROVIDERS now (this will help operators and reviewers). Once CI (unit + e2e) completes successfully, this PR is ready for review/merge. Thanks for the thorough description and comprehensive tests!
Last updated: Mon, 02 Feb 2026 15:28:40 GMT
|
📊 Coverage check completed. See workflow run for details. |
|
📊 Coverage check completed. See workflow run for details. |
- Handle 401, 403 as Easy Auth configured but not authenticated - Handle 302 (opaqueredirect) as Easy Auth configured but not authenticated - Add redirect: 'manual' to detect 302 without following redirect - Keep 404 as Easy Auth not configured - Update tests for new status code handling
…trotrejo/ChatEasyAuth
There was a problem hiding this comment.
Pull request overview
This PR implements Easy Auth detection in the iframe chat application to improve the authentication flow by distinguishing between Easy Auth not being configured versus Easy Auth being configured but the user not being authenticated.
Changes:
- Added
isEasyAuthConfiguredproperty toAuthInformationinterface to track Easy Auth configuration status - Updated
checkAuthStatusto detect Easy Auth configuration by analyzing different status codes (404 = not configured, 401/403/302 = configured but not authenticated) - Modified authentication flow in
IframeWrapperto skip login prompts when Easy Auth is not configured or when no identity providers are defined - Removed
DEFAULT_IDENTITY_PROVIDERSfallback to avoid showing unnecessary sign-in UI
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/iframe-app/src/lib/authHandler.ts | Added isEasyAuthConfigured property and detection logic based on status codes; added redirect: 'manual' to detect 302 redirects |
| apps/iframe-app/src/lib/tests/authHandler.test.ts | Added tests for different Easy Auth status codes (404, 401, 403, opaqueredirect); updated existing tests to include isEasyAuthConfigured |
| apps/iframe-app/src/components/IframeWrapper.tsx | Updated auth flow to check isEasyAuthConfigured and skip login when not configured or no providers defined; added dependency on props.identityProviders |
| apps/iframe-app/src/components/tests/IframeWrapper.test.tsx | Added tests for new auth flow scenarios and updated mock returns to include isEasyAuthConfigured |
| apps/iframe-app/src/components/tests/IframeWrapper.contextId.test.tsx | Updated mock to include isEasyAuthConfigured: true in the default return value |
| apps/iframe-app/src/lib/utils/config-parser.ts | Removed DEFAULT_IDENTITY_PROVIDERS constant and fallback logic; now returns undefined when not configured |
| apps/iframe-app/src/lib/utils/tests/config-parser.test.ts | Updated tests to expect undefined instead of default providers; updated test descriptions and comments |
Comments suppressed due to low confidence (1)
apps/iframe-app/src/components/IframeWrapper.tsx:127
- The catch block in IframeWrapper assumes that any error during checkAuthStatus means login is needed (setNeedsLogin(true)). However, this is inconsistent with the checkAuthStatus implementation which returns isEasyAuthConfigured: false for network errors.
When checkAuthStatus throws an error (network failure), it means Easy Auth status is unknown. The current implementation will show the login UI even when identity providers are not configured, which defeats the purpose of the Easy Auth detection.
Consider checking if identity providers are configured before showing login on errors, similar to the successful response handling. For example:
- If identity providers are configured, show login (current behavior)
- If identity providers are NOT configured, skip login and let it fail naturally
} catch (error) {
console.error('[Auth] Failed to check authentication status:', error);
setNeedsLogin(true);
|
📊 Coverage check completed. See workflow run for details. |
1 similar comment
|
📊 Coverage check completed. See workflow run for details. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
- Add JSDoc documentation for isEasyAuthConfigured property in AuthInformation - Remove redundant setIsCheckingAuth(false) call in IframeWrapper (rely on finally block) - Fix parseIdentityProviders to reject arrays (not valid Record format) - Add test coverage for 5xx server errors (500, 503) in checkAuthStatus - Update tests to expect correct behavior for array identity providers
|
📊 Coverage check completed. See workflow run for details. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
apps/iframe-app/src/components/IframeWrapper.tsx:126
- The catch block unconditionally sets needsLogin to true, which contradicts the new Easy Auth detection logic. When checkAuthStatus throws an exception (which returns isEasyAuthConfigured: false), the catch block should respect whether identity providers are configured before deciding to show login.
Currently, if checkAuthStatus throws an error (network failure, CORS issue, etc.), the catch block will show the login UI even when no identity providers are configured, defeating the purpose of this PR.
Consider checking if identity providers are configured before setting needsLogin to true in the catch block, similar to the logic in the try block.
} catch (error) {
console.error('[Auth] Failed to check authentication status:', error);
setNeedsLogin(true);
…ovider injection - Use HTML document interception to inject identity providers instead of addInitScript - Fix MOCK_IDENTITY_PROVIDERS to use signInEndpoint instead of loginPath - Use route.fallback() instead of route.continue() to allow route chaining - Add explicit waits and increase timeouts for popup events - Skip auth/API URLs in catch-all routes to prevent conflicts
|
📊 Coverage check completed. See workflow run for details. |
|
📊 Coverage check completed. See workflow run for details. |
Commit Type
Risk Level
What & Why
Implements Azure App Service Easy Auth detection in the iframe-app chat UI to provide a smarter authentication flow. Previously, the app would always show a login prompt with hardcoded default identity providers (Microsoft, Google, Facebook, GitHub), even when Easy Auth was not configured on the Logic App.
Problem
Solution
isEasyAuthConfiguredflag toAuthInformationinterface to distinguish between authentication statescheckAuthStatus()to detect Easy Auth configuration by interpreting HTTP status codes from/.auth/me:404→ Easy Auth is NOT configured401,403→ Easy Auth IS configured, user not authenticated302(opaqueredirect) → Easy Auth IS configured, redirect to loginredirect: 'manual'to fetch options to detect 302 redirects without following themDEFAULT_IDENTITY_PROVIDERSfallback - identity providers must now be explicitly configured viawindow.IDENTITY_PROVIDERSIframeWrapperto use the new detection logic and skip login UI when appropriateparseIdentityProviders()to reject arrays (not a validRecord<string, IdentityProvider>format)Impact of Change
AuthInformationinterface now includesisEasyAuthConfigured: booleanproperty. Identity providers are no longer injected by default.window.IDENTITY_PROVIDERSserver-side injection.Test Plan
Unit test scenarios covered:
checkAuthStatusreturnsisEasyAuthConfigured: falsewhen/.auth/mereturns 404checkAuthStatusreturnsisEasyAuthConfigured: truefor 401, 403, and 302 (opaqueredirect) responsescheckAuthStatusreturnsisEasyAuthConfigured: truewith error for 500/503 server errorsIframeWrapperskips login when Easy Auth is not configured (404)IframeWrapperskips login when Easy Auth is configured but no identity providers definedundefinedfor identity providers when not explicitly set (no fallback)E2E test improvements:
baseTestwith proper mocking setupFiles Changed
apps/iframe-app/src/lib/authHandler.tsisEasyAuthConfiguredtoAuthInformationinterface, enhanced status code handling withredirect: 'manual'apps/iframe-app/src/components/IframeWrapper.tsxprops.identityProvidersto dependency arrayapps/iframe-app/src/lib/utils/config-parser.tsDEFAULT_IDENTITY_PROVIDERSconstant and fallback, added array rejection inparseIdentityProviders()apps/iframe-app/src/lib/__tests__/authHandler.test.tsapps/iframe-app/src/components/__tests__/IframeWrapper.test.tsxapps/iframe-app/src/components/__tests__/IframeWrapper.contextId.test.tsxisEasyAuthConfiguredflagapps/iframe-app/src/lib/utils/__tests__/config-parser.test.tse2e/chatClient/fixtures/sse-fixtures.tse2e/chatClient/tests/features/authentication/auth-flow.spec.tse2e/chatClient/tests/features/authentication/login-prompt.spec.tsbaseTestwith proper identity provider injectionContributors
Screenshots/Videos
N/A - Logic change only, no visual changes