Skip to content

Commit 277e75e

Browse files
authored
Merge branch 'main' into ping-identity-home-account-refresh
2 parents c994042 + cb59f84 commit 277e75e

621 files changed

Lines changed: 15815 additions & 78009 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/copilot-instructions.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,67 @@
1+
# Code Review Rules
2+
3+
These rules apply to Copilot code review. Read all rules before commenting.
4+
5+
## Review scope
6+
7+
- Only comment on lines added or modified in the PR diff
8+
- Do not comment on pre-existing code unless the PR directly introduces the issue
9+
- Do not comment on style, formatting, or indentation
10+
- Focus exclusively on: bugs, security issues, logic errors, API contract violations
11+
- If unsure whether something is a bug, do not comment
12+
- Prefer no comment over a speculative comment
13+
- Do not re-post a comment already made on an earlier commit in the same PR
14+
15+
## Repo-specific patterns — do NOT flag these
16+
17+
These patterns are correct in this repo. Do not suggest changes:
18+
19+
- `[RunOn]` inherits from `TestMethodAttribute`. Do not flag as missing `[TestMethod]`
20+
- `Client.AppConfig.X` resolves via parent namespace `Microsoft.Identity`. Do not flag as unresolved namespace
21+
- `Assert.IsTrue(bool?)` is a valid MSTest overload. Do not flag nullable bool as a type mismatch
22+
- `Assert.DoesNotContain(substring, value)` — MSTest v4 signature is substring first, value second
23+
- `ConfigureAwait(false)` is intentional in library code. Do not suggest removal
24+
25+
## ConcurrentDictionary.GetOrAdd — always use factory delegate
26+
27+
`GetOrAdd(key, value)` eagerly evaluates the value arg. Flag any call where the second argument is not a delegate/lambda/method group:
28+
29+
- Bad: `pool.GetOrAdd(key, new ExpensiveObject());`
30+
- Good: `pool.GetOrAdd(key, _ => new ExpensiveObject());`
31+
32+
## C# coding standards
33+
34+
- Use `is null` / `is not null` instead of `== null` / `!= null`
35+
- No reflection in product code (`/src`). Acceptable in tests
36+
- Static fields: `s_camelCase` (e.g., `s_knownHosts`)
37+
- Ordinal string comparisons for protocol values, identifiers, cache keys
38+
- Validate inputs at method boundaries (fail fast with specific exception types)
39+
- Do not include secrets/tokens/PII in exception messages or logs
40+
- Use `nameof` instead of string literals for member names
41+
42+
## Testing standards
43+
44+
- MSTest SDK v4 with NSubstitute for mocking
45+
- Use `// Arrange`, `// Act`, `// Assert` comments
46+
- Prefer deterministic tests (no timing flakiness)
47+
48+
## Public API changes
49+
50+
- Update `PublicAPI.Unshipped.txt` for any public API additions/removals
51+
- XML doc comments required on all public APIs
52+
- Maintain backward compatibility
53+
54+
## MSAL-specific rules
55+
56+
- Use certificate-based auth over client secrets when possible
57+
- Use async APIs consistently
58+
- Keep dependencies minimal and well-justified
59+
60+
---
61+
62+
<!-- Everything below this line is for Copilot Chat and Copilot Agent only. -->
63+
<!-- Copilot code review reads only the first 4,000 characters of this file. -->
64+
165
Carefully review all markdown documents in the ../.clinerules folder. Those are your custom instructions.
266

367
---
@@ -45,18 +109,24 @@ Copilot will automatically reference and describe:
45109
- `@msal-mtls-pop-guidance` - Foundational concepts
46110
- `@msal-mtls-pop-vanilla` - Direct token acquisition
47111
- `@msal-mtls-pop-fic-two-leg` - Token exchange patterns
112+
- `@msal-auth-code-flow` - Authorization Code Flow
113+
- `@msal-client-credentials` - Client Credentials Flow
114+
- `@msal-obo-flow` - On-Behalf-Of Flow
48115

49116
---
50117

51118
## 📚 Available Skills Overview
52119

53-
This repository contains **three GitHub Agent Skills** for mTLS Proof-of-Possession (PoP) authentication:
120+
This repository contains **six GitHub Agent Skills** for MSAL.NET authentication:
54121

55122
| Skill | Purpose | Best For |
56123
|-------|---------|----------|
57124
| **@msal-mtls-pop-guidance** | Foundational concepts, terminology, decision frameworks | Learning the fundamentals, comparing approaches |
58125
| **@msal-mtls-pop-vanilla** | Direct single-step token acquisition with complete code | Quick implementation with MSI or Confidential Client |
59126
| **@msal-mtls-pop-fic-two-leg** | Two-step token exchange patterns | Complex scenarios requiring token exchange |
127+
| **@msal-auth-code-flow** | Authorization Code Flow for web apps | User sign-in with server-side backend |
128+
| **@msal-client-credentials** | Client Credentials Flow for daemons | Service-to-service, no user context |
129+
| **@msal-obo-flow** | On-Behalf-Of Flow for multi-tier APIs | Propagating user identity through API chain |
60130

61131
---
62132

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Source code review rules
2+
3+
Applies to: src/**/*.cs
4+
5+
These rules apply when reviewing production source code in this repository.
6+
7+
## Namespace resolution — do NOT flag
8+
9+
- `Client.AppConfig.X`, `Client.Internal.X`, and similar short namespace references resolve via parent namespace `Microsoft.Identity`. Do not flag as unresolved.
10+
11+
## ConcurrentDictionary.GetOrAdd
12+
13+
`GetOrAdd(key, value)` eagerly evaluates the value argument. Flag any call where the second argument is not a delegate/lambda/method group:
14+
15+
- Bad: `pool.GetOrAdd(key, new ExpensiveObject());`
16+
- Good: `pool.GetOrAdd(key, _ => new ExpensiveObject());`
17+
18+
## `ConfigureAwait(false)`
19+
20+
`ConfigureAwait(false)` is intentional in library code. Do not suggest removal.
21+
22+
## Public API changes
23+
24+
- Any public API additions or removals must be reflected in `PublicAPI.Unshipped.txt`
25+
- XML doc comments are required on all public APIs
26+
- Maintain backward compatibility — breaking changes require explicit justification
27+
28+
## MSAL-specific
29+
30+
- Keep dependencies minimal and well-justified
31+
32+
## Scope
33+
34+
- Only comment on source code added or modified in the PR diff
35+
- Do not comment on pre-existing code unless the PR directly introduces the issue
36+
- Do not comment on style or formatting — coding standards are enforced via .editorconfig
37+
- Focus on: bugs, security issues, logic errors, API contract violations
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Test file review rules
2+
3+
Applies to: tests/**/*.cs
4+
5+
These rules apply when reviewing test files in this repository.
6+
7+
## Test framework patterns — do NOT flag
8+
9+
- `[RunOn]` inherits from `TestMethodAttribute` (see `tests/Microsoft.Identity.Test.Integration.netcore/Infrastructure/TargetFramework.cs` line 15). Tests decorated with `[RunOn]` WILL be discovered by MSTest. Do not flag as missing `[TestMethod]`.
10+
- `Assert.IsTrue(bool?)` is a valid MSTest overload. Do not flag nullable bool arguments as type mismatches.
11+
- `Assert.DoesNotContain(substring, value)` — in MSTest v4, the first argument is the substring and the second is the value to search. Do not suggest swapping arguments.
12+
- `Assert.HasCount(expected, collection)` — valid MSTest v4 assertion. Do not suggest `Assert.AreEqual` for count checks.
13+
14+
## Test conventions
15+
16+
- Use MSTest SDK v4 with NSubstitute for mocking
17+
- Use `// Arrange`, `// Act`, `// Assert` comments
18+
- Prefer deterministic tests: avoid `Thread.Sleep`, timing dependencies, or environment-specific behavior
19+
- Copy existing style in nearby files for test method names
20+
21+
## Scope
22+
23+
- Only comment on test code that is added or modified in the PR diff
24+
- Do not comment on pre-existing test patterns or style
25+
- Do not re-post comments already made on earlier commits

.github/skills/README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ GitHub Copilot Agent Skills are specialized knowledge modules that help Copilot
1313

1414
## Available Skills
1515

16-
### 1. Confidential Client Authentication (`msal-confidential-auth/`)
16+
### 1. Confidential Client Authentication
1717

18-
A comprehensive skill set for confidential client authentication patterns in MSAL.NET, covering three core flows with granularized, reusable credential setup patterns.
18+
Three individual skills for confidential client authentication patterns in MSAL.NET, with reusable credential setup patterns in `msal-shared/`.
1919

2020
#### Authentication Flows
2121

22-
- **[Authorization Code Flow](msal-confidential-auth/auth-code-flow/SKILL.md)** - Web applications with user sign-in
23-
- **[On-Behalf-Of (OBO) Flow](msal-confidential-auth/obo-flow/SKILL.md)** - Multi-tier services acting on behalf of users
24-
- **[Client Credentials Flow](msal-confidential-auth/client-credentials/SKILL.md)** - Service-to-service daemon applications
22+
- **[Authorization Code Flow](msal-auth-code-flow/SKILL.md)** - Web applications with user sign-in
23+
- **[On-Behalf-Of (OBO) Flow](msal-obo-flow/SKILL.md)** - Multi-tier services acting on behalf of users
24+
- **[Client Credentials Flow](msal-client-credentials/SKILL.md)** - Service-to-service daemon applications
2525

2626
#### Shared Resources (DRY Principle)
2727

@@ -141,9 +141,9 @@ Specialized skills for mTLS PoP authentication with Managed Identity and Confide
141141

142142
| Scenario | Skill to Use |
143143
|----------|--------------|
144-
| Web app with user sign-in | [Authorization Code Flow](msal-confidential-auth/auth-code-flow/SKILL.md) |
145-
| API acting on behalf of user | [On-Behalf-Of Flow](msal-confidential-auth/obo-flow/SKILL.md) |
146-
| Daemon/background service | [Client Credentials Flow](msal-confidential-auth/client-credentials/SKILL.md) |
144+
| Web app with user sign-in | [Authorization Code Flow](msal-auth-code-flow/SKILL.md) |
145+
| API acting on behalf of user | [On-Behalf-Of Flow](msal-obo-flow/SKILL.md) |
146+
| Daemon/background service | [Client Credentials Flow](msal-client-credentials/SKILL.md) |
147147
| Direct mTLS PoP token (MSI/SNI) | [Vanilla mTLS PoP](msal-mtls-pop-vanilla/SKILL.md) |
148148
| FIC token exchange with mTLS PoP | [FIC Two-Leg mTLS PoP](msal-mtls-pop-fic-two-leg/SKILL.md) |
149149

@@ -235,11 +235,12 @@ skill-name/
235235
│ ├── code-examples/ # Copy-paste code snippets
236236
│ ├── credential-setup/ # Setup guides by credential type
237237
│ └── patterns/ # Common patterns, troubleshooting
238-
├── skill-set-name/
239-
│ ├── flow1/
240-
│ │ └── SKILL.md # Flow-specific documentation
241-
│ └── flow2/
242-
│ └── SKILL.md
238+
├── msal-auth-code-flow/
239+
│ └── SKILL.md # Auth Code Flow skill
240+
├── msal-client-credentials/
241+
│ └── SKILL.md # Client Credentials Flow skill
242+
├── msal-obo-flow/
243+
│ └── SKILL.md # OBO Flow skill
243244
└── individual-skill-name/
244245
├── SKILL.md # Main documentation with YAML frontmatter
245246
└── HelperClass.cs # Optional production helper class

.github/skills/msal-confidential-auth/auth-code-flow/SKILL.md renamed to .github/skills/msal-auth-code-flow/SKILL.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
---
2+
name: msal-auth-code-flow
3+
description: Authorization Code Flow for web applications using MSAL.NET confidential client to sign in users and access APIs on their behalf
4+
tags:
5+
- msal
6+
- auth-code
7+
- authorization-code
8+
- web-app
9+
- confidential-client
10+
- user-sign-in
11+
- redirect
12+
- consent
13+
---
14+
115
# Authorization Code Flow Skill
216

317
## Overview
@@ -20,15 +34,15 @@ Authorization Code Flow is used by web applications to authenticate users and ob
2034

2135
### Generate Code Snippet
2236
Agent can show code snippets for each credential type:
23-
- Standard Certificate: [with-certificate.cs](../../msal-shared/code-examples/with-certificate.cs)
24-
- Certificate with SNI: [with-certificate-sni.cs](../../msal-shared/code-examples/with-certificate-sni.cs)
25-
- Federated Identity Credentials: [with-federated-identity-credentials.cs](../../msal-shared/code-examples/with-federated-identity-credentials.cs)
37+
- Standard Certificate: [with-certificate.cs](../msal-shared/code-examples/with-certificate.cs)
38+
- Certificate with SNI: [with-certificate-sni.cs](../msal-shared/code-examples/with-certificate-sni.cs)
39+
- Federated Identity Credentials: [with-federated-identity-credentials.cs](../msal-shared/code-examples/with-federated-identity-credentials.cs)
2640

2741
### Setup Guidance
2842
Reference appropriate credential setup:
29-
- [Certificate Setup](../../msal-shared/credential-setup/certificate-setup.md)
30-
- [Certificate with SNI](../../msal-shared/credential-setup/certificate-sni-setup.md)
31-
- [Federated Identity Credentials](../../msal-shared/credential-setup/federated-identity-credentials.md)
43+
- [Certificate Setup](../msal-shared/credential-setup/certificate-setup.md)
44+
- [Certificate with SNI](../msal-shared/credential-setup/certificate-sni-setup.md)
45+
- [Federated Identity Credentials](../msal-shared/credential-setup/federated-identity-credentials.md)
3246

3347
### Example: Web Application with Certificate
3448
```csharp
@@ -54,11 +68,11 @@ public async Task HandleCallback(string code, string state)
5468
```
5569

5670
### Error Resolution
57-
Refer to [Troubleshooting Guide](../../msal-shared/patterns/troubleshooting.md)
71+
Refer to [Troubleshooting Guide](../msal-shared/patterns/troubleshooting.md)
5872

5973
### Best Practices
60-
- Use [Token Caching Strategies](../../msal-shared/patterns/token-caching-strategies.md) for optimal token acquisition
61-
- Implement [Error Handling Patterns](../../msal-shared/patterns/error-handling-patterns.md)
74+
- Use [Token Caching Strategies](../msal-shared/patterns/token-caching-strategies.md) for optimal token acquisition
75+
- Implement [Error Handling Patterns](../msal-shared/patterns/error-handling-patterns.md)
6276
- Store refresh tokens securely
6377
- Use PKCE for native clients
6478
- For advanced caching options including distributed caches for multi-instance deployments, see [Token cache serialization documentation](https://learn.microsoft.com/en-us/entra/msal/dotnet/how-to/token-cache-serialization?tabs=msal)

.github/skills/msal-confidential-auth/client-credentials/SKILL.md renamed to .github/skills/msal-client-credentials/SKILL.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
---
2+
name: msal-client-credentials
3+
description: Client Credentials Flow for service-to-service (daemon) authentication in MSAL.NET without user involvement
4+
tags:
5+
- msal
6+
- client-credentials
7+
- daemon
8+
- service-to-service
9+
- confidential-client
10+
- background-service
11+
- machine-to-machine
12+
---
13+
114
# Client Credentials Flow Skill
215

316
## Overview
@@ -20,15 +33,15 @@ Client Credentials Flow is used for service-to-service authentication without us
2033

2134
### Generate Code Snippet
2235
Agent can show code for each credential type:
23-
- Standard Certificate: [with-certificate.cs](../../msal-shared/code-examples/with-certificate.cs)
24-
- Certificate with SNI: [with-certificate-sni.cs](../../msal-shared/code-examples/with-certificate-sni.cs)
25-
- Federated Identity Credentials: [with-federated-identity-credentials.cs](../../msal-shared/code-examples/with-federated-identity-credentials.cs)
36+
- Standard Certificate: [with-certificate.cs](../msal-shared/code-examples/with-certificate.cs)
37+
- Certificate with SNI: [with-certificate-sni.cs](../msal-shared/code-examples/with-certificate-sni.cs)
38+
- Federated Identity Credentials: [with-federated-identity-credentials.cs](../msal-shared/code-examples/with-federated-identity-credentials.cs)
2639

2740
### Setup Guidance
2841
Reference appropriate credential setup:
29-
- [Certificate Setup](../../msal-shared/credential-setup/certificate-setup.md)
30-
- [Certificate with SNI](../../msal-shared/credential-setup/certificate-sni-setup.md)
31-
- [Federated Identity Credentials](../../msal-shared/credential-setup/federated-identity-credentials.md)
42+
- [Certificate Setup](../msal-shared/credential-setup/certificate-setup.md)
43+
- [Certificate with SNI](../msal-shared/credential-setup/certificate-sni-setup.md)
44+
- [Federated Identity Credentials](../msal-shared/credential-setup/federated-identity-credentials.md)
3245

3346
### Example: Service with Certificate
3447
```csharp
@@ -60,11 +73,11 @@ public class TokenAcquisitionService
6073
```
6174

6275
### Error Resolution
63-
Refer to [Troubleshooting Guide](../../msal-shared/patterns/troubleshooting.md)
76+
Refer to [Troubleshooting Guide](../msal-shared/patterns/troubleshooting.md)
6477

6578
### Best Practices
66-
- Use [Token Caching Strategies](../../msal-shared/patterns/token-caching-strategies.md) - enable static token caching with `.WithCacheOptions(CacheOptions.EnableSharedCacheOptions)` for optimal performance
67-
- Implement [Error Handling Patterns](../../msal-shared/patterns/error-handling-patterns.md)
79+
- Use [Token Caching Strategies](../msal-shared/patterns/token-caching-strategies.md) - enable static token caching with `.WithCacheOptions(CacheOptions.EnableSharedCacheOptions)` for optimal performance
80+
- Implement [Error Handling Patterns](../msal-shared/patterns/error-handling-patterns.md)
6881
- Monitor token acquisition using `AuthenticationResultMetadata` for cache hit ratios
6982
- Rotate certificates periodically (if using certificate-based auth)
7083
- Use Federated Identity Credentials with Managed Identity for keyless authentication

.github/skills/msal-confidential-auth/obo-flow/SKILL.md renamed to .github/skills/msal-obo-flow/SKILL.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
---
2+
name: msal-obo-flow
3+
description: On-Behalf-Of (OBO) Flow for web APIs to call downstream APIs while preserving user identity in MSAL.NET
4+
tags:
5+
- msal
6+
- obo
7+
- on-behalf-of
8+
- token-exchange
9+
- confidential-client
10+
- multi-tier
11+
- downstream-api
12+
- user-assertion
13+
---
14+
115
# On-Behalf-Of (OBO) Flow Skill
216

317
## Overview
@@ -23,15 +37,15 @@ ID tokens are for authentication; access tokens are for authorization and API ac
2337

2438
### Generate Code Snippet
2539
Agent can show code for each credential type:
26-
- Standard Certificate: [with-certificate.cs](../../msal-shared/code-examples/with-certificate.cs)
27-
- Certificate with SNI: [with-certificate-sni.cs](../../msal-shared/code-examples/with-certificate-sni.cs)
28-
- Federated Identity Credentials: [with-federated-identity-credentials.cs](../../msal-shared/code-examples/with-federated-identity-credentials.cs)
40+
- Standard Certificate: [with-certificate.cs](../msal-shared/code-examples/with-certificate.cs)
41+
- Certificate with SNI: [with-certificate-sni.cs](../msal-shared/code-examples/with-certificate-sni.cs)
42+
- Federated Identity Credentials: [with-federated-identity-credentials.cs](../msal-shared/code-examples/with-federated-identity-credentials.cs)
2943

3044
### Setup Guidance
3145
Reference appropriate credential setup:
32-
- [Certificate Setup](../../msal-shared/credential-setup/certificate-setup.md)
33-
- [Certificate with SNI](../../msal-shared/credential-setup/certificate-sni-setup.md)
34-
- [Federated Identity Credentials](../../msal-shared/credential-setup/federated-identity-credentials.md)
46+
- [Certificate Setup](../msal-shared/credential-setup/certificate-setup.md)
47+
- [Certificate with SNI](../msal-shared/credential-setup/certificate-sni-setup.md)
48+
- [Federated Identity Credentials](../msal-shared/credential-setup/federated-identity-credentials.md)
3549

3650
### Example: Web API with Certificate
3751
```csharp
@@ -64,15 +78,15 @@ public async Task<IActionResult> GetData()
6478
```
6579

6680
### Error Resolution
67-
Refer to [Troubleshooting Guide](../../msal-shared/patterns/troubleshooting.md)
81+
Refer to [Troubleshooting Guide](../msal-shared/patterns/troubleshooting.md)
6882

6983
**Common OBO errors:**
7084
- `MsalUiRequiredException`: MFA or conditional access required—requires client re-authentication
7185
- Invalid token: Verify access token (not ID token) is passed
7286

7387
### Best Practices
74-
- Use [Token Caching Strategies](../../msal-shared/patterns/token-caching-strategies.md) for optimal session-based token caching
75-
- Implement [Error Handling Patterns](../../msal-shared/patterns/error-handling-patterns.md)
88+
- Use [Token Caching Strategies](../msal-shared/patterns/token-caching-strategies.md) for optimal session-based token caching
89+
- Implement [Error Handling Patterns](../msal-shared/patterns/error-handling-patterns.md)
7690
- Always validate incoming token before using in OBO
7791
- Extract `tid` claim from user token for guest user scenarios—use tenant-specific authority, not /common
7892
- For multi-instance deployments and advanced caching, see [Token cache serialization documentation](https://learn.microsoft.com/en-us/entra/msal/dotnet/how-to/token-cache-serialization?tabs=msal)

0 commit comments

Comments
 (0)