How Device Code Authentication Works
Display Code
The provider displays a message with:
- A unique code
- A URL where the code should be entered
Prerequisites
- A Microsoft Entra ID tenant
- Permissions to create an app registration in your tenant
Setup
Create App Registration
Configure Platform
- Set “Mobile and desktop applications” as platform type
- Add
https://login.microsoftonline.com/common/oauth2/nativeclientas a redirect URI
Provider Configuration
- Environment Variables (Recommended)
- Terraform Configuration
Usage Workflow
When you run Terraform with device code authentication, you’ll see a message similar to:Use Cases
Device code authentication is ideal for:CI/CD Pipelines
CI/CD pipelines with manual intervention
No Browser Environments
Environments without a web browser
Remote Terminals
Remote terminals or SSH sessions
Limited Redirection
Scenarios where redirection to a local web server isn’t possible
Security Considerations
Important Security Notes
- Device code authentication requires user interaction for each token acquisition
- The default token lifetime is one hour
- For automated processes, consider using client secret, certificate, or OIDC authentication instead
- This authentication method grants permissions based on the authenticated user’s privileges
Troubleshooting
Code expired
Code expired
If you don’t authenticate within the time limit (typically 15 minutes), you’ll need to restart the process.
Permission denied
Permission denied
Ensure you’ve granted admin consent for the required permissions in your app registration.
No code displayed
No code displayed
Verify your terminal can display output from the provider. Check that stdout is not being redirected.
