Cline rules
.clinerules/02-External-tenant-configuration.mdCline rules
Quality
69/100
Scores the file, not the repository.Length
2,145 words
63 headings · 7 code blocksRepository
344
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# Agent Instructions: Create iOS/macOS Sample Application with Microsoft Entra ID - External configuration23## Overview45These instructions guide agents through creating a sample iOS or macOS application that implements user sign-in using Microsoft Entra External ID for external tenants (customer-facing applications) and calls the Microsoft Graph API.67## Prerequisites89Before starting, ensure the following requirements are met:1011### Azure Requirements1213- Active Azure subscription with an active account14- Permissions to manage applications (requires one of these roles):15 - Application Administrator16 - Application Developer17- An external tenant. To create one, choose from:18 - Use the [Microsoft Entra External ID extension](https://aka.ms/ciamvscode/samples/marketplace) to set up an external tenant directly in Visual Studio Code _(Recommended)_19 - [Create a new external tenant](https://learn.microsoft.com/en-us/entra/external-id/customers/how-to-create-external-tenant-portal) in the Microsoft Entra admin center2021### Development Environment2223- **iOS**: Version 16 or higher (for iOS apps)24- **macOS**: Version 11 or higher (for macOS apps)25- **CocoaPods**: For dependency management2627### Pre-Configuration2829- Register a new application in the Microsoft Entra admin center30- Configure for "Accounts in this organizational directory only"31- Record the following values from the application Overview page:32 - **Application (client) ID**33 - **Directory (tenant) ID**34 - **Tenant Subdomain** (e.g., if your tenant primary domain is `contoso.onmicrosoft.com`, the subdomain is `contoso`)3536### Additional Requirements3738- A user flow configured for self-service sign-up39- The application must be added to the user flow4041## Step 1: Register Application in Microsoft Entra Admin Center4243### 1.1 Create App Registration44451. Navigate to the [Microsoft Entra admin center](https://entra.microsoft.com)462. Select **Applications** > **App registrations** > **New registration**473. Enter a name for your application484. Select "Accounts in this organizational directory only" as the supported account types495. Click **Register**506. Save the **Application (client) ID** and **Directory (tenant) ID** from the Overview page5152### 1.2 Get Tenant Details53541. Note your tenant's primary domain (e.g., `contoso.onmicrosoft.com`)552. Extract the subdomain portion (e.g., `contoso`)563. Save this subdomain for later configuration5758### 1.3 Configure Platform (iOS/macOS)59601. Under **Manage**, select **Authentication** > **Add Platform** > **iOS / macOS**612. Enter your **Bundle Identifier**62 - For the sample code: `com.microsoft.identitysample.ciam.MSALiOS`63 - For custom apps: Use your unique identifier (e.g., `com.yourcompany.appname`)643. Click **Configure** and save the **MSAL Configuration** details654. Click **Done**6667### 1.4 Enable Public Client Flow68691. Under **Manage**, select **Authentication**702. Scroll to **Advanced settings**713. For **Allow public client flows**, select **Yes**724. Click **Save**7374## Step 2: Configure User Flow7576### 2.1 Create User Flow77781. In the Microsoft Entra admin center, navigate to **External Identities** > **User flows**792. Click **New user flow**803. Select **Sign up and sign in** as the user flow type814. Configure the user flow:82 - Name the user flow83 - Select identity providers (e.g., Email and password)84 - Choose user attributes to collect during sign-up85 - Configure optional claims865. Click **Create**8788### 2.2 Add Application to User Flow89901. Open your created user flow912. Select **Applications**923. Click **Add application**934. Select your registered application945. Click **Add**9596For detailed instructions, see:9798- [Create self-service sign-up user flows](https://learn.microsoft.com/en-us/entra/external-id/customers/how-to-user-flow-sign-up-sign-in-customers)99- [Add application to user flow](https://learn.microsoft.com/en-us/entra/external-id/customers/how-to-user-flow-add-application)100101## Step 3: Download Sample Code102103### 3.1 Clone the Repository104105Open Terminal and run the following command:106107```bash108git clone https://github.com/Azure-Samples/ms-identity-ciam-browser-delegated-ios-sample.git109cd ms-identity-ciam-browser-delegated-ios-sample110```111112Alternatively, download as a ZIP file:113114```bash115curl -L https://github.com/Azure-Samples/ms-identity-ciam-browser-delegated-ios-sample/archive/refs/heads/main.zip -o ios-ciam-sample.zip116unzip ios-ciam-sample.zip117cd ms-identity-ciam-browser-delegated-ios-sample-main118```119120## Step 4: Install Dependencies121122### 4.1 Install MSAL Library1231241. Navigate to the project directory in Terminal1252. Run CocoaPods to install the Microsoft Authentication Library (MSAL):126```bash127pod install128```1293. Wait for the installation to complete130131### 4.2 Open Workspace132133After pod installation, open the `.xcworkspace` file:134135```bash136open *.xcworkspace137```138139**Important**: Always use the `.xcworkspace` file, not the `.xcodeproj` file when working with CocoaPods.140141## Step 5: Configure the Application142143### 5.1 Update Configuration.swift1441451. In Xcode, locate and open **/MSALiOS/Configuration.swift**1462. Replace the placeholders with your values:147148```swift149// Replace Enter_the_Application_Id_Here with your Application (client) ID150let kClientID = "YOUR_APPLICATION_CLIENT_ID_HERE"151152// Replace Enter_the_Redirect_URI_Here with your redirect URI153// This should match the MSAL configuration from the portal154let kRedirectUri = "msauth.com.microsoft.identitysample.ciam.MSALiOS://auth"155156// Replace Enter_the_Tenant_Subdomain_Here with your tenant subdomain157// For example, if your domain is contoso.onmicrosoft.com, use "contoso"158let kTenantSubdomain = "YOUR_TENANT_SUBDOMAIN"159160// Replace Enter_the_Protected_API_Scopes_Here with your API scopes161// If you haven't configured any scopes yet, you can leave this empty162let kScopes = ["YOUR_API_SCOPES_HERE"]163// Example: let kScopes = ["api://YOUR_CLIENT_ID/ToDoList.Read", "api://YOUR_CLIENT_ID/ToDoList.ReadWrite"]164```165166### 5.2 Configure Bundle Identifier1671681. In Xcode, select the project in the navigator1692. Select your target1703. Go to the **General** tab1714. In the **Identity** section, verify the **Bundle Identifier** matches what you registered in the Azure portal172 - Default sample: `com.microsoft.identitysample.ciam.MSALiOS`173174### 5.3 Update Info.plist (if needed)175176The Info.plist should already be configured correctly for the sample. If you're using a custom Bundle Identifier:1771781. Right-click **Info.plist** in the project navigator1792. Select **Open As** > **Source Code**1803. Find the `CFBundleURLTypes` section1814. Ensure the URL scheme matches your configuration:182183```xml184<key>CFBundleURLTypes</key>185<array>186 <dict>187 <key>CFBundleURLSchemes</key>188 <array>189 <string>msauth.YOUR_BUNDLE_IDENTIFIER</string>190 </array>191 </dict>192</array>193```194195## Step 6: Grant Admin Consent (if required)196197If your application requires API permissions:1981991. In the Microsoft Entra admin center, go to your app registration2002. Under **Manage**, select **API permissions**2013. Review the configured permissions2024. Click **Grant admin consent for [your tenant]**2035. Confirm the consent204205For more details, see [Grant admin consent](https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app#grant-admin-consent-external-tenants-only).206207## Step 7: Build and Run the Application208209### 7.1 Build the Project2102111. Select your target device or simulator from the scheme selector2122. Click the **Build** button (⌘+B) or select **Product** > **Build**2133. Verify there are no build errors214215### 7.2 Run the Application2162171. Select **Product** > **Run** from the menu (or press ⌘+R)2182. The app will launch in the simulator or on your connected device219220### 7.3 Test Authentication2212221. When the app launches, you'll see the main interface2232. Click **Acquire Token Interactively**2243. A browser or web view will open with your configured sign-in experience2254. Complete the sign-up or sign-in process:226 - For new users: Fill in required attributes during sign-up227 - For existing users: Enter credentials2285. After successful authentication, you'll be redirected back to the app2296. The app will display user information and the access token230231### 7.4 Test API Calls2322331. Click **API - Perform GET** to test calling a protected API2342. Note: If you haven't configured a protected API yet, you may receive an error2353. For testing purposes, you can use Microsoft Graph API or deploy a custom API236237## Step 8: Understanding the External Tenant Flow238239### Authentication Flow for External Tenants240241```242User opens app243 ↓244User clicks "Acquire Token Interactively"245 ↓246App initiates MSAL authentication with external tenant247 ↓248Browser/Web view opens with custom sign-up/sign-in UI249 ↓250New user: Sign-up flow with attribute collection251Existing user: Sign-in with credentials252 ↓253External tenant validates credentials254 ↓255User grants consent (if needed)256 ↓257Redirect back to app with authorization code258 ↓259MSAL exchanges code for access token260 ↓261App receives access token and ID token262 ↓263App can call protected APIs264```265266### Key Differences from Workforce Tenants267268- **User Flows**: External tenants use customizable user flows for sign-up/sign-in269- **Self-Service Registration**: Users can sign up without admin pre-creation270- **Branding**: Fully customizable sign-up/sign-in experience271- **Identity Providers**: Can configure social identity providers (Google, Facebook, etc.)272- **Attribute Collection**: Configure which user attributes to collect during sign-up273274## Step 9: Testing the Application275276### 9.1 Test New User Sign-Up2772781. Launch the app2792. Click **Acquire Token Interactively**2803. On the sign-in page, click **Sign up now** or similar link2814. Fill in required attributes (email, password, etc.)2825. Complete email verification if configured2836. Verify successful account creation and sign-in2847. Check that user information is displayed in the app285286### 9.2 Test Existing User Sign-In2872881. Launch the app (or sign out if already signed in)2892. Click **Acquire Token Interactively**2903. Enter credentials for an existing user2914. Verify successful sign-in2925. Check that user information is displayed293294### 9.3 Test Silent Token Acquisition2952961. After initial sign-in, restart the app2972. Click **Acquire Token Silently**2983. Verify token is obtained without user interaction2994. This validates token caching and refresh token functionality300301### 9.4 Test API Access302303If you've configured a protected API:3043051. Click **API - Perform GET**3062. Verify successful API call with the acquired token3073. Check the response data308309## Step 10: Customize Branding and User Experience310311### 10.1 Customize Branding3123131. In the Microsoft Entra admin center, go to **Company branding**3142. Configure:315 - Logo and background images316 - Colors and themes317 - Custom text and messages3183. Save changes3194. Test the updated branding in your app320321For details, see [Customize the default branding](https://learn.microsoft.com/en-us/entra/external-id/customers/how-to-customize-branding-customers).322323### 10.2 Configure Social Identity Providers324325Add social sign-in options (Google, Facebook, etc.):3263271. In the Microsoft Entra admin center, go to **External Identities** > **All identity providers**3282. Click **New identity provider**3293. Select the provider (e.g., Google)3304. Configure the provider settings3315. Add the provider to your user flow332333For details, see [Configure sign-in with Google](https://learn.microsoft.com/en-us/entra/external-id/customers/how-to-google-federation-customers).334335## Step 11: Common Configuration Issues336337### Issue: "Invalid tenant subdomain"338339- **Solution**: Verify the tenant subdomain in Configuration.swift340- Ensure no extra spaces or characters341- Check that it matches your tenant's primary domain342343### Issue: "Application not found in user flow"344345- **Solution**: Verify the app is added to the user flow346- Check that the user flow is active347- Ensure the correct user flow is configured348349### Issue: "Redirect URI mismatch"350351- **Solution**: Verify Bundle Identifier matches Azure portal configuration352- Ensure the redirect URI in Configuration.swift matches the portal353- Check that URL scheme in Info.plist is correct354355### Issue: "Invalid client"356357- **Solution**: Double-check Application (client) ID in Configuration.swift358- Ensure the app registration exists in the correct tenant359- Verify no extra spaces or characters360361### Issue: "Scopes not granted"362363- **Solution**: Verify API permissions are configured364- Grant admin consent if required365- Check that scopes in Configuration.swift match configured permissions366367### Issue: "Pod install fails"368369- **Solution**: Update CocoaPods: `sudo gem install cocoapods`370- Clear pod cache: `pod cache clean --all`371- Try again: `pod install`372373### Issue: "Sign-up attributes not appearing"374375- **Solution**: Check user flow configuration376- Verify required attributes are selected377- Ensure custom attributes are defined if needed378379## Step 12: Next Steps380381After successfully building and running the sample:382383### Implement Protected API Calls384385- Follow the tutorial: [Sign in users and call a protected web API in sample iOS (Swift) app](https://learn.microsoft.com/en-us/entra/external-id/customers/sample-mobile-app-ios-swift-sign-in-call-api)386- Deploy an ASP.NET Core web API387- Configure API permissions and scopes388- Implement authenticated API calls from the mobile app389390### Enhance User Experience391392- Customize the in-app UI after authentication393- Implement user profile management394- Add password reset functionality395- Configure multi-factor authentication396397### Add Advanced Features398399- Implement token refresh strategies400- Add offline support with cached tokens401- Integrate biometric authentication (Face ID, Touch ID)402- Add logging and analytics403404### Production Readiness405406- Implement comprehensive error handling407- Add retry logic for network failures408- Configure app transport security409- Implement certificate pinning410- Add crash reporting and monitoring411412## Step 13: Additional Resources413414### Documentation415416- **External ID Overview**: [Microsoft Entra External ID documentation](https://learn.microsoft.com/en-us/entra/external-id/)417- **MSAL for iOS/macOS**: [Microsoft Authentication Library for iOS and macOS](https://github.com/AzureAD/microsoft-authentication-library-for-objc)418- **User Flows**: [User flows for external tenants](https://learn.microsoft.com/en-us/entra/external-id/customers/concept-user-flows)419- **API Protection**: [Protect an API in external tenants](https://learn.microsoft.com/en-us/entra/external-id/customers/tutorial-protect-web-api-dotnet-core-build-app)420421### Sample Applications422423- **iOS Sample**: [ms-identity-ciam-browser-delegated-ios-sample](https://github.com/Azure-Samples/ms-identity-ciam-browser-delegated-ios-sample)424- **macOS Sample**: Available in the same repository with platform-specific configurations425426### Best Practices427428- **Security**: [Security best practices for external tenants](https://learn.microsoft.com/en-us/entra/external-id/customers/concept-security-customers)429- **User Experience**: [UX best practices for customer-facing apps](https://learn.microsoft.com/en-us/entra/external-id/customers/concept-branding-customers)430- **Token Management**: [Token lifetimes and policies](https://learn.microsoft.com/en-us/entra/identity-platform/configurable-token-lifetimes)431432## Step 14: Security Considerations for External Tenants433434### Authentication Security4354361. **Use strong password policies**: Configure in user flow settings4372. **Enable MFA**: Add multi-factor authentication to user flows4383. **Implement account protection**: Configure suspicious activity detection4394. **Rate limiting**: Protect against brute force attacks440441### Token Security4424431. **Minimal scopes**: Request only necessary API permissions4442. **Token validation**: Always validate tokens server-side4453. **Secure storage**: Use iOS Keychain for token storage4464. **Token refresh**: Implement proper token refresh logic4475. **Revocation**: Support token and session revocation448449### Data Protection4504511. **HTTPS only**: Ensure all communication uses HTTPS4522. **Certificate pinning**: Consider implementing for production4533. **Data encryption**: Encrypt sensitive data at rest4544. **PII handling**: Follow privacy regulations (GDPR, CCPA)455456### App Security4574581. **Code obfuscation**: Protect sensitive logic in production4592. **Jailbreak detection**: Consider detecting compromised devices4603. **Input validation**: Validate all user inputs4614. **Secure coding**: Follow OWASP Mobile Security guidelines462463---464465**Source**: [Microsoft Learn - Quickstart: Sign in users in a sample mobile app (External Tenants)](https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-mobile-app-sign-in?tabs=ios-macos-external&pivots=external)466
Also in AzureAD/microsoft-authentication-library-for-objc
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| AzureAD/microsoft-authentication-library-for-objcCLAUDE.md · 344 | CLAUDE.md | buildteststylearch+6 | 76/100 | 3 days ago | |
| AzureAD/microsoft-authentication-library-for-objc.clinerules/01-Workforce-tenant-configuration.md · 344 | Cline rules | setupbuildtestarch+5 | 58/100 | 3 days ago | |
| AzureAD/microsoft-authentication-library-for-objc.clinerules/03-MSAL-API-usage.md · 344 | Cline rules | styleapi | 58/100 | 3 days ago | |
| AzureAD/microsoft-authentication-library-for-objc.clinerules/04-Code-style-guidelines.md · 344 | Cline rules | stylearchtypestesting-strategy+4 | 69/100 | 3 days ago | |
| AzureAD/microsoft-authentication-library-for-objc.clinerules/05-feature-gating.md · 344 | Cline rules | stylearchdependenciesperformance+2 | 61/100 | 3 days ago | |
| AzureAD/microsoft-authentication-library-for-objc.clinerules/06-Customer-communication-guidelines.md · 344 | Cline rules | stylemonorepodo-notagent-behaviour | 51/100 | 3 days ago | |
| AzureAD/microsoft-authentication-library-for-objc.clinerules/AGENTS.md · 344 | AGENTS.md | styleapi | 48/100 | 3 days ago | |
| AzureAD/microsoft-authentication-library-for-objc.cursor/rules/ruler_cursor_instructions.mdc · 344 | Cursor rules | buildteststylearch+6 | 76/100 | 3 days ago | |
| AzureAD/microsoft-authentication-library-for-objc.github/copilot-instructions.md · 344 | Copilot instructions | setupbuildteststyle+11 | 64/100 | 3 days ago | |
| AzureAD/microsoft-authentication-library-for-objcAGENTS.md · 344 | AGENTS.md | buildteststylearch+6 | 76/100 | 3 days ago |
Diff against CLAUDE.md Diff against .clinerules/01-Workforce-tenant-configuration.md Diff against .clinerules/03-MSAL-API-usage.md Diff against .clinerules/04-Code-style-guidelines.md Diff against .clinerules/05-feature-gating.md Diff against .clinerules/06-Customer-communication-guidelines.md Diff against .clinerules/AGENTS.md Diff against .cursor/rules/ruler_cursor_instructions.mdc Diff against .github/copilot-instructions.md Diff against AGENTS.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| JCodesMore/ai-website-cloner-template.clinerules · 31k | Cline rules | buildlint-formatstylearch+3 | 97/100 | 2 days ago | |
| BryaanF/LiantPortfolio.clinerules/project-guidelines.md · 0 | Cline rules | buildstylearchgit+2 | 96/100 | 3 days ago | |
| lepinkainen/humanlog.clinerules/project-rules.md · 0 | Cline rules | setupbuildtestlint-format+8 | 96/100 | 3 days ago | |
| u9401066/zotero-keeper.clinerules/50-pubmed-project.md · 6 | Cline rules | testlint-formatstylearch+1 | 94/100 | 3 days ago | |
| u9401066/zotero-keepervscode-extension/resources/repo-assets/pubmed-search-mcp/.clinerules/50-pubmed-project.md · 6 | Cline rules | testlint-formatstylearch+1 | 94/100 | 3 days ago | |
| u9401066/pubmed-search-mcp.clinerules/50-pubmed-project.md · 23 | Cline rules | testlint-formatstylearch+1 | 94/100 | 3 days ago | |
| VaillerTeeter/HoshimiNest.clinerules/project-identity.md · 1 | Cline rules | setuparchtypesdo-not | 93/100 | yesterday | |
| blendsdk/codeops-mcp.clinerules/project.md · 0 | Cline rules | buildteststylearch+7 | 91/100 | 3 days ago |
