5.5 KiB
Microsoft Entra ID Setup Guide
This guide provides step-by-step instructions for setting up Microsoft Entra ID (formerly Azure Active Directory) authentication for the PDF Renamer web application.
Prerequisites
- An Azure subscription
- Administrative access to Azure Active Directory
- The PDF Renamer application code
Step 1: Access Azure Portal
- Open your web browser and navigate to Azure Portal
- Sign in with your Azure account credentials
Step 2: Navigate to App Registrations
- In the Azure Portal, search for "Azure Active Directory" in the search bar
- Click on "Azure Active Directory" from the results
- In the left sidebar, click on "App registrations"
- Click on "New registration" at the top
Step 3: Register the Application
-
Name: Enter a descriptive name for your app, e.g., "PDF Renamer Web App"
-
Supported account types: Select "Accounts in this organizational directory only (Single tenant)"
-
Redirect URI:
- Platform: Web
- URI:
http://localhost:3000/auth(for local development) - Note: For production, use your actual domain, e.g.,
https://yourdomain.com/auth
-
Click "Register"
Step 4: Record Application Details
After registration, you'll be taken to the app's overview page. Record these values:
- Application (client) ID: Copy this value - this is your
CLIENT_ID - Directory (tenant) ID: Copy this value - this is your
TENANT_ID
Step 5: Create Client Secret
-
In the left sidebar of your app registration, click on "Certificates & secrets"
-
Click on "New client secret"
-
Description: Enter a description, e.g., "PDF Renamer Secret"
-
Expires: Choose an appropriate expiration (recommend 1 year for development)
-
Click "Add"
-
Important: Immediately copy the Value (not the Secret ID) - this is your
CLIENT_SECRET- Warning: This value will only be shown once. Store it securely!
Step 6: Configure Authentication Settings
- In the left sidebar, click on "Authentication"
- Under "Web" section, ensure your redirect URI is listed:
http://localhost:3000/auth - Under "Implicit grant and hybrid flows":
- Check "Access tokens (used for implicit flows)"
- Check "ID tokens (used for implicit and hybrid flows)"
- Click "Save" at the top
Step 7: Set Environment Variables
Create a .env file in your project root directory with the following content:
TENANT_ID=your-tenant-id-here
CLIENT_ID=your-client-id-here
CLIENT_SECRET=your-client-secret-here
SECRET_KEY=your-random-secret-key-here
Security Notes:
- Never commit the
.envfile to version control - Use a strong, random string for
SECRET_KEY(at least 32 characters) - For production, use Azure Key Vault or similar secure storage
Step 8: Alternative - Set Environment Variables in Shell
If you prefer not to use a .env file, you can set environment variables in your shell:
Windows (PowerShell):
$env:TENANT_ID = "your-tenant-id-here"
$env:CLIENT_ID = "your-client-id-here"
$env:CLIENT_SECRET = "your-client-secret-here"
$env:SECRET_KEY = "your-random-secret-key-here"
Windows (Command Prompt):
set TENANT_ID=your-tenant-id-here
set CLIENT_ID=your-client-id-here
set CLIENT_SECRET=your-client-secret-here
set SECRET_KEY=your-random-secret-key-here
Linux/macOS:
export TENANT_ID=your-tenant-id-here
export CLIENT_ID=your-client-id-here
export CLIENT_SECRET=your-client-secret-here
export SECRET_KEY=your-random-secret-key-here
Step 9: Test the Configuration
- Ensure your virtual environment is activated
- Run the application:
python pdf_renamer.py - Open your browser to
http://127.0.0.1:3000/ - You should be redirected to Microsoft login
- After successful authentication, you'll access the PDF Renamer app
Troubleshooting
Common Issues:
-
"Invalid client" error:
- Verify
CLIENT_IDandCLIENT_SECRETare correct - Ensure the client secret hasn't expired
- Verify
-
"Invalid redirect URI" error:
- Check that the redirect URI in Azure matches exactly:
http://localhost:3000/auth - For production, update to your domain
- Check that the redirect URI in Azure matches exactly:
-
"Tenant not found" error:
- Verify
TENANT_IDis correct - Ensure you're using the Directory (tenant) ID, not the Application ID
- Verify
-
Permission denied:
- Ensure your Azure account has permissions to register applications
- Check that the app registration is in the correct tenant
Additional Resources:
- Azure AD App Registration Documentation
- OAuth 2.0 Authorization Code Flow
- Microsoft Identity Platform Documentation
Production Deployment Notes
When deploying to production:
- Update redirect URIs to your production domain
- Use HTTPS for all URLs
- Store secrets securely (Azure Key Vault recommended)
- Consider using managed identity for Azure resources
- Implement proper logging and monitoring
- Set appropriate token lifetimes and refresh policies
Support
If you encounter issues with the Entra ID setup, please check:
- Azure Portal configuration
- Environment variable values
- Application logs for error messages
- Network connectivity to login.microsoftonline.com c:\Users\NateEmmert\pdf-rename-sort\pdf-rename-sort\ENTRA_SETUP.md