Skip to content

Commit

Permalink
Pop client_secret to protect pipeline (#36947)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyan99 authored Aug 20, 2024
1 parent 99bfd77 commit 8a6980c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def _run_pipeline(self, request: HttpRequest, **kwargs: Any) -> AccessToken:
# tenant_id is already part of `request` at this point
kwargs.pop("tenant_id", None)
kwargs.pop("claims", None)
kwargs.pop("client_secret", None)
enable_cae = kwargs.pop("enable_cae", False)
now = int(time.time())
response = self._pipeline.run(request, retry_on_methods=self._POST, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ async def _run_pipeline(self, request: HttpRequest, **kwargs) -> AccessToken:
# tenant_id is already part of `request` at this point
kwargs.pop("tenant_id", None)
kwargs.pop("claims", None)
kwargs.pop("client_secret", None)
enable_cae = kwargs.pop("enable_cae", False)
now = int(time.time())
response = await self._pipeline.run(request, retry_on_methods=self._POST, **kwargs)
Expand Down
3 changes: 3 additions & 0 deletions sdk/identity/azure-identity/tests/test_aad_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def send(request, **_):
client.obtain_token_by_authorization_code("scope", "code", "uri")
client.obtain_token_by_refresh_token("scope", "refresh token")

# obtain_token_by_refresh_token is client_secret safe
client.obtain_token_by_refresh_token("scope", "refresh token", client_secret="secret")

# authority can be configured via environment variable
with patch.dict("os.environ", {EnvironmentVariables.AZURE_AUTHORITY_HOST: authority}, clear=True):
client = AadClient(tenant_id=tenant_id, client_id="client id", transport=Mock(send=send))
Expand Down
3 changes: 3 additions & 0 deletions sdk/identity/azure-identity/tests/test_aad_client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ async def send(request, **_):
await client.obtain_token_by_authorization_code("scope", "code", "uri")
await client.obtain_token_by_refresh_token("scope", "refresh token")

# obtain_token_by_refresh_token is client_secret safe
client.obtain_token_by_refresh_token("scope", "refresh token", client_secret="secret")

# authority can be configured via environment variable
with patch.dict("os.environ", {EnvironmentVariables.AZURE_AUTHORITY_HOST: authority}, clear=True):
client = AadClient(tenant_id=tenant_id, client_id="client id", transport=Mock(send=send))
Expand Down

0 comments on commit 8a6980c

Please sign in to comment.