# Claude Instructions for MSAL iOS/macOS

## Repository Overview

This is the **Microsoft Authentication Library (MSAL) for iOS and macOS** - an authentication SDK for integrating Microsoft identity platform authentication into native Apple applications. The library supports OAuth2/OpenID Connect protocols for Microsoft Entra ID (workforce), External ID (customers), Azure AD B2C, and personal Microsoft accounts.

**Key Facts:**

- **Languages:** Objective-C (primary), Swift (native auth APIs)
- **Platforms:** iOS 16+, macOS 11+, visionOS 1.2+
- **Distribution:** CocoaPods, Carthage, Swift Package Manager, Git submodule
- **Submodule:** `MSAL/IdentityCore` contains shared common code (do NOT make direct changes without understanding impact)

## Critical: Architecture & Project Structure

### Main Workspace & Targets

- **Workspace:** `MSAL.xcworkspace` (ALWAYS use .xcworkspace, NEVER .xcodeproj directly)
- **Main Project:** `MSAL/MSAL.xcodeproj`
- **Submodule:** `MSAL/IdentityCore` - shared common library (git submodule)

### Source Code Organization

```
MSAL/src/
├── public/              # Public API headers (MSAL prefix)
│   ├── MSAL.h          # Main umbrella header
│   ├── ios/            # iOS-specific public headers
│   ├── mac/            # macOS-specific public headers
│   ├── configuration/  # Configuration classes
│   └── native_auth/public/  # Native auth public APIs (Swift)
├── MSALPublicClientApplication.m  # Main SDK entry point
├── configuration/      # Internal configuration
├── instance/          # Authority/instance handling
├── native_auth/       # Native authentication (Swift + Obj-C bridge)
├── telemetry/         # Telemetry implementation
└── util/              # Utilities
```

### Public API Files

Public headers MUST be in:

- `MSAL/src/public/*.h` (shared)
- `MSAL/src/public/ios/*.h` (iOS only)
- `MSAL/src/public/mac/*.h` (macOS only)
- `MSAL/src/public/configuration/*.h` (config classes)
- `MSAL/src/native_auth/public/` (native auth - Swift)

### Configuration Files

- **Build configs:** `MSAL/xcconfig/*.xcconfig` - Xcode build settings
- **Swift lint:** `MSAL/.swiftlint.yml` - only applies to `src/native_auth`
- **CocoaPods:** `MSAL.podspec` - pod spec with `app-lib` and `native-auth` subspecs
- **Swift PM:** `Package.swift` - binary framework distribution
- **Privacy:** `MSAL/PrivacyInfo.xcprivacy` - Apple privacy manifest

## Testing

**Unit Tests:** Located in `MSAL/test/unit/`
**Integration Tests:** Located in `MSAL/test/integration/`
**Automation Tests:** Located in `MSAL/test/automation/` (requires conf.json - not in repo)

**Running Tests:**

- Via Xcode: Select scheme and Cmd+U
- E2E tests require test configuration from Azure KeyVault (CI only)

## Code Style Guidelines

**READ:** `.clinerules/04-Code-style-guidelines.md` - Contains mandatory Objective-C style rules

**Key Rules (Repository-Specific):**

1. **Opening braces on NEW line** (differs from most Obj-C guides)
2. **4-space indentation** (never tabs)
3. **Imports NOT grouped** - list without organizing comments
4. **Error handling:** Check return value, NEVER the error variable directly
5. **Prefixes:** `MSAL` for public classes, `MSID` for IdentityCore internal
6. **Properties over ivars:** Use `@property` declarations
7. **Swift lint:** Native auth code must pass SwiftLint (line length: 150)
8. **Comments:** Only comment non-obvious rationale. Don't add comments that explain what the code already explains.

**Example:**

```objc
- (BOOL)performOperationWithError:(NSError **)error
{
    NSError *internalError = nil;
    BOOL result = [self doSomethingWithError:&internalError];
    
    if (!result)  // Check return value, not error
    {
        if (error) *error = internalError;
        return NO;
    }
    
    return YES;
}
```

## Making Changes

### Adding New Public API

1. Add header to appropriate `MSAL/src/public/` subdirectory
2. Import in `MSAL/src/public/MSAL.h` umbrella header
3. Update `MSAL.podspec` if needed (public_header_files)
4. Add to `MSAL/module.modulemap` if using native auth subspec
5. Document in header comments (Jazzy-compatible)

### Modifying Build Settings

1. Edit appropriate `.xcconfig` file in `MSAL/xcconfig/`
2. Settings cascade: specific → platform → common
3. Test both Debug and Release configurations

### Adding Dependencies

**Internal:** Avoid. This library should be self-contained.
**External (IdentityCore):** Coordinate with common library team.

### Modifying IdentityCore Submodule

1. Make changes in IdentityCore repo separately
2. Update submodule reference: `cd MSAL/IdentityCore && git checkout <commit>`
3. Commit submodule update in MSAL repo
4. Test thoroughly - affects BOTH MSAL and ADAL

## Key Files to Never Modify

- `MSAL/IdentityCore/` - managed as submodule
- `Package.swift` - auto-generated by release process
- `MSAL.zip` - binary distribution artifact
- `build/` - build artifacts directory
- `.xcuserdata/` - user-specific Xcode settings

## Trust These Instructions

These instructions have been validated against the actual build system, CI pipelines, and codebase structure. If you encounter conflicts between these instructions and other information:

1. **Trust these instructions FIRST**
2. Only search for additional information if:
   - Instructions are incomplete for your specific task
   - You encounter an error not covered here
   - You need API usage examples (see `.clinerules/03-MSAL-API-usage.md` for MSAL API samples)
   - You need to create a new application with MSAL authentication (see `.clinerules/AGENTS.md` for details about the different options the user can select)
   - You are implementing a new feature in MSAL library, it needs to be guarded by a feature flag (see `.clinerules/05-feature-gating.md` for guidelines)

**When searching:**

- Check `.clinerules/*.md` for code style specifics, API usage, configuration steps and feature flag guidance.
- Check `README.md` for user-facing documentation
- Check `CHANGELOG.md` for version history and breaking changes
- Check specific xcconfig files for build settings
