fix(auth): handle OAuth scope claim as both string and list types#4594
Open
bogdanmariusc10 wants to merge 4 commits intomainfrom
Open
Conversation
Signed-off-by: Bogdan-Marius-Catanus <bogdan-marius.catanus@ibm.com>
Signed-off-by: Bogdan-Marius-Catanus <bogdan-marius.catanus@ibm.com>
Signed-off-by: Bogdan-Marius-Catanus <bogdan-marius.catanus@ibm.com>
…ter-oauth-list-object-has-no-attribute-split
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Related Issue
Closes #4593
Jira Issue: https://jsw.ibm.com/browse/ICACF-40
📝 Summary
Fixed OAuth token scope validation failure that caused "Failed to fetch tools after OAuth: 'list' object has no attribute 'split'" error when connecting to MCP servers (e.g., Gamma) that return OAuth scopes as a list instead of a space-separated string.
Root Cause: The code assumed OAuth
scope/scpclaims would always be strings, but some OAuth providers return them as lists, which is valid per OAuth 2.0 specifications.Solution: Updated scope handling in two critical locations to accept both string and list formats:
_normalize_scope())exchange_code_for_tokens())🏷️ Type of Change
🧪 Verification
make lintmake testmake coverageTest Results:
test_token_validation_service.py: 46 tests pass (including 5 new tests for list input)test_oauth_manager.py: 112 tests passtest_gateway_service_oauth_comprehensive.py: 29 tests pass✅ Checklist
make black isort pre-commit)📓 Notes
Files Changed
1.
mcpgateway/services/token_validation_service.py_normalize_scope()to handle bothstrandlistinputsscope_input: Anyinstead ofscope_str: str2.
mcpgateway/services/oauth_manager.pyexchange_code_for_tokens()to handle scope as string or list.split()store_tokens()always receivesList[str]3.
tests/unit/mcpgateway/services/test_token_validation_service.pytest_list_input_simple_scopestest_list_input_uri_prefixed_scopestest_empty_listtest_mixed_list_with_uri_and_simpletest_invalid_input_typeImpact