Skip to content

Instantly share code, notes, and snippets.

View MauRiEEZZZ's full-sized avatar
💭
Come on, Jump!

Maurice MJ de Jong MauRiEEZZZ

💭
Come on, Jump!
View GitHub Profile
import adal, uuid, time
from msrestazure.azure_active_directory import AADTokenCredentials
from azure.keyvault import KeyVaultClient
from msrestazure.azure_cloud import AZURE_PUBLIC_CLOUD
secret_name = 'ExamplePassword'
vault_uri = '<replace this text and brackets>'
tenant_id='<replace this text and brackets>'
cloud=AZURE_PUBLIC_CLOUD
authority_host_uri = cloud.endpoints.active_directory + \
'/' + tenant_id
keyvault_resource_uri = 'https://vault.azure.net'
client_id = '04b07795-8ddb-461a-bbee-02f9e1bf7b46'
context = adal.AuthenticationContext(authority_host_uri, api_version=None)
code = context.acquire_user_code(keyvault_resource_uri, client_id)
print(code['message'])
kv_token = context.acquire_token_with_device_code(keyvault_resource_uri, code, client_id)
kv_credential = AADTokenCredentials(kv_token, client_id)
keyvault_client = KeyVaultClient(kv_credential)
supersecret = keyvault_client.get_secret(vault_uri, secret_name, '')
print("The secret value is: "+ supersecret.value)
!pip install azure-identity --no-cache-dir --upgrade
!pip install azure-keyvault-secrets --no-cache-dir --upgrade
from azure.identity import DeviceCodeCredential
from azure.keyvault.secrets import SecretClient
secret_name = 'ExamplePassword'
vault_uri = '<replace this text and brackets>'
tenant_id='<replace this text and brackets>'
authority_host_uri = 'login.microsoftonline.com'
keyvault_resource_uri = 'https://vault.azure.net'
client_id = '04b07795-8ddb-461a-bbee-02f9e1bf7b46'
credential = DeviceCodeCredential(client_id, authority=authority_host_uri, tenant=tenant_id)
secret_client = SecretClient(vault_uri, credential)
supersecret = secret_client.get_secret(secret_name)
print("The secret value is: "+ supersecret.value)
az group create --name "ContosoResourceGroup" --location eastus