/vibe:ghcopilot-instr-dataverse-python-authentication-securityfrom vibe
Provides guidance on authentication and security patterns for the Dataverse SDK for Python, including credential types like InteractiveBrowserCredential and DefaultAzureCredential.
Ships in vibe. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Based on official Microsoft Azure SDK authentication documentation and Dataverse SDK best practices.
The Dataverse SDK for Python uses Azure Identity credentials for token-based authentication. This approach follows the principle of least privilege and works across local development, cloud deployment, and on-premises environments.
Advantages over connection strings:
Use for: Developer workstations during local development.
from azure.identity import InteractiveBrowserCredential
from PowerPlatform.Dataverse.client import DataverseClient
# Opens browser for authentication
credential = InteractiveBrowserCredential()
client = DataverseClient(
base_url="https://myorg.crm.dynamics.com",
credential=credential
)
# First use prompts for sign-in; subsequent calls use cached token
records = client.get("account")
When to use:
Use for: Apps that run in multiple environments (dev → test → production).
from azure.identity import DefaultAzureCredential
from PowerPlatform.Dataverse.client import DataverseClient
# Attempts credentials in this order:
# 1. Environment variables (app service principal)
# 2. Azure CLI credentials (local development)
# 3. Azure PowerShell credentials (local development)
# 4. Managed identity (when running in Azure)
credential = DefaultAzureCredential()
client = DataverseClient(
base_url="https://myorg.crm.dynamics.com",
credential=credential
)
records = client.get("account")
Advantages:
Credential chain:
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET)az login)Connect-AzAccount)Use for: Unattended authentication (scheduled jobs, scripts, on-premises services).
from azure.identity import ClientSecretCredential
from PowerPlatform.Dataverse.client import DataverseClient
import os
credential = ClientSecretCredential(
tenant_id=os.environ["AZURE_TENANT_ID"],
client_id=os.environ["AZURE_CLIENT_ID"],
client_secret=os.environ["AZURE_CLIENT_SECRET"]
)
client = DataverseClient(
base_url="https://myorg.crm.dynamics.com",
credential=credential
)
records = client.get("account")
Setup steps:
Security concerns:
Use for: Apps hosted in Azure (App Service, Azure Functions, AKS, VMs).
from azure.identity import ManagedIdentityCredential
from PowerPlatform.Dataverse.client import DataverseClient
# No secrets needed - Azure manages identity
credential = ManagedIdentityCredential()
client = DataverseClient(
base_url="https://myorg.crm.dynamics.com",
credential=credential
)
records = client.get("account")
Benefits:
Setup:
# .env file (git-ignored)
DATAVERSE_URL=https://myorg-dev.crm.dynamics.com
# Python code
import os
from azure.identity import DefaultAzureCredential
from PowerPlatform.Dataverse.client import DataverseClient
# Uses your Azure CLI credentials
credential = DefaultAzureCredential()
client = DataverseClient(
base_url=os.environ["DATAVERSE_URL"],
credential=credential
)
Setup: az login with your developer account
from azure.identity import ManagedIdentityCredential
from PowerPlatform.Dataverse.client import DataverseClient
# Automatically uses managed identity
credential = ManagedIdentityCredential()
client = DataverseClient(
base_url="https://myorg.crm.dynamics.com",
credential=credential
)
Setup: Enable managed identity in App Service, grant permissions in Dataverse
import os
from azure.identity import ClientSecretCredential
from PowerPlatform.Dataverse.client import DataverseClient
credential = ClientSecretCredential(
tenant_id=os.environ["AZURE_TENANT_ID"],
client_id=os.environ["AZURE_CLIENT_ID"],
client_secret=os.environ["AZURE_CLIENT_SECRET"]
)
client = DataverseClient(
base_url="https://myorg.crm.dynamics.com",
credential=credential
)
Setup: Create service principal, store credentials securely, grant Dataverse permissions
from PowerPlatform.Dataverse.core.config import DataverseConfig
from azure.identity import DefaultAzureCredential
from PowerPlatform.Dataverse.client import DataverseClient
cfg = DataverseConfig()
cfg.logging_enable = True # Enable detailed logging
client = DataverseClient(
base_url="https://myorg.crm.dynamics.com",
credential=DefaultAzureCredential(),
config=cfg
)
from PowerPlatform.Dataverse.core.config import DataverseConfig
cfg = DataverseConfig()
# Timeout settings
cfg.http_timeout = 30 # Request timeout in seconds
# Retry configuration
cfg.http_retries = 3 # Number of retry attempts
cfg.http_backoff = 1 # Initial backoff in seconds
# Connection reuse
cfg.connection_timeout = 5 # Connection timeout
client = DataverseClient(
base_url="https://myorg.crm.dynamics.com",
credential=credential,
config=cfg
)
# ❌ BAD - Don't do this!
credential = ClientSecretCredential(
tenant_id="your-tenant-id",
client_id="your-client-id",
client_secret="your-secret-key" # EXPOSED!
)
# ✅ GOOD - Use environment variables
import os
credential = ClientSecretCredential(
tenant_id=os.environ["AZURE_TENANT_ID"],
client_id=os.environ["AZURE_CLIENT_ID"],
client_secret=os.environ["AZURE_CLIENT_SECRET"]
)
Development:
# .env file (git-ignored)
AZURE_TENANT_ID=your-tenant-id
AZURE_CLIENT_ID=your-client-id
AZURE_CLIENT_SECRET=your-secret-key
Production:
from azure.keyvault.secrets import SecretClient
from azure.identity import DefaultAzureCredential
# Retrieve secrets from Azure Key Vault
credential = DefaultAzureCredential()
client = SecretClient(
vault_url="https://mykeyvault.vault.azure.net",
credential=credential
)
secret = client.get_secret("dataverse-client-secret")
# Grant minimal permissions:
# - Only read if app only reads
# - Only specific tables if possible
# - Time-limit credentials (auto-rotation)
# - Use managed identity instead of shared secrets
import logging
logger = logging.getLogger("dataverse_auth")
try:
client = DataverseClient(
base_url="https://myorg.crm.dynamics.com",
credential=credential
)
logger.info("Successfully authenticated to Dataverse")
except Exception as e:
logger.error(f"Authentication failed: {e}")
raise
from azure.core.exceptions import ClientAuthenticationError
import time
def create_with_auth_retry(client, table_name, payload, max_retries=2):
"""Create record, retrying if token expired."""
for attempt in range(max_retries):
try:
return client.create(table_name, payload)
except ClientAuthenticationError:
if attempt < max_retries - 1:
logger.warning("Token expired, retrying...")
time.sleep(1)
else:
raise
from azure.identity import DefaultAzureCredential
from PowerPlatform.Dataverse.client import DataverseClient
def get_client_for_tenant(tenant_id: str) -> DataverseClient:
"""Get DataverseClient for specific tenant."""
credential = DefaultAzureCredential()
# Dataverse URL contains tenant-specific org
base_url = f"https://{get_org_for_tenant(tenant_id)}.crm.dynamics.com"
return DataverseClient(
base_url=base_url,
credential=credential
)
def get_org_for_tenant(tenant_id: str) -> str:
"""Map tenant to Dataverse organization."""
# Implementation depends on your multi-tenant strategy
# Could be database lookup, configuration, etc.
pass
try:
client.get("account")
except DataverseError as e:
if e.status_code == 403:
print("User/app lacks Dataverse permissions")
print("Ensure Dataverse security role is assigned")
# Check credential source
from azure.identity import DefaultAzureCredential
try:
cred = DefaultAzureCredential(exclude_cli_credential=False,
exclude_powershell_credential=False)
# Force re-authentication
import subprocess
subprocess.run(["az", "login"])
except Exception as e:
print(f"Authentication failed: {e}")
# Verify tenant ID
import json
from azure.identity import DefaultAzureCredential
credential = DefaultAzureCredential()
token = credential.get_token("https://dataverse.dynamics.com/.default")
# Decode token to verify tenant
import base64
payload = base64.b64decode(token.token.split('.')[1] + '==')
claims = json.loads(payload)
print(f"Token tenant: {claims.get('tid')}")
Azure Identity handles token refresh automatically:
# Tokens are cached and refreshed automatically
credential = DefaultAzureCredential()
# First call acquires token
client.get("account")
# Subsequent calls reuse cached token
client.get("contact")
# If token expires, SDK automatically refreshes
class DataverseSession:
"""Manages DataverseClient lifecycle."""
def __init__(self, base_url: str):
from azure.identity import DefaultAzureCredential
self.client = DataverseClient(
base_url=base_url,
credential=DefaultAzureCredential()
)
def __enter__(self):
return self.client
def __exit__(self, exc_type, exc_val, exc_tb):
# Cleanup if needed
pass
# Usage
with DataverseSession("https://myorg.crm.dynamics.com") as client:
records = client.get("account")
User's Dataverse security role determines accessible records:
from azure.identity import InteractiveBrowserCredential
from PowerPlatform.Dataverse.client import DataverseClient
# Each user gets client with their credentials
def get_user_client(user_username: str) -> DataverseClient:
# User must already be authenticated
credential = InteractiveBrowserCredential()
client = DataverseClient(
base_url="https://myorg.crm.dynamics.com",
credential=credential
)
# User only sees records they have access to
return client
Assign minimal required roles:
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
dataverse, azure-identity, authentication, security-patterns, python-sdk
5,304 skills in this plugin
/3d-pipelineChoose a 3D generation or reconstruction pipeline given input type, output format, and use case. Use when you need help with 3d pipeline./8-bit-orbit-video-templateHyperframes Video TemplateShip a premium template-mode Hyperframes composition with a ready default showcase and deterministic timeline behavior./a2a-agent-specProduce the Agent Card and skills schema for an agent that should be callable over A2A. Use when you need help with a2a agent spec.npx claudepluginhub anubhavg-icpl/vibe --plugin vibeOther plugins' skills for the same job