-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix #3845 #3847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix #3845 #3847
Changes from all commits
006d547
b6cb922
5e7effb
a4fb713
f339c50
752d42d
4636a5b
9e8d85d
428cd57
facc6f4
962dcde
2e01565
65c40e5
adb85b7
63830a6
d6a049d
ee9b052
34ae26a
672f65c
63e3691
a9ea483
be56163
6ed98e0
363c2e1
e1764f6
59307d4
fbec565
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,11 +7,6 @@ | |
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
@@ -22,6 +17,7 @@ | |
| from .auth_schemes import AuthSchemeType | ||
| from .auth_schemes import OpenIdConnectWithConfig | ||
| from .auth_tool import AuthConfig | ||
| from .credential_manager import CredentialManager | ||
| from .exchanger.oauth2_credential_exchanger import OAuth2CredentialExchanger | ||
|
|
||
| if TYPE_CHECKING: | ||
|
|
@@ -48,10 +44,13 @@ async def exchange_auth_token( | |
| self, | ||
| ) -> AuthCredential: | ||
| exchanger = OAuth2CredentialExchanger() | ||
| exchange_result = await exchanger.exchange( | ||
| self.auth_config.exchanged_auth_credential, self.auth_config.auth_scheme | ||
| ) | ||
| return exchange_result.credential | ||
|
|
||
| # Restore secret if needed | ||
| credential = self.auth_config.exchanged_auth_credential | ||
|
|
||
| with CredentialManager.restore_client_secret(credential): | ||
| res = await exchanger.exchange(credential, self.auth_config.auth_scheme) | ||
| return res.credential | ||
|
|
||
| async def parse_and_store_auth_response(self, state: State) -> None: | ||
|
|
||
|
|
@@ -183,21 +182,25 @@ def generate_auth_uri( | |
| ) | ||
| scopes = list(scopes.keys()) | ||
|
|
||
| client = OAuth2Session( | ||
| auth_credential.oauth2.client_id, | ||
| auth_credential.oauth2.client_secret, | ||
| scope=" ".join(scopes), | ||
| redirect_uri=auth_credential.oauth2.redirect_uri, | ||
| ) | ||
| params = { | ||
| "access_type": "offline", | ||
| "prompt": "consent", | ||
| } | ||
| if auth_credential.oauth2.audience: | ||
| params["audience"] = auth_credential.oauth2.audience | ||
| uri, state = client.create_authorization_url( | ||
| url=authorization_endpoint, **params | ||
| ) | ||
| client_id = auth_credential.oauth2.client_id | ||
|
|
||
| with CredentialManager.restore_client_secret(auth_credential): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the |
||
| client_secret = auth_credential.oauth2.client_secret | ||
| client = OAuth2Session( | ||
| client_id, | ||
| client_secret, | ||
| scope=" ".join(scopes), | ||
| redirect_uri=auth_credential.oauth2.redirect_uri, | ||
| ) | ||
| params = { | ||
| "access_type": "offline", | ||
| "prompt": "consent", | ||
| } | ||
| if auth_credential.oauth2.audience: | ||
| params["audience"] = auth_credential.oauth2.audience | ||
| uri, state = client.create_authorization_url( | ||
| url=authorization_endpoint, **params | ||
| ) | ||
|
|
||
| exchanged_auth_credential = auth_credential.model_copy(deep=True) | ||
| exchanged_auth_credential.oauth2.auth_uri = uri | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
credentialobject here isself.auth_config.exchanged_auth_credential. If theAuthHandlerinstance is initialized with the originalauth_configobject, andCredentialManagerlater deep copies thisauth_configin its__init__method, thenself.auth_config.exchanged_auth_credentialinAuthHandlerwill still refer to the original credential object, not the deep-copied one managed byCredentialManager. Consequently, callingCredentialManager.restore_client_secret(credential)might not operate on the correct, managed credential object, potentially bypassing the intended secret management or leading to unexpected behavior. Consider ensuring thatAuthHandleralways operates on theauth_configobject thatCredentialManageris actively managing, or retrieve the managed credential fromCredentialManagerdirectly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you address this.