-
Notifications
You must be signed in to change notification settings - Fork 241
Adding Extensibility for Custom Signed Assertion Providers #3226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JoshLozensky
merged 37 commits into
master
from
lozensky/AddCustomSignedAssertionExtensibility
Feb 6, 2025
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
8ca8810
Added logic to DefaultCredentialsLoader to support custom signed asse…
JoshLozensky adc6ec9
adjusted logging message
JoshLozensky b82dd8b
simplified constructor
JoshLozensky 129819b
Added unit tests
JoshLozensky eeb9d7d
Update src/Microsoft.Identity.Web.Certificate/DefaultCredentialsLoade…
JoshLozensky b4096af
reworked error logging
JoshLozensky c9ffdef
Update error string
JoshLozensky 6cd4fdc
extra line
JoshLozensky f7dfa87
fixing public API and addressing PR comments
JoshLozensky 4be7c48
changed CustomSignedAssertionCredentialSourceLoader dict to use ICust…
JoshLozensky 39fdc69
finished unit test for behavior when user extension throws an error
JoshLozensky fb145fd
added to method summary
JoshLozensky 51681b4
Changed to concurrent dict and added logging for duplicate keys
JoshLozensky 79fc329
Added more specificity to tests and also added a check for duplicate …
JoshLozensky 9aaaac0
Merge branch 'master' into lozensky/AddCustomSignedAssertionExtensibi…
JoshLozensky 8520c07
Added null check and test
JoshLozensky c6ca484
Added custom mock logger to unit tests
JoshLozensky cb9affe
changed CustomSignedAssertionCredentialSourceLoaders to protected
JoshLozensky b8edcb6
improve null check
JoshLozensky 2a02584
removed Moq dependency
JoshLozensky 5c12e8d
Initial setup of extension classes
JoshLozensky 6779b3d
added snk reference
JoshLozensky 6748f02
Added test
JoshLozensky 06d6700
Added handling in ConfidentialClientApplicationBuilderExtension for C…
JoshLozensky db5546c
removing unneeded project reference
JoshLozensky c32179a
bring constructor up through DefaultCredentialsLoader
JoshLozensky bdd7393
added more configuration
JoshLozensky 9a3f44f
addressing PR feedback
JoshLozensky c5d15b7
Refactored Tests
JoshLozensky 6e55b7a
added appsettings copy to csproj
JoshLozensky 7a47370
Remove duplicitive functionality in test project
JoshLozensky ebc7128
fix typo
JoshLozensky 260e006
formatting
JoshLozensky 0de5970
Update tests/E2E Tests/CustomSignedAssertionProviderTests/CustomSigne…
JoshLozensky 42f611a
Update tests/E2E Tests/CustomSignedAssertionProviderTests/CustomSigne…
JoshLozensky 6a45dca
updated comment
JoshLozensky 2ed6114
fix typo
JoshLozensky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/Microsoft.Identity.Web.Certificate/DefaultCredentialsLoader.CustomSignedAssertion.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Globalization; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Identity.Abstractions; | ||
|
|
||
| namespace Microsoft.Identity.Web | ||
| { | ||
| public partial class DefaultCredentialsLoader | ||
| { | ||
| /// <summary> | ||
| /// Constructor for DefaultCredentialsLoader when using custom signed assertion provider source loaders. | ||
| /// </summary> | ||
| /// <param name="customSignedAssertionProviders">Set of custom signed assertion providers.</param> | ||
| /// <param name="logger">ILogger.</param> | ||
| public DefaultCredentialsLoader(IEnumerable<ICustomSignedAssertionProvider> customSignedAssertionProviders, ILogger<DefaultCredentialsLoader>? logger) : this(logger) | ||
| { | ||
| _ = Throws.IfNull(customSignedAssertionProviders); | ||
| var sourceLoaderDict = new Dictionary<string, ICustomSignedAssertionProvider>(); | ||
|
|
||
| foreach (ICustomSignedAssertionProvider provider in customSignedAssertionProviders) | ||
| { | ||
| string providerName = provider.Name ?? provider.GetType().FullName!; | ||
| if (sourceLoaderDict.ContainsKey(providerName)) | ||
| { | ||
| _logger.LogWarning(CertificateErrorMessage.CustomProviderNameAlreadyExists, providerName); | ||
| } | ||
| else | ||
| { | ||
| sourceLoaderDict.Add(providerName, provider); | ||
| } | ||
| } | ||
| CustomSignedAssertionCredentialSourceLoaders = sourceLoaderDict; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Dictionary of custom signed assertion credential source loaders, by name (either ICustomSignedAssertionProvider.Name or the fully qualified type name). | ||
| /// The application can add more to process additional credential sources. | ||
| /// </summary> | ||
| protected IDictionary<string, ICustomSignedAssertionProvider>? CustomSignedAssertionCredentialSourceLoaders { get; } | ||
|
|
||
| private async Task ProcessCustomSignedAssertionAsync(CredentialDescription credentialDescription, CredentialSourceLoaderParameters? parameters) | ||
| { | ||
| if (CustomSignedAssertionCredentialSourceLoaders == null || CustomSignedAssertionCredentialSourceLoaders.Count == 0) | ||
| { | ||
| // No source loader(s) | ||
| _logger.LogError(CertificateErrorMessage.CustomProviderSourceLoaderNullOrEmpty); | ||
| } | ||
| else if (string.IsNullOrEmpty(credentialDescription.CustomSignedAssertionProviderName)) | ||
| { | ||
| // No provider name | ||
| _logger.LogError(CertificateErrorMessage.CustomProviderNameNullOrEmpty); | ||
| } | ||
| else if (!CustomSignedAssertionCredentialSourceLoaders!.TryGetValue(credentialDescription.CustomSignedAssertionProviderName!, out ICustomSignedAssertionProvider? sourceLoader)) | ||
| { | ||
| // No source loader for provider name | ||
| _logger.LogError(CertificateErrorMessage.CustomProviderNotFound, credentialDescription.CustomSignedAssertionProviderName); | ||
| } | ||
| else | ||
| { | ||
| // Load the credentials, if there is an error, it is coming from the user's custom extension and should be logged and propagated. | ||
| try | ||
| { | ||
| await sourceLoader.LoadIfNeededAsync(credentialDescription, parameters); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Logger.CustomSignedAssertionProviderLoadingFailure(_logger, credentialDescription, ex); | ||
| throw; | ||
| } | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| const Microsoft.Identity.Web.CertificateErrorMessage.CustomProviderNameAlreadyExists = "IDW10111 The custom signed assertion provider '{0}' already exists, only the the first instance of ICustomSignedAssertionProvider with this name will be used." -> string! | ||
| const Microsoft.Identity.Web.CertificateErrorMessage.CustomProviderNameNullOrEmpty = "IDW10112 The name of the custom signed assertion provider is null or empty." -> string! | ||
| const Microsoft.Identity.Web.CertificateErrorMessage.CustomProviderNotFound = "IDW10113: The custom signed assertion provider with name '{0}' was not found. Was it registered in the service collection?" -> string! | ||
| const Microsoft.Identity.Web.CertificateErrorMessage.CustomProviderSourceLoaderNullOrEmpty = "IDW10114 The dictionary of SourceLoaders for custom signed assertion providers is null or empty." -> string! | ||
| const Microsoft.Identity.Web.DefaultCredentialsLoader.nameMissing = "NameMissing" -> string! | ||
| Microsoft.Identity.Web.CustomSignedAssertionProviderNotFoundException | ||
| Microsoft.Identity.Web.CustomSignedAssertionProviderNotFoundException.CustomSignedAssertionProviderNotFoundException(string! message) -> void | ||
| static Microsoft.Identity.Web.CustomSignedAssertionProviderNotFoundException.ProviderNameNotFound(string! name) -> Microsoft.Identity.Web.CustomSignedAssertionProviderNotFoundException! | ||
| static Microsoft.Identity.Web.CustomSignedAssertionProviderNotFoundException.ProviderNameNullOrEmpty() -> Microsoft.Identity.Web.CustomSignedAssertionProviderNotFoundException! | ||
| static Microsoft.Identity.Web.CustomSignedAssertionProviderNotFoundException.SourceLoadersNullOrEmpty() -> Microsoft.Identity.Web.CustomSignedAssertionProviderNotFoundException! | ||
| static Microsoft.Identity.Web.DefaultCredentialsLoader.CustomSignedAssertionProviderLoadingFailureMessage(string! providerName, string! sourceType, string! skip) -> string! |
3 changes: 3 additions & 0 deletions
3
src/Microsoft.Identity.Web.Certificate/PublicAPI.Unshipped.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| #nullable enable | ||
| Microsoft.Identity.Web.DefaultCertificateLoader.DefaultCertificateLoader(System.Collections.Generic.IEnumerable<Microsoft.Identity.Abstractions.ICustomSignedAssertionProvider!>! customSignedAssertionProviders, Microsoft.Extensions.Logging.ILogger<Microsoft.Identity.Web.DefaultCertificateLoader!>? logger) -> void | ||
| Microsoft.Identity.Web.DefaultCredentialsLoader.CustomSignedAssertionCredentialSourceLoaders.get -> System.Collections.Generic.IDictionary<string!, Microsoft.Identity.Abstractions.ICustomSignedAssertionProvider!>? | ||
| Microsoft.Identity.Web.DefaultCredentialsLoader.DefaultCredentialsLoader(System.Collections.Generic.IEnumerable<Microsoft.Identity.Abstractions.ICustomSignedAssertionProvider!>! customSignedAssertionProviders, Microsoft.Extensions.Logging.ILogger<Microsoft.Identity.Web.DefaultCredentialsLoader!>? logger) -> void |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.