Skip to content

Conversation

@madhav-db
Copy link
Contributor

What type of PR is this?

Fixes token federation warnings that were appearing for users not using identity federation. Token federation is now opt-in and only enabled when identity_federation_client_id is explicitly provided.

  • Refactor
  • Feature
  • Bug Fix
  • Other

Description

How is this tested?

  • Unit tests
  • E2E Tests
  • Manually
  • N/A

Related Tickets & Documents

Copilot AI review requested due to automatic review settings November 19, 2025 06:01
@github-actions
Copy link

Thanks for your contribution! To satisfy the DCO policy in our contributing guide every commit message must include a sign-off message. One or more of your commits is missing this message. You can reword previous commit messages with an interactive rebase (git rebase -i main).

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes token federation warnings by making it opt-in and improving error handling. Previously, token federation was always enabled for all authentication methods, causing warnings for users who weren't using identity federation. Now, token federation is only enabled when identity_federation_client_id is explicitly provided.

Key Changes:

  • Token federation is now opt-in via the identity_federation_client_id parameter
  • Added custom exception classes for better error handling and categorization
  • Enhanced logging with appropriate levels (debug/info/warning) based on error type

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/databricks/sql/auth/auth.py Modified to only wrap providers with TokenFederationProvider when identity_federation_client_id is provided
src/databricks/sql/auth/token_federation.py Added custom exception classes and improved error handling with specific exceptions for different HTTP status codes
tests/unit/test_auth.py Updated tests to verify token federation is only enabled with identity_federation_client_id and reformatted some lines
tests/unit/test_token_federation.py Added tests for new exception types and fallback behavior on 404/401/403 errors

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +268 to +271
if response.status == 404:
raise TokenExchangeNotAvailableError(
"Token exchange endpoint not found. Token federation may not be enabled for this workspace."
)
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The error messages are hardcoded strings. Consider defining them as class constants (e.g., ERROR_MSG_404, ERROR_MSG_401_403) for better maintainability and consistency, especially since these messages are validated in tests.

Copilot uses AI. Check for mistakes.
@madhav-db madhav-db changed the title Fix token federation warnings by making it opt-in and improving error handling Fix token federation warnings by making it opt-in and improving error handling [Issue #702] Nov 21, 2025
@madhav-db
Copy link
Contributor Author

Fix for issue #702

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