

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
1# Agent Instructions: Create iOS/macOS Sample Application with Microsoft Entra ID - Workforce configuration23## Overview45These instructions guide agents through creating a sample iOS or macOS application that implements user sign-in using Microsoft Entra ID (formerly Azure AD) 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- A workforce tenant (or create a new tenant)1819### Development Environment2021- **iOS**: Version 16 or higher (for iOS apps)22- **macOS**: Version 11 or higher (for macOS apps)23- **CocoaPods**: For dependency management2425### Pre-Configuration2627- Register a new application in the Microsoft Entra admin center28- Configure for "Accounts in this organizational directory only"29- Record the following values from the application Overview page:30 - **Application (client) ID**31 - **Directory (tenant) ID**3233## Step 1: Register Application in Microsoft Entra Admin Center3435### 1.1 Create App Registration36371. Navigate to the [Microsoft Entra admin center](https://entra.microsoft.com)382. Select **Applications** > **App registrations** > **New registration**393. Enter a name for your application404. Select "Accounts in this organizational directory only" as the supported account types415. Click **Register**426. Save the **Application (client) ID** and **Directory (tenant) ID** from the Overview page4344### 1.2 Configure Platform (iOS/macOS)45461. Under **Manage**, select **Authentication** > **Add Platform** > **iOS/macOS**472. Enter your **Bundle Identifier** (e.g., `com.<yourname>.identitysample.MSALMacOS`)48 - Note: This is a unique string that identifies your application49 - The iOS configuration also applies to macOS applications503. Click **Configure** and save the **MSAL Configuration** details514. Click **Done**5253### 1.3 Enable Public Client Flow54551. Under **Manage**, select **Authentication**562. Scroll to **Advanced settings**573. For **Allow public client flows**, select **Yes**584. Click **Save**5960## Step 2: Download Sample Code6162### 2.1 Download the Project6364Choose the appropriate sample based on your target platform:6566**For iOS:**6768```bash69curl -L https://github.com/Azure-Samples/active-directory-ios-swift-native-v2/archive/master.zip -o ios-sample.zip70unzip ios-sample.zip71cd active-directory-ios-swift-native-v2-master72```7374**For macOS:**7576```bash77curl -L https://github.com/Azure-Samples/active-directory-macOS-swift-native-v2/archive/master.zip -o macos-sample.zip78unzip macos-sample.zip79cd active-directory-macOS-swift-native-v2-master80```8182## Step 3: Install Dependencies8384### 3.1 Install MSAL Library85861. Open Terminal and navigate to the project directory872. Run CocoaPods to install the Microsoft Authentication Library (MSAL):88```bash89pod install90```913. Wait for the installation to complete9293### 3.2 Open Workspace9495After pod installation, open the `.xcworkspace` file (NOT the `.xcodeproj` file):9697```bash98open *.xcworkspace99```100101## Step 4: Configure the Application102103### 4.1 Update ViewController.swift1041051. In Xcode, open the project navigator1062. Locate and open **ViewController.swift**1073. Find the line starting with `let kClientID` and replace it with your Application (client) ID:108109```swift110let kClientID = "YOUR_APPLICATION_CLIENT_ID_HERE"111```112113### 4.2 Configure Endpoints114115For standard Microsoft Entra ID (global access), use default values:116117```swift118let kGraphEndpoint = "https://graph.microsoft.com/"119let kAuthority = "https://login.microsoftonline.com/common"120```121122**For national clouds** (if applicable):123124- **Microsoft Entra Germany:**125126```swift127let kGraphEndpoint = "https://graph.microsoft.de/"128let kAuthority = "https://login.microsoftonline.de/common"129```130131See [Microsoft Graph deployments documentation](https://learn.microsoft.com/en-us/graph/deployments#app-registration-and-token-service-root-endpoints) for other endpoints.132133### 4.3 Configure Bundle Identifier1341351. In Xcode, select the project in the navigator1362. Select your target1373. Go to the **General** tab1384. In the **Identity** section, set the **Bundle Identifier** to match what you registered in the Azure portal139140### 4.4 Update Info.plist1411421. Right-click **Info.plist** in the project navigator1432. Select **Open As** > **Source Code**1443. Find the `CFBundleURLTypes` section under the dict root node1454. Replace `Enter_the_Bundle_Id_Here` with your Bundle Identifier1465. Note: Keep the `msauth.` prefix in the string147148```xml149<key>CFBundleURLTypes</key>150<array>151 <dict>152 <key>CFBundleURLSchemes</key>153 <array>154 <string>msauth.YOUR_BUNDLE_IDENTIFIER_HERE</string>155 </array>156 </dict>157</array>158```159160## Step 5: Build and Run the Application161162### 5.1 Build the Project1631641. Select your target device or simulator from the scheme selector1652. Click the **Build** button (⌘+B) or select **Product** > **Build**1663. Verify there are no build errors167168### 5.2 Run the Application1691701. Select **Product** > **Run** from the menu (or press ⌘+R)1712. The app will launch in the simulator or on your connected device172173### 5.3 Test Authentication1741751. When the app launches, you'll see the main interface1762. Click **Sign In** or **Acquire Token Interactively**1773. You'll be prompted to enter your credentials1784. After successful authentication, the app will display user information1795. The app can now make authenticated calls to Microsoft Graph API180181## Step 6: Understanding the Code Flow182183### Authentication Flow Diagram184185```186User clicks "Sign In"187 ↓188App initiates MSAL authentication189 ↓190Browser/Web view opens with Microsoft login191 ↓192User enters credentials193 ↓194Microsoft Entra ID validates credentials195 ↓196Redirect back to app with authorization code197 ↓198MSAL exchanges code for access token199 ↓200App receives access token201 ↓202App can call Microsoft Graph API203```204205### Key Components206207- **MSAL Library**: Handles authentication and token management208- **ViewController**: Main UI and authentication logic209- **Microsoft Graph API**: Provides access to user data and resources210- **Access Token**: JWT token used to authenticate API calls211212## Step 7: Testing the Application213214### 7.1 Interactive Sign-In215216Test the interactive authentication flow:2172181. Launch the app2192. Click **Acquire Token Interactively**2203. Enter valid test credentials2214. Verify successful sign-in2225. Check that user information is displayed223224### 7.2 Silent Token Acquisition225226Test silent token refresh:2272281. After initial sign-in, click **Acquire Token Silently**2292. Verify token is obtained without user interaction2303. This uses cached refresh tokens231232### 7.3 Microsoft Graph API Call233234Test API access:2352361. Click **Get Graph Data Interactively** or **Get Graph Data Silently**2372. Verify the app successfully calls Microsoft Graph API2383. Check that user profile data is displayed239240## Step 8: Common Configuration Issues241242### Issue: "Redirect URI mismatch"243244- **Solution**: Verify Bundle Identifier in Info.plist matches Azure portal configuration245- Ensure `msauth.` prefix is included in the redirect URI246247### Issue: "Invalid client"248249- **Solution**: Double-check Application (client) ID in ViewController.swift250- Ensure no extra spaces or characters251252### Issue: "Pod install fails"253254- **Solution**: Update CocoaPods: `sudo gem install cocoapods`255- Clear pod cache: `pod cache clean --all`256- Try again: `pod install`257258### Issue: "Build fails with MSAL errors"259260- **Solution**: Ensure you opened the `.xcworkspace` file, not `.xcodeproj`261- Clean build folder: **Product** > **Clean Build Folder** (⇧⌘K)262263## Step 9: Next Steps264265After successfully building and running the sample:266267### For iOS Applications268269- Follow the tutorial: [Sign in users and call Microsoft Graph from an iOS app](https://learn.microsoft.com/en-us/entra/identity-platform/tutorial-v2-ios)270- Implement additional Microsoft Graph API calls271- Add custom UI and branding272- Implement token caching strategies273274### For macOS Applications275276- Follow the iOS tutorial (also applies to macOS): [Sign in users and call Microsoft Graph from a iOS/macOS app](https://learn.microsoft.com/en-us/entra/identity-platform/tutorial-v2-ios)277- Implement additional application features278- Add keychain integration for secure token storage279280### General Enhancements281282- Implement error handling and retry logic283- Add logging and telemetry284- Configure additional API scopes285- Implement sign-out functionality286- Add multi-account support287288## Additional Resources289290- **MSAL Documentation**: [Microsoft Authentication Library for iOS and macOS](https://github.com/AzureAD/microsoft-authentication-library-for-objc)291- **Microsoft Graph API**: [Microsoft Graph REST API reference](https://learn.microsoft.com/en-us/graph/api/overview)292- **Authentication Flows**: [OAuth 2.0 and OpenID Connect protocols](https://learn.microsoft.com/en-us/entra/identity-platform/v2-protocols)293- **Best Practices**: [Security best practices for application developers](https://learn.microsoft.com/en-us/entra/identity-platform/identity-platform-integration-checklist)294295## Security Considerations2962971. **Never hardcode secrets**: Use secure storage mechanisms2982. **Validate tokens**: Always validate tokens server-side for API calls2993. **Use HTTPS**: Ensure all network communication uses HTTPS3004. **Minimal scopes**: Request only the minimum required API scopes3015. **Token expiration**: Handle token expiration and refresh appropriately3026. **Secure storage**: Use iOS Keychain or macOS Keychain for sensitive data303304---305306**Source**: [Microsoft Learn - Quickstart: Sign in users in a sample mobile app](https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-mobile-app-sign-in)307
One 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 · 345 | CLAUDE.md | buildteststylearch+6 | 76/100 | today | |
| AzureAD/microsoft-authentication-library-for-objc.clinerules/02-External-tenant-configuration.md · 345 | Cline rules | setupbuildteststyle+7 | 69/100 | 14 days ago | |
| AzureAD/microsoft-authentication-library-for-objc.clinerules/04-Code-style-guidelines.md · 345 | Cline rules | lint-formatstylearchtypes+5 | 73/100 | today | |
| AzureAD/microsoft-authentication-library-for-objc.clinerules/05-feature-gating.md · 345 | Cline rules | stylearchdependenciesperformance+2 | 61/100 | 14 days ago | |
| AzureAD/microsoft-authentication-library-for-objc.clinerules/AGENTS.md · 345 | AGENTS.md | buildteststyleapi+2 | 82/100 | today | |
| AzureAD/microsoft-authentication-library-for-objc.cursor/rules/ruler_cursor_instructions.mdc · 345 | Cursor rules | buildteststylearch+6 | 76/100 | 14 days ago | |
| AzureAD/microsoft-authentication-library-for-objc.github/copilot-instructions.md · 345 | Copilot instructions | setupbuildteststyle+11 | 64/100 | 14 days ago | |
| AzureAD/microsoft-authentication-library-for-objcAGENTS.md · 345 | AGENTS.md | buildteststylearch+6 | 76/100 | 14 days ago | |
| AzureAD/microsoft-authentication-library-for-objc.clinerules/06-Customer-communication-guidelines.md · 345 | Cline rules | stylemonorepodo-notagent-behaviour | 51/100 | 14 days ago | |
| AzureAD/microsoft-authentication-library-for-objc.clinerules/03-MSAL-API-usage.md · 345 | Cline rules | styleapi | 58/100 | 14 days ago |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| JCodesMore/ai-website-cloner-template.clinerules · 32k | Cline rules | buildlint-formatstylearch+3 | 97/100 | 7 days ago | |
| BryaanF/LiantPortfolio.clinerules/project-guidelines.md · 0 | Cline rules | buildstylearchgit+2 | 96/100 | 14 days ago | |
| enuno/unifi-mcp-server.clinerules · 226 | Cline rules | setuptestlint-formatstyle+10 | 96/100 | today | |
| lepinkainen/humanlog.clinerules/project-rules.md · 0 | Cline rules | setupbuildtestlint-format+8 | 96/100 | 14 days ago | |
| u9401066/pubmed-search-mcp.clinerules/50-pubmed-project.md · 25 | Cline rules | testlint-formatstylearch+1 | 94/100 | 14 days ago | |
| u9401066/zotero-keeper.clinerules/50-pubmed-project.md · 6 | Cline rules | testlint-formatstylearch+1 | 94/100 | 14 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 | 14 days ago | |
| VaillerTeeter/HoshimiNest.clinerules/project-identity.md · 1 | Cline rules | setuparchtypesdo-not | 93/100 | 12 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/azuread-microsoft-authentication-library-for-objc-clinerules-01-workforce-tenant-configuration)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.