-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Identity] Allow use of client assertion in OBO cred (#35812)
The new kwarg `client_assertion_func` was added to allow passing in client assertion callbacks to OBO credential. Signed-off-by: Paul Van Eck <[email protected]>
- Loading branch information
Showing
9 changed files
with
229 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
43 changes: 43 additions & 0 deletions
43
sdk/identity/azure-identity/samples/on_behalf_of_client_assertion.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
""" | ||
FILE: on_behalf_of_client_assertion.py | ||
DESCRIPTION: | ||
This sample demonstrates the use of OnBehalfOfCredential to authenticate the Key Vault SecretClient using a managed | ||
identity as the client assertion. More information about the On-Behalf-Of flow can be found here: | ||
https://learn.microsoft.com/entra/identity-platform/v2-oauth2-on-behalf-of-flow. | ||
USAGE: | ||
python on_behalf_of_client_assertion.py | ||
**Note** - This sample requires the `azure-keyvault-secrets` package. | ||
""" | ||
# [START obo_client_assertion] | ||
from azure.identity import OnBehalfOfCredential, ManagedIdentityCredential | ||
from azure.keyvault.secrets import SecretClient | ||
|
||
|
||
# Replace the following variables with your own values. | ||
tenant_id = "<tenant_id>" | ||
client_id = "<client_id>" | ||
user_assertion = "<user_assertion>" | ||
|
||
managed_identity_credential = ManagedIdentityCredential() | ||
|
||
|
||
def get_managed_identity_token() -> str: | ||
# This function should return an access token obtained from a managed identity. | ||
access_token = managed_identity_credential.get_token("api://AzureADTokenExchange") | ||
return access_token.token | ||
|
||
|
||
credential = OnBehalfOfCredential( | ||
tenant_id=tenant_id, | ||
client_id=client_id, | ||
user_assertion=user_assertion, | ||
client_assertion_func=get_managed_identity_token, | ||
) | ||
|
||
client = SecretClient(vault_url="https://<your-key-vault-name>.vault.azure.net/", credential=credential) | ||
# [END obo_client_assertion] |
This file contains 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
Oops, something went wrong.