Skip to content

Commit 1c15052

Browse files
cpp11nullptrZhenya Polyvanyi
andauthored
Add authorization header provider interface to return token with binding certificate (#223)
* Update create authorization header API to include binding certificate in result * Extract credentials bound APIs into separated interface * Change parent of auth header bound provider to generic auth header provider * Reworded a comment for auth header bound provider --------- Co-authored-by: Zhenya Polyvanyi <[email protected]>
1 parent b67fd30 commit 1c15052

File tree

11 files changed

+37
-3
lines changed

11 files changed

+37
-3
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ namespace TokenAcquisition {
185185
}
186186
187187
class IAuthorizationHeaderProvider { <<interface>> }
188+
class IAuthorizationHeaderBoundProvider { <<interface>> }
188189
class IAuthorizationHeaderProvider_TResult_ { <<interface>> }
189190
class IDownstreamApi { <<interface>>
190191
+CallApiAsync(...)
@@ -422,6 +423,8 @@ It's also possible (and recommended) to use higher level APIs:
422423
- IAuthorizationHeaderProvider is the component that provides the authorization header, delegating to the ITokenAcquirer.
423424
Whereas ITokenAcquirer only knows about tokens, IAuthorizationHeaderProvider knows about protocols (for instance bearer,
424425
Pop, etc ...)
426+
- IAuthorizationHeaderBoundProvider extends IAuthorizationHeaderProvider to provide authorization headers along with
427+
bound certificate information, useful for scenarios requiring certificate binding details.
425428

426429
```mermaid
427430
classDiagram
@@ -458,6 +461,11 @@ It's also possible (and recommended) to use higher level APIs:
458461
+Task&lt;string&gt; CreateAuthorizationHeaderForAppAsync(string scopes, AuthorizationHeaderProviderOptions downstreamApiOptions, CancellationToken cancellationToken)
459462
+Task&lt;string&gt; CreateAuthorizationHeaderAsync(IEnumerable&lt;string&gt; scopes, AuthorizationHeaderProviderOptions options, ClaimsPrincipal claimsPrincipal, CancellationToken cancellationToken)
460463
}
464+
class IAuthorizationHeaderBoundProvider { <<interface>>
465+
+Task&lt;AuthorizationHeaderInformation&gt; CreateAuthorizationHeaderBoundForUserAsync(IEnumerable&lt;string&gt; scopes, AuthorizationHeaderProviderOptions authorizationHeaderProviderOptions, ClaimsPrincipal claimsPrincipal, CancellationToken cancellationToken)
466+
+Task&lt;AuthorizationHeaderInformation&gt; CreateAuthorizationHeaderBoundForAppAsync(string scopes, AuthorizationHeaderProviderOptions downstreamApiOptions, CancellationToken cancellationToken)
467+
+Task&lt;AuthorizationHeaderInformation&gt; CreateAuthorizationHeaderBoundAsync(IEnumerable&lt;string&gt; scopes, AuthorizationHeaderProviderOptions options, ClaimsPrincipal claimsPrincipal, CancellationToken cancellationToken)
468+
}
461469
class IDownstreamApi { <<interface>>
462470
+Task&lt;HttpResponseMessage&gt; CallApiAsync(DownstreamApiOptions downstreamApiOptions, ClaimsPrincipal user, HttpContent content, CancellationToken cancellationToken)
463471
+Task&lt;HttpResponseMessage&gt; CallApiAsync(string serviceName, Action&lt;DownstreamApiOptions&gt; downstreamApiOptionsOverride, ClaimsPrincipal user, HttpContent content, CancellationToken cancellationToken)
@@ -515,11 +523,13 @@ It's also possible (and recommended) to use higher level APIs:
515523
516524
AuthorizationHeaderProviderOptions <|-- DownstreamApiOptions : Inherits
517525
DownstreamApiOptions <|-- DownstreamApiOptionsReadOnlyHttpMethod : Inherits
526+
IAuthorizationHeaderProvider <|-- IAuthorizationHeaderBoundProvider : Inherits
518527
CredentialDescription --> "DecryptKeysAuthenticationOptions" AuthorizationHeaderProviderOptions : Has
519528
AuthorizationHeaderProviderOptions --> "AcquireTokenOptions" AcquireTokenOptions : Has
520529
AcquireTokenOptions --> "ManagedIdentity" ManagedIdentityOptions : Has
521530
IDownstreamApi ..> DownstreamApiOptions : Uses
522531
IAuthorizationHeaderProvider ..> AuthorizationHeaderProviderOptions : Uses
532+
IAuthorizationHeaderBoundProvider ..> AuthorizationHeaderProviderOptions : Uses
523533
524534
```
525535

agents.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ Through its well-designed abstractions and interfaces, Microsoft.Identity.Abstra
169169
- ITokenAcquirer - Core interface for token acquisition
170170
- ITokenAcquirerFactory - Factory of Token acquirers
171171
- IAuthorizationHeaderProvider - creates authorization headers (getting tokens and building the protocol string)
172+
- IAuthorizationHeaderBoundProvider - extends IAuthorizationHeaderProvider to provide authorization headers with bound certificate information
172173
- IDownstreamApi - call downstream APIs in an authenticated way.
173174

174175
### Development Guidelines
@@ -278,7 +279,7 @@ This document replaces the previous `.clinerules` directory structure and consol
278279

279280
### Original Files Migrated
280281
- `.clinerules/abstractions-guidelines.md` → Section: Microsoft.Identity.Abstractions Guidelines
281-
- `.clinerules/ai-guidelines.md` → Section: AI Assistant Guidelines
282+
- `.clinerules/ai-guidelines.md` → Section: AI Assistant Guidelines
282283
- `.clinerules/cline-instructions.md` → Section: AI Assistant Guidelines (Cline-specific content)
283284
- `.clinerules/csharp-guidelines.md` → Section: C# Development Standards
284285

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
namespace Microsoft.Identity.Abstractions
5+
{
6+
/// <summary>
7+
/// Creates an authorization header value that the caller can use to access a protected web API, which supports either unbound or
8+
/// bound to a certificate (for example, in an mTLS PoP scenario) tokens.
9+
/// </summary>
10+
public interface IAuthorizationHeaderBoundProvider : IAuthorizationHeaderProvider<OperationResult<AuthorizationHeaderInformation, AuthorizationHeaderError>>
11+
{
12+
}
13+
}

src/Microsoft.Identity.Abstractions/DownstreamApi/IAuthorizationHeaderProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface IAuthorizationHeaderProvider
2828
/// (for instance: "Bearer token", "PoP token", etc ...).
2929
/// </returns>
3030
Task<string> CreateAuthorizationHeaderForUserAsync(
31-
IEnumerable<string> scopes,
31+
IEnumerable<string> scopes,
3232
AuthorizationHeaderProviderOptions? authorizationHeaderProviderOptions = null,
3333
ClaimsPrincipal? claimsPrincipal = default,
3434
CancellationToken cancellationToken = default);
@@ -53,7 +53,7 @@ Task<string> CreateAuthorizationHeaderForAppAsync(
5353
/// <summary>
5454
/// Creates an authorization header for calling a protected web API on behalf of a user or the application.
5555
/// </summary>
56-
/// <param name="scopes">The scopes for which to request the authorization header.
56+
/// <param name="scopes">The scopes for which to request the authorization header.
5757
/// Provide a single scope if the header needs to be created on behalf of an application.</param>
5858
/// <param name="options">The <see cref="AuthorizationHeaderProviderOptions"/> containing information about the API
5959
/// to be called and token acquisition settings. If not provided, the header will be for a bearer token.</param>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
#nullable enable
2+
Microsoft.Identity.Abstractions.IAuthorizationHeaderBoundProvider
3+
Microsoft.Identity.Abstractions.IAuthorizationHeaderBoundProvider.CreateAuthorizationHeaderBoundAsync(System.Collections.Generic.IEnumerable<string!>! scopes, Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions? options = null, System.Security.Claims.ClaimsPrincipal? claimsPrincipal = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<Microsoft.Identity.Abstractions.AuthorizationHeaderInformation!>!
4+
Microsoft.Identity.Abstractions.IAuthorizationHeaderBoundProvider.CreateAuthorizationHeaderBoundForAppAsync(string! scopes, Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions? downstreamApiOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<Microsoft.Identity.Abstractions.AuthorizationHeaderInformation!>!
5+
Microsoft.Identity.Abstractions.IAuthorizationHeaderBoundProvider.CreateAuthorizationHeaderBoundForUserAsync(System.Collections.Generic.IEnumerable<string!>! scopes, Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions? authorizationHeaderProviderOptions = null, System.Security.Claims.ClaimsPrincipal? claimsPrincipal = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<Microsoft.Identity.Abstractions.AuthorizationHeaderInformation!>!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
#nullable enable
2+
Microsoft.Identity.Abstractions.IAuthorizationHeaderBoundProvider
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
#nullable enable
2+
Microsoft.Identity.Abstractions.IAuthorizationHeaderBoundProvider
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
#nullable enable
2+
Microsoft.Identity.Abstractions.IAuthorizationHeaderBoundProvider
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
#nullable enable
2+
Microsoft.Identity.Abstractions.IAuthorizationHeaderBoundProvider
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
#nullable enable
2+
Microsoft.Identity.Abstractions.IAuthorizationHeaderBoundProvider

0 commit comments

Comments
 (0)