How Client Secret Authentication Works
Load Configuration
The provider loads authentication configuration from either Terraform configuration or environment variables (
M365_TENANT_ID, M365_CLIENT_ID, M365_CLIENT_SECRET)Request Token
The provider constructs an OAuth 2.0 token request to Microsoft Entra ID’s token endpoint:
Validate Credentials
Microsoft Entra ID validates the client credentials by checking:
- Client ID exists
- Client secret is correct and not expired
- App has been granted the requested permissions
Prerequisites
- A Microsoft Entra ID tenant
- Permissions to create an app registration in your tenant
Setup
- Manual Setup
- Using Terraform
- Using PowerShell
Create App Registration
Add API Permissions
- Navigate to “API permissions” in your app registration
- Click “Add a permission” and select “Microsoft Graph”
- Choose “Application permissions” for automation scenarios
- Apply least privilege principles: Only add permissions specific to the resources you need to manage
- Click “Grant admin consent” for these permissions
Provider Configuration
- Environment Variables (Recommended)
- Terraform Configuration
The provider automatically reads values from environment variables if they’re not specified in the provider configuration.
HashiCorp Vault Integration
HashiCorp Vault provides a secure way to store and access secrets.Store Credentials in Vault
Retrieve with Vault Provider
Security Considerations
Troubleshooting
Authentication failed
Authentication failed
Verify the tenant ID, client ID, and client secret are correct. Check for typos and ensure the values haven’t been truncated.
Permission denied
Permission denied
Ensure you’ve granted admin consent for the required permissions in your app registration.
Secret expired
Secret expired
Check if your client secret has expired and create a new one if necessary. Set up alerts before expiration.
Insufficient permissions
Insufficient permissions
Your app registration needs appropriate Microsoft Graph permissions. Consult the provider documentation for the specific permissions required by each resource.
