Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Register Microsoft Entra ID apps and configure OAuth 2.0 authentication with MSAL integration.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/first-app-registration.md
1# First App Registration - Step-by-Step Guide23This guide walks you through creating your first Microsoft Entra app registration from scratch.45## Overview67You'll learn how to:81. Create an app registration in Azure Portal92. Configure authentication settings103. Add API permissions114. Create client credentials125. Test the authentication flow1314## Prerequisites1516- Azure subscription (free tier works)17- Azure Portal access: https://portal.azure.com18- Basic understanding of your application type (web, mobile, service)1920## Step 1: Navigate to App Registrations21221. Open [Azure Portal](https://portal.azure.com)232. Search for **"Microsoft Entra ID"**243. In the left menu, click **"App registrations"**254. Click **"+ New registration"** at the top2627## Step 2: Register Your Application2829You'll see a form with several fields:3031### Application Name32- **What to enter:** A descriptive name for your app33- **Example:** "My First Console App" or "Product Inventory API"34- **Tip:** Use a name that clearly identifies the purpose3536### Supported Account Types3738Choose who can use your application:3940| Option | When to Use |41|--------|-------------|42| **Accounts in this organizational directory only (Single tenant)** | Only users from the same tenant of this app registration need access |43| **Accounts in any organizational directory (Multi-tenant)** | Users from multiple organization tenants need access |44| **Accounts in any organizational directory + Personal Microsoft accounts** | Users from multiple organization tenants and MSA users need access |45| **Personal Microsoft accounts only** | Only MSA users need access |4647**Note:** Once selected, users whose account type is not allowed will get errors when trying to get access token for the app registration.4849### Redirect URI (optional)5051The redirect URI is where authentication responses are sent.5253**Platform:** Select the type:54- **Web** - Server-side web apps55- **Single-page application (SPA)** - React, Angular, Vue apps56- **Public client/native** - Mobile, desktop, console apps5758**URI examples:**59- Web app: `https://localhost:5001/signin-oidc`60- SPA: `http://localhost:3000`61- Console/Desktop: `http://localhost`6263**For your first app:** Select **"Public client/native"** and enter `http://localhost`6465### Click "Register"6667After clicking, you'll be redirected to your app's overview page.6869## Step 3: Save Important Information7071On the **Overview** page, you'll see critical information. **Copy and save these values:**7273### Application (client) ID74- **What it is:** Unique identifier for your app75- **Format:** `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` (GUID)76- **When you need it:** Every time your app authenticates77- **Where to save:** Environment variables, configuration file7879### Directory (tenant) ID80- **What it is:** Unique identifier for your Azure AD tenant81- **Format:** `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` (GUID)82- **When you need it:** Constructing authentication URLs8384### Example values to save:85```bash86# Save these in a secure location87APPLICATION_CLIENT_ID="12345678-1234-1234-1234-123456789012"88TENANT_ID="87654321-4321-4321-4321-210987654321"89```9091## Step 4: Configure Authentication (Optional)9293Click **"Authentication"** in the left menu.9495### Advanced Settings9697**Allow public client flows:**98- **What it is:** Enables device code flow, resource owner password flow99- **For console apps:** Turn this **ON**100- **For web apps:** Keep **OFF**101102### Supported account types103104You can change this later if needed.105106### Logout URL (optional)107108Where to redirect users after logout.109110**Click "Save"** at the top if you made changes.111112## Step 5: Add API Permissions113114Click **"API permissions"** in the left menu.115116### Default Permission117118You'll see one default permission:119- **Microsoft Graph → User.Read (Delegated)**120121This allows your app to read the signed-in user's profile.122123### Add More Permissions1241251. Click **"+ Add a permission"**1262. Select **"Microsoft Graph"**1273. Choose **"Delegated permissions"** (for user context)1284. Search for and select permissions you need:129- **User.Read** - Read user profile (already added)130- **Mail.Read** - Read user's mail131- **Calendars.Read** - Read user's calendar1321335. Click **"Add permissions"**134135### Admin Consent136137Some permissions require admin consent:138- If you're an admin: Click **"Grant admin consent for [Your Org]"**139- If you're not: Ask your admin to grant consent140141**Status indicator:**142- ✅ Green checkmark = Granted143- ⚠️ Yellow warning = Not granted (may still work for user consent)144145## Step 6: Create Client Secret (If Needed)146147**Skip this if:** You're building a desktop/mobile/console app (public client)148149**Do this if:** You're building a web app, API, or service (confidential client)1501511. Click **"Certificates & secrets"** in the left menu1522. Click **"+ New client secret"**1533. Enter a description: "Development Secret"1544. Choose expiration:155- **Recommended for development:** 6 months156- **For production:** 12-24 months (set up rotation)1575. Click **"Add"**158159**⚠️ CRITICAL:** Copy the secret **Value** immediately!160- It's only shown once161- You cannot retrieve it later162- If you lose it, create a new one163164```bash165# Save this securely (example)166CLIENT_SECRET="abc123~defGHI456jklMNO789pqrSTU"167```168169**Security tips:**170- Never commit secrets to source control171- Use Azure Key Vault for production172- Use environment variables for development173174## Step 7: Test Your App Registration175176### Option A: Quick Test with Azure CLI177178```bash179# Set your values180CLIENT_ID="your-client-id-here"181TENANT_ID="your-tenant-id-here"182183# Interactive login184az login --scope "https://graph.microsoft.com/.default"185186# Get an access token187az account get-access-token --resource "https://graph.microsoft.com"188```189190### Option B: Test with MSAL Library191192See the complete code example in [console-app-example.md](console-app-example.md)193194### Expected Results195196**Success:**197- Browser opens for authentication (or device code shown)198- You authenticate with your Azure AD account199- Access token is returned200- You can call Microsoft Graph API201202**Common first-time issues:**203- Redirect URI mismatch → Double-check URI in Authentication settings204- Insufficient permissions → Add required API permissions205- User consent required → Grant admin consent or user must consent206207**Tip:** Once you get the access token, you can use [jwt.ms](https://jwt.ms) to decode it and inspect its claims.208209## Step 8: Review Configuration210211### Checklist212213- ✅ App registered with clear name214- ✅ Application ID and Tenant ID saved securely215- ✅ Redirect URI configured correctly216- ✅ API permissions added217- ✅ Admin consent granted (if required)218- ✅ Client secret created and saved (if needed)219- ✅ Authentication tested successfully220221## Next Steps222223- In your client app, implement the OAuth flow to acquire access tokens for your app registration.224- In your server app, implement token validation to protect your resources.225226## Troubleshooting227228### Redirect URI mismatch"229230**Solution:**231- Check Authentication → Redirect URIs232- Ensure exact match (case-sensitive, trailing slash matters)233- Ensure correct platform (Web vs SPA vs Public client)234235### User consent required236237**Solution:**238- Grant admin consent in API permissions239- Or have user consent during first login240241## Additional Resources242243- [Microsoft Entra ID Documentation](https://learn.microsoft.com/en-us/entra/identity-platform/)244