This document contains comprehensive guidelines for AI agents, development standards, and automation workflows for the Microsoft.Identity.Abstractions repository. These guidelines help ensure consistent code quality, development practices, and effective AI-assisted development.
- Repository Overview
- AI Assistant Guidelines
- C# Development Standards
- Microsoft.Identity.Abstractions Guidelines
- Agent Configuration
Microsoft.Identity.Abstractions is a core authentication and authorization library that provides essential interfaces and base classes for implementing identity and access management in .NET applications. This repository follows specific development and automation standards to maintain high code quality and contributor experience.
- Abstractions and options for applications using Microsoft Entra ID
- Token acquisition options and interfaces
- Credential handling abstractions
- Protocol-agnostic identity concepts
- Make changes incrementally and verify each step
- Always analyze existing code patterns before making changes
- Prioritize built-in tools over shell commands
- Follow existing project patterns and conventions
- Maintain comprehensive test coverage
- Use
read_filefor examining file contents instead of shell commands likecat - Use
replace_in_filefor targeted, specific changes to existing files - Use
write_to_fileonly for new files or complete file rewrites - Use
list_filesto explore directory structures - Use
search_fileswith precise regex patterns to find code patterns - Use
list_code_definition_namesto understand code structure before modifications
- Use
execute_commandsparingly, preferring built-in file operation tools when possible - Always provide clear explanations for any executed commands
- Set
requires_approvalto true for potentially impactful operations
- Begin complex tasks in PLAN mode to discuss approach
- Analyze existing codebase patterns using search tools
- Review related test files to understand testing patterns
- Present clear implementation steps for approval
- Ask clarifying questions early to avoid rework
- Make changes incrementally, one file at a time
- Verify each change before proceeding
- Follow patterns discovered during planning phase
- Focus on maintaining test coverage
- Use error messages and linter feedback to guide fixes
- Follow .editorconfig rules strictly
- Preserve file headers and license information
- Maintain consistent XML documentation
- Respect existing error handling patterns
- Keep line endings consistent with existing files
- Verify changes match existing code style
- Ensure test coverage for new code
- Validate changes against project conventions
- Check for proper error handling
- Maintain nullable reference type annotations
- Use appropriate MCP tools when available for specialized tasks
- Access MCP resources efficiently using proper URIs
- Handle MCP operation results appropriately
- Follow server-specific authentication and usage patterns
- Provide clear error messages and suggestions
- Handle tool operation failures gracefully
- Suggest alternative approaches when primary approach fails
- Roll back changes if necessary to maintain stability
- Always use the latest version C#, currently C# 13 features
- Never change global.json unless explicitly asked to
- Never change package.json or package-lock.json files unless explicitly asked to
- Never change NuGet.config files unless explicitly asked to
- Apply code-formatting style defined in
.editorconfig - Prefer file-scoped namespace declarations and single-line using directives
- Insert a newline before the opening curly brace of any code block (e.g., after
if,for,while,foreach,using,try, etc.) - Ensure that the final return statement of a method is on its own line
- Use pattern matching and switch expressions wherever possible
- Use
nameofinstead of string literals when referring to member names - Ensure that XML doc comments are created for any public APIs. When applicable, include
<example>and<code>documentation in the comments - Use sentence casing for documentation (e.g., "This is a sentence" not "This Is A Sentence")
- Declare variables non-nullable, and check for
nullat entry points - Always use
is nulloris not nullinstead of== nullor!= null - Trust the C# null annotations and don't add null checks when the type system says a value cannot be null
- We use xUnit SDK v2 for tests
- Emit "Act", "Arrange" or "Assert" comments
- Use Moq 4.14.x for mocking in tests
- Copy existing style in nearby files for test method names and capitalization
- To build and run tests in the repo, run
dotnet test, you need one solution open, or specify the solution
Microsoft.Identity.Abstractions is a core authentication and authorization library that provides essential interfaces and base classes for implementing identity and access management in .NET applications. The library specializes in:
- Abstractions and options for applications using Microsoft Entra ID
- Token acquisition options and interfaces
- Credential handling abstractions
- Protocol-agnostic identity concepts
Through its well-designed abstractions and interfaces, Microsoft.Identity.Abstractions enables consistent authentication patterns across different authentication providers and scenarios.
/src- Contains all source code for the Microsoft.Identity.Abstractions package- ApplicationOptions - Options describing the authentication part of applications
- Credentials - Option describing credentials (secrets, certificate, signed assertions)
- TokenAcquisition - Options and interfaces to acquire tokens, and creating Authorization headers
/tests- Unit tests/build- Build configuration and scripts
| I want to... | Look in | Key files |
|---|---|---|
| Understand app configuration options | src/ApplicationOptions/ |
IdentityApplicationOptions.cs, MicrosoftIdentityApplicationOptions.cs |
| Add a new credential source | src/Credentials/ |
CredentialSource.cs (enum), ICredentialSourceLoader.cs (interface) |
| Modify token acquisition | src/TokenAcquisition/ |
ITokenAcquirer.cs, AcquireTokenOptions.cs |
| Change downstream API calling | src/DownstreamApi/ |
IDownstreamApi.cs, DownstreamApiOptions.cs |
| Add HTTP method variants | src/DownstreamApi/ |
IDownstreamApi.HttpMethods.tt (T4 template!) |
| Work with result patterns | src/Results/ |
OperationResult.cs, OperationError.cs |
Do NOT edit directly:
IDownstreamApi.HttpMethods.cs— Generated fromIDownstreamApi.HttpMethods.tt
Edit the T4 template instead, then regenerate.
IdentityApplicationOptions
└── MicrosoftEntraApplicationOptions
└── MicrosoftIdentityApplicationOptions
AuthorizationHeaderProviderOptions
└── DownstreamApiOptions
└── DownstreamApiOptionsReadOnlyHttpMethod
OperationError (abstract)
└── AuthorizationHeaderError
When implementing these interfaces, you must:
| Interface | Contract Requirements |
|---|---|
ITokenAcquirer |
Both GetTokenForUserAsync and GetTokenForAppAsync |
ICredentialSourceLoader |
LoadIfNeededAsync + expose CredentialSource enum value |
ICustomSignedAssertionProvider |
Extends ICredentialSourceLoader, adds Name property |
IDownstreamApi |
~50+ methods (use IDE to implement) |
Context: Credentials can come from many sources (KeyVault, file, managed identity) but are fundamentally only a few types (certificate, secret, signed assertion).
Decision: Two enums:
CredentialSource— where the credential comes fromCredentialType(4 values) — what the credential fundamentally is
Consequence: CredentialDescription.CredentialType is derived from CredentialSource, not set independently.
Context: IDownstreamApi needs methods for every combination of:
- HTTP method (Get, Post, Put, Patch, Delete)
- Token type (User, App)
- Generic parameters (TInput, TOutput, both, neither)
- Framework (all, NET8+ for AOT)
Decision: Use T4 template to generate all combinations (~50+ methods).
Consequence:
- Edit
IDownstreamApi.HttpMethods.tt, not the generated.csfile - Regenerate after changes by saving the
.ttfile or using VS "Run Custom Tool"
Context: Authorization header creation can fail (token errors, network issues). Need clean error handling without exceptions for expected failures.
Decision: Discriminated union pattern via OperationResult<T, E> record struct.
Consequence: Callers check result.Succeeded before accessing result.Result or result.Error.
- CredentialDescription - describes a credential
- MicrosoftIdentityApplicationOptions - describes an application
- ICredentialProvider - Interface to bring your own credential loaders
- ITokenAcquirer - Core interface for token acquisition
- ITokenAcquirerFactory - Factory of Token acquirers
- IAuthorizationHeaderProvider - creates authorization headers (getting tokens and building the protocol string)
- IBoundAuthorizationHeaderProvider - creates authorization headers with token, which is optionally bound to a certififcate
- IDownstreamApi - call downstream APIs in an authenticated way.
- Follow .editorconfig rules strictly
- Design for extensibility and flexibility
- Maintain backward compatibility
- Keep abstractions clean and focused
- Minimize concrete implementations
- Keep interfaces focused and cohesive
- Follow Interface Segregation Principle
- Document interface contracts thoroughly
- Consider extension points
- Maintain consistent naming patterns
- Create purpose-specific abstractions
- Avoid leaking implementation details
- Design for dependency injection
- Support multiple authentication scenarios
- Enable easy testing through abstractions
- Test interface contracts thoroughly
- Include mocked implementations
- Verify extensibility points
- Test configuration patterns
- Validate integration scenarios
- The project uses Microsoft.CodeAnalysis.PublicApiAnalyzers
- For any public and internal API (i.e. public and internal member) changes:
- Update PublicAPI.Unshipped.txt in the relevant package directory for a public API change
- Update InternalAPI.Unshipped.txt in the relevant package directory for an internal API change
- Include complete API signatures
- Consider backward compatibility impacts
- Document breaking changes clearly
- Update the mermaid diagrams in the Readme.md file to reflect the changes to the public API.
Example format:
// Adding new API
+Microsoft.Identity.Abstractions.ITokenAcquirer.GetTokenAsync(TokenRequestContext context) -> System.Threading.Tasks.Task<string>
+Microsoft.Identity.Abstractions.AuthenticationClientOptions.Scopes.get -> System.Collections.Generic.IEnumerable<string>
// Removing API (requires careful consideration)
-Microsoft.Identity.Abstractions.ObsoleteAuthenticationMethod() -> voidThe analyzer enforces documentation of all public API changes in PublicAPI.Unshipped.txt and all internal API changes in InternalAPI.Unshipped.txt and will fail the build if changes are not properly reflected.
# Agent Configuration Metadata
name: "Microsoft.Identity.Abstractions Development Agent"
version: "1.0.0"
description: "AI agent configuration for Microsoft.Identity.Abstractions repository"
repository: "AzureAD/microsoft-identity-abstractions-for-dotnet"
# Supported AI Assistants
supported_assistants:
- name: "GitHub Copilot"
features: ["code_completion", "chat", "pull_request_review"]
- name: "Cline"
features: ["code_analysis", "file_operations", "automated_refactoring"]
# Development Workflow
workflow:
planning_mode: true
incremental_changes: true
test_coverage_required: true
api_analyzer_compliance: true
# Code Quality Standards
quality_standards:
language: "C# 13"
target_frameworks: ["netstandard2.0", "netstandard2.1", "net462", "net8.0", "net9.0"]
nullable_reference_types: true
code_analysis: true
public_api_tracking: true
# Integration Points
integrations:
build_system: "MSBuild"
test_framework: "xUnit"
mocking_framework: "Moq 4.14.x"
package_analyzer: "Microsoft.CodeAnalysis.PublicApiAnalyzers"This document replaces the previous .clinerules directory structure and consolidates all agent rules and development guidelines into a single, comprehensive document. The migration ensures:
- No Loss of Information: All content from the original files has been preserved and organized
- Improved Structure: Guidelines are now organized in logical sections with clear hierarchy
- Enhanced Documentation: Added context and explanations for contributors
- Modern Format: Uses markdown with YAML configuration blocks as recommended by GitHub
- Agent Integration: Provides clear configuration for AI agents and automation tools
.clinerules/abstractions-guidelines.md→ Section: Microsoft.Identity.Abstractions Guidelines.clinerules/ai-guidelines.md→ Section: AI Assistant Guidelines.clinerules/cline-instructions.md→ Section: AI Assistant Guidelines (Cline-specific content).clinerules/csharp-guidelines.md→ Section: C# Development Standards
Please refer to this document for all development guidelines, coding standards, and AI assistant interactions. The guidelines help maintain consistency and quality across the repository while enabling effective AI-assisted development workflows.