@@ -45,41 +45,64 @@ def create_func_docstring(description: str, params: Sequence[ParameterSchema]) -
45
45
46
46
47
47
def identify_required_authn_params (
48
- req_authn_params : Mapping [str , list [str ]], auth_service_names : Iterable [str ]
49
- ) -> tuple [dict [str , list [str ]], set [str ]]:
48
+ req_authn_params : Mapping [str , list [str ]],
49
+ req_authz_tokens : list [str ],
50
+ auth_service_names : Iterable [str ],
51
+ ) -> tuple [dict [str , list [str ]], list [str ], set [str ]]:
50
52
"""
51
- Identifies authentication parameters that are still required; because they
52
- are not covered by the provided `auth_service_names`, and also returns a
53
- set of all authentication services that were found to be matching.
53
+ Identifies authentication parameters and authorization tokens that are still
54
+ required because they are not covered by the provided `auth_service_names`.
55
+ Also returns a set of all authentication/authorization services from
56
+ `auth_service_names` that were found to be matching.
54
57
55
- Args:
56
- req_authn_params: A mapping of parameter names to lists of required
57
- authentication services.
58
- auth_service_names: An iterable of authentication service names for which
59
- token getters are available.
58
+ Args:
59
+ req_authn_params: A mapping of parameter names to lists of required
60
+ authentication services for those parameters.
61
+ req_authz_tokens: A list of strings representing all authorization
62
+ tokens that are required to invoke the current tool.
63
+ auth_service_names: An iterable of authentication/authorization service
64
+ names for which token getters are available.
60
65
61
66
Returns:
62
67
A tuple containing:
63
68
- A new dictionary representing the subset of required
64
69
authentication parameters that are not covered by the provided
65
70
`auth_service_names`.
66
- - A list of authentication service names from `auth_service_names`
67
- that were found to satisfy at least one parameter's requirements.
71
+ - A list of required authorization tokens if no service name in
72
+ `auth_service_names` matches any token in `req_authz_tokens`. If
73
+ any match is found, this list is empty.
74
+ - A set of service names from `auth_service_names` that were found
75
+ to satisfy at least one authentication parameter's requirements or
76
+ matched one of the `req_authz_tokens`.
68
77
"""
69
- required_params : dict [str , list [str ]] = {}
78
+ required_authn_params : dict [str , list [str ]] = {}
70
79
used_services : set [str ] = set ()
71
80
81
+ # find which of the required authn params are covered by available services.
72
82
for param , services in req_authn_params .items ():
83
+
73
84
# if we don't have a token_getter for any of the services required by the param,
74
85
# the param is still required
75
- matched_services = [s for s in services if s in auth_service_names ]
86
+ matched_authn_services = [s for s in services if s in auth_service_names ]
76
87
77
- if matched_services :
78
- used_services .update (matched_services )
88
+ if matched_authn_services :
89
+ used_services .update (matched_authn_services )
79
90
else :
80
- required_params [param ] = services
91
+ required_authn_params [param ] = services
92
+
93
+ # find which of the required authz tokens are covered by available services.
94
+ matched_authz_services = [s for s in auth_service_names if s in req_authz_tokens ]
95
+ required_authz_tokens : list [str ] = []
96
+
97
+ # If a match is found, authorization is met (no remaining required tokens).
98
+ # Otherwise, all `req_authz_tokens` are still required. (Handles empty
99
+ # `req_authz_tokens` correctly, resulting in no required tokens).
100
+ if matched_authz_services :
101
+ used_services .update (matched_authz_services )
102
+ else :
103
+ required_authz_tokens = req_authz_tokens
81
104
82
- return required_params , used_services
105
+ return required_authn_params , required_authz_tokens , used_services
83
106
84
107
85
108
def params_to_pydantic_model (
0 commit comments