fix all them tests
This commit is contained in:
@@ -482,6 +482,12 @@ def handle_auth_callback(
|
||||
)
|
||||
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
|
||||
|
||||
# Allow partial scope grants without raising an exception.
|
||||
# When users decline some scopes on Google's consent screen,
|
||||
# oauthlib raises because the granted scopes differ from requested.
|
||||
if "OAUTHLIB_RELAX_TOKEN_SCOPE" not in os.environ:
|
||||
os.environ["OAUTHLIB_RELAX_TOKEN_SCOPE"] = "1"
|
||||
|
||||
store = get_oauth21_session_store()
|
||||
parsed_response = urlparse(authorization_response)
|
||||
state_values = parse_qs(parsed_response.query).get("state")
|
||||
@@ -504,6 +510,27 @@ def handle_auth_callback(
|
||||
credentials = flow.credentials
|
||||
logger.info("Successfully exchanged authorization code for tokens.")
|
||||
|
||||
# Handle partial OAuth grants: if the user declined some scopes on
|
||||
# Google's consent screen, credentials.granted_scopes contains only
|
||||
# what was actually authorized. Store those instead of the inflated
|
||||
# requested scopes so that refresh() sends the correct scope set.
|
||||
granted = getattr(credentials, "granted_scopes", None)
|
||||
if granted and set(granted) != set(credentials.scopes or []):
|
||||
logger.warning(
|
||||
"Partial OAuth grant detected. Requested: %s, Granted: %s",
|
||||
credentials.scopes,
|
||||
granted,
|
||||
)
|
||||
credentials = Credentials(
|
||||
token=credentials.token,
|
||||
refresh_token=credentials.refresh_token,
|
||||
token_uri=credentials.token_uri,
|
||||
client_id=credentials.client_id,
|
||||
client_secret=credentials.client_secret,
|
||||
scopes=list(granted),
|
||||
expiry=credentials.expiry,
|
||||
)
|
||||
|
||||
# Get user info to determine user_id (using email here)
|
||||
user_info = get_user_info(credentials)
|
||||
if not user_info or "email" not in user_info:
|
||||
|
||||
@@ -291,6 +291,24 @@ def get_scopes_for_tools(enabled_tools=None):
|
||||
Returns:
|
||||
List of unique scopes for the enabled tools plus base scopes.
|
||||
"""
|
||||
# Granular permissions mode overrides both full and read-only scope maps.
|
||||
# Lazy import with guard to avoid circular dependency during module init
|
||||
# (SCOPES = get_scopes_for_tools() runs at import time before auth.permissions
|
||||
# is fully loaded, but permissions mode is never active at that point).
|
||||
try:
|
||||
from auth.permissions import is_permissions_mode, get_all_permission_scopes
|
||||
|
||||
if is_permissions_mode():
|
||||
scopes = BASE_SCOPES.copy()
|
||||
scopes.extend(get_all_permission_scopes())
|
||||
logger.debug(
|
||||
"Generated scopes from granular permissions: %d unique scopes",
|
||||
len(set(scopes)),
|
||||
)
|
||||
return list(set(scopes))
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
if enabled_tools is None:
|
||||
# Default behavior - return all scopes
|
||||
enabled_tools = TOOL_SCOPES_MAP.keys()
|
||||
|
||||
Reference in New Issue
Block a user