Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ab84ec9
Update expected error for auth method blocked
nilo-ms Oct 20, 2025
4b745c2
modified: MSAL/IdentityCore (modified content)
antrix1989 Oct 29, 2025
5a5458a
Merge pull request #2764 from AzureAD/ameyapat/add-bart-support-toggl…
ameyapat Oct 31, 2025
62ce78a
modified: MSAL/IdentityCore
antrix1989 Nov 4, 2025
773205e
Merge branch 'dev' into sedemche/fix_upn
antrix1989 Nov 4, 2025
bff02c1
modified: MSAL/IdentityCore
antrix1989 Nov 5, 2025
d38801c
modified: MSAL/IdentityCore
antrix1989 Nov 5, 2025
af1020a
Merge pull request #2763 from AzureAD/sedemche/fix_upn
antrix1989 Nov 5, 2025
0a6da71
Merge pull request #2754 from AzureAD/danilo/update-blocked-auth-method
nilo-ms Nov 5, 2025
1b2936e
Initial plan
Copilot Nov 6, 2025
46e549d
Update Xcode version from 15.4 to 16.2 in pr-validation.yml
Copilot Nov 6, 2025
36b4d25
Merge pull request #2769 from AzureAD/copilot/update-xcode-version-16-2
ameyapat Nov 6, 2025
2c680fe
Update tests
spetrescu84 Nov 7, 2025
7722f41
Add rules for AI agents: cline, GitHub Copilot, claude & cursor.
juan-arias Nov 7, 2025
ba0b8dc
Merge branch 'dev' into jarias/add_ai_agent_rules
juan-arias Nov 7, 2025
e0789ef
Merge pull request #2771 from AzureAD/spetrescu/update-block-auth-met…
spetrescu84 Nov 10, 2025
05cac10
Merge release 1.17.0 back into dev
josephpab Nov 10, 2025
1345024
Rename to correct file names.
juan-arias Nov 12, 2025
2903d4d
Address PR comments
juan-arias Nov 12, 2025
4cc2264
Update IdentityCore
josephpab Nov 14, 2025
aa3bd32
Merge pull request #2774 from AzureAD/josephpab/merge_release_1.17.0_…
josephpab Nov 14, 2025
221ae4f
Merge pull request #2772 from AzureAD/jarias/add_ai_agent_rules
juan-arias Nov 18, 2025
f427a8e
Fix issue with legacy keychain on macOS.
juan-arias Nov 19, 2025
db635d2
Update MSAL version
juan-arias Nov 20, 2025
9fb4a80
Merge branch 'hotfix/2.4.3' into hotfix/2.5.2
juan-arias Nov 20, 2025
7cbcae8
Merge branch 'dev' into jarias/update-hotfix-2.5.2-to-dev
juan-arias Nov 24, 2025
e82a0a8
Initial plan
Copilot Nov 24, 2025
588bce2
docs: update supported iOS and macOS versions in README.md
Copilot Nov 24, 2025
a4dcc34
Update MSAL iOS test app to support ATS starvation simulation
Nov 25, 2025
3dddc48
Update wording
Nov 25, 2025
54f0e9f
Merge branch 'dev' into kasong/3403740-thread-starvation
Nov 25, 2025
346347b
Update MSAL/test/app/ios/MSALTestAppAcquireTokenViewController.storyb…
kaisong1990 Nov 25, 2025
0b81760
Update MSAL/test/app/ios/MSALTestAppAcquireTokenViewController.m
kaisong1990 Nov 25, 2025
de91c0f
Update MSAL/test/app/ios/MSALTestAppAcquireTokenViewController.m
kaisong1990 Nov 25, 2025
6a76032
Merge pull request #2786 from AzureAD/kasong/3403740-thread-starvation
kaisong1990 Nov 25, 2025
d7f51cb
Merge branch 'dev' into copilot/update-ios-macos-version-docs
juan-arias Nov 25, 2025
ce889e9
Merge branch 'dev' into jarias/update-hotfix-2.5.2-to-dev
juan-arias Nov 25, 2025
4f5706b
Merge pull request #2783 from AzureAD/jarias/update-hotfix-2.5.2-to-dev
juan-arias Nov 26, 2025
1cbeceb
Merge pull request #2784 from AzureAD/copilot/update-ios-macos-versio…
juan-arias Nov 26, 2025
b443e30
Use autolayout in sample app.
antrix1989 Nov 27, 2025
55fd93a
Merge pull request #2787 from AzureAD/sedemche/fix_loading_indicator
antrix1989 Dec 2, 2025
370547a
modified: MSAL/IdentityCore
antrix1989 Dec 2, 2025
87bb76f
Merge pull request #2791 from AzureAD/sedemche/update_msal
antrix1989 Dec 2, 2025
a1579bc
Update release branch
Dec 2, 2025
864f9ab
update ios support version to v16 in Package.swift
Dec 4, 2025
42e29e7
Update macOS to v11
Dec 4, 2025
7ca0b63
Update swift-tools-version
Dec 4, 2025
70a3bf3
Merge pull request #2793 from AzureAD/kasong/270-patch
kaisong1990 Dec 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
306 changes: 306 additions & 0 deletions .clinerules/01-Workforce-tenant-configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
# Agent Instructions: Create iOS/macOS Sample Application with Microsoft Entra ID - Workforce configuration

## Overview

These 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.

## Prerequisites

Before starting, ensure the following requirements are met:

### Azure Requirements

- Active Azure subscription with an active account
- Permissions to manage applications (requires one of these roles):
- Application Administrator
- Application Developer
- A workforce tenant (or create a new tenant)

### Development Environment

- **iOS**: Version 16 or higher (for iOS apps)
- **macOS**: Version 11 or higher (for macOS apps)
- **CocoaPods**: For dependency management

### Pre-Configuration

- Register a new application in the Microsoft Entra admin center
- Configure for "Accounts in this organizational directory only"
- Record the following values from the application Overview page:
- **Application (client) ID**
- **Directory (tenant) ID**

## Step 1: Register Application in Microsoft Entra Admin Center

### 1.1 Create App Registration

1. Navigate to the [Microsoft Entra admin center](https://entra.microsoft.com)
2. Select **Applications** > **App registrations** > **New registration**
3. Enter a name for your application
4. Select "Accounts in this organizational directory only" as the supported account types
5. Click **Register**
6. Save the **Application (client) ID** and **Directory (tenant) ID** from the Overview page

### 1.2 Configure Platform (iOS/macOS)

1. Under **Manage**, select **Authentication** > **Add Platform** > **iOS/macOS**
2. Enter your **Bundle Identifier** (e.g., `com.<yourname>.identitysample.MSALMacOS`)
- Note: This is a unique string that identifies your application
- The iOS configuration also applies to macOS applications
3. Click **Configure** and save the **MSAL Configuration** details
4. Click **Done**

### 1.3 Enable Public Client Flow

1. Under **Manage**, select **Authentication**
2. Scroll to **Advanced settings**
3. For **Allow public client flows**, select **Yes**
4. Click **Save**

## Step 2: Download Sample Code

### 2.1 Download the Project

Choose the appropriate sample based on your target platform:

**For iOS:**

```bash
curl -L https://github.com/Azure-Samples/active-directory-ios-swift-native-v2/archive/master.zip -o ios-sample.zip
unzip ios-sample.zip
cd active-directory-ios-swift-native-v2-master
```

**For macOS:**

```bash
curl -L https://github.com/Azure-Samples/active-directory-macOS-swift-native-v2/archive/master.zip -o macos-sample.zip
unzip macos-sample.zip
cd active-directory-macOS-swift-native-v2-master
```

## Step 3: Install Dependencies

### 3.1 Install MSAL Library

1. Open Terminal and navigate to the project directory
2. Run CocoaPods to install the Microsoft Authentication Library (MSAL):
```bash
pod install
```
3. Wait for the installation to complete

### 3.2 Open Workspace

After pod installation, open the `.xcworkspace` file (NOT the `.xcodeproj` file):

```bash
open *.xcworkspace
```

## Step 4: Configure the Application

### 4.1 Update ViewController.swift

1. In Xcode, open the project navigator
2. Locate and open **ViewController.swift**
3. Find the line starting with `let kClientID` and replace it with your Application (client) ID:

```swift
let kClientID = "YOUR_APPLICATION_CLIENT_ID_HERE"
```

### 4.2 Configure Endpoints

For standard Microsoft Entra ID (global access), use default values:

```swift
let kGraphEndpoint = "https://graph.microsoft.com/"
let kAuthority = "https://login.microsoftonline.com/common"
```

**For national clouds** (if applicable):

- **Microsoft Entra Germany:**

```swift
let kGraphEndpoint = "https://graph.microsoft.de/"
let kAuthority = "https://login.microsoftonline.de/common"
```

See [Microsoft Graph deployments documentation](https://learn.microsoft.com/en-us/graph/deployments#app-registration-and-token-service-root-endpoints) for other endpoints.

### 4.3 Configure Bundle Identifier

1. In Xcode, select the project in the navigator
2. Select your target
3. Go to the **General** tab
4. In the **Identity** section, set the **Bundle Identifier** to match what you registered in the Azure portal

### 4.4 Update Info.plist

1. Right-click **Info.plist** in the project navigator
2. Select **Open As** > **Source Code**
3. Find the `CFBundleURLTypes` section under the dict root node
4. Replace `Enter_the_Bundle_Id_Here` with your Bundle Identifier
5. Note: Keep the `msauth.` prefix in the string

```xml
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>msauth.YOUR_BUNDLE_IDENTIFIER_HERE</string>
</array>
</dict>
</array>
```

## Step 5: Build and Run the Application

### 5.1 Build the Project

1. Select your target device or simulator from the scheme selector
2. Click the **Build** button (⌘+B) or select **Product** > **Build**
3. Verify there are no build errors

### 5.2 Run the Application

1. Select **Product** > **Run** from the menu (or press ⌘+R)
2. The app will launch in the simulator or on your connected device

### 5.3 Test Authentication

1. When the app launches, you'll see the main interface
2. Click **Sign In** or **Acquire Token Interactively**
3. You'll be prompted to enter your credentials
4. After successful authentication, the app will display user information
5. The app can now make authenticated calls to Microsoft Graph API

## Step 6: Understanding the Code Flow

### Authentication Flow Diagram

```
User clicks "Sign In"
App initiates MSAL authentication
Browser/Web view opens with Microsoft login
User enters credentials
Microsoft Entra ID validates credentials
Redirect back to app with authorization code
MSAL exchanges code for access token
App receives access token
App can call Microsoft Graph API
```

### Key Components

- **MSAL Library**: Handles authentication and token management
- **ViewController**: Main UI and authentication logic
- **Microsoft Graph API**: Provides access to user data and resources
- **Access Token**: JWT token used to authenticate API calls

## Step 7: Testing the Application

### 7.1 Interactive Sign-In

Test the interactive authentication flow:

1. Launch the app
2. Click **Acquire Token Interactively**
3. Enter valid test credentials
4. Verify successful sign-in
5. Check that user information is displayed

### 7.2 Silent Token Acquisition

Test silent token refresh:

1. After initial sign-in, click **Acquire Token Silently**
2. Verify token is obtained without user interaction
3. This uses cached refresh tokens

### 7.3 Microsoft Graph API Call

Test API access:

1. Click **Get Graph Data Interactively** or **Get Graph Data Silently**
2. Verify the app successfully calls Microsoft Graph API
3. Check that user profile data is displayed

## Step 8: Common Configuration Issues

### Issue: "Redirect URI mismatch"

- **Solution**: Verify Bundle Identifier in Info.plist matches Azure portal configuration
- Ensure `msauth.` prefix is included in the redirect URI

### Issue: "Invalid client"

- **Solution**: Double-check Application (client) ID in ViewController.swift
- Ensure no extra spaces or characters

### Issue: "Pod install fails"

- **Solution**: Update CocoaPods: `sudo gem install cocoapods`
- Clear pod cache: `pod cache clean --all`
- Try again: `pod install`

### Issue: "Build fails with MSAL errors"

- **Solution**: Ensure you opened the `.xcworkspace` file, not `.xcodeproj`
- Clean build folder: **Product** > **Clean Build Folder** (⇧⌘K)

## Step 9: Next Steps

After successfully building and running the sample:

### For iOS Applications

- 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)
- Implement additional Microsoft Graph API calls
- Add custom UI and branding
- Implement token caching strategies

### For macOS Applications

- 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)
- Implement additional application features
- Add keychain integration for secure token storage

### General Enhancements

- Implement error handling and retry logic
- Add logging and telemetry
- Configure additional API scopes
- Implement sign-out functionality
- Add multi-account support

## Additional Resources

- **MSAL Documentation**: [Microsoft Authentication Library for iOS and macOS](https://github.com/AzureAD/microsoft-authentication-library-for-objc)
- **Microsoft Graph API**: [Microsoft Graph REST API reference](https://learn.microsoft.com/en-us/graph/api/overview)
- **Authentication Flows**: [OAuth 2.0 and OpenID Connect protocols](https://learn.microsoft.com/en-us/entra/identity-platform/v2-protocols)
- **Best Practices**: [Security best practices for application developers](https://learn.microsoft.com/en-us/entra/identity-platform/identity-platform-integration-checklist)

## Security Considerations

1. **Never hardcode secrets**: Use secure storage mechanisms
2. **Validate tokens**: Always validate tokens server-side for API calls
3. **Use HTTPS**: Ensure all network communication uses HTTPS
4. **Minimal scopes**: Request only the minimum required API scopes
5. **Token expiration**: Handle token expiration and refresh appropriately
6. **Secure storage**: Use iOS Keychain or macOS Keychain for sensitive data

---

**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)
Loading
Loading