-
Notifications
You must be signed in to change notification settings - Fork 378
Adding withCertificate overload to use cert serial number #5151
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b57a9db
Adding withCertificate overload to use cert serial number
ef22a55
Merge branch 'main' into trwalke/CertSerialNum
trwalke f35a3ea
Updating summary
9884279
Updating new api
b704b75
Adding test cases
cb9da31
Apply suggestions from code review
trwalke 94f0d7c
Refactoring
0939714
Updating comments
4f98748
Merge branch 'main' into trwalke/CertSerialNum
trwalke f8bc899
Updating tests to reset static caches
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
47 changes: 47 additions & 0 deletions
47
...ntity.Client/Extensibility/RP/ConfidentialClientApplicationBuilderForResourceProviders.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,47 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Security.Cryptography.X509Certificates; | ||
|
|
||
| namespace Microsoft.Identity.Client.RP | ||
| { | ||
| /// <summary> | ||
| /// Resource Provider extensibility methods for <see cref="ConfidentialClientApplicationBuilder"/> | ||
| /// </summary> | ||
| #if !SUPPORTS_CONFIDENTIAL_CLIENT | ||
| [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] // hide confidential client on mobile | ||
| #endif | ||
| public static class ConfidentialClientApplicationBuilderForResourceProviders | ||
| { | ||
| /// <summary> | ||
| /// Sets the certificate associated with the application. | ||
| /// Applicable to first-party applications only, this method also allows to specify | ||
| /// if the <see href="https://datatracker.ietf.org/doc/html/rfc7517#section-4.7">x5c claim</see> should be sent to Azure AD. | ||
| /// Sending the x5c enables application developers to achieve easy certificate roll-over in Azure AD: | ||
| /// this method will send the certificate chain to Azure AD along with the token request, | ||
| /// so that Azure AD can use it to validate the subject name based on a trusted issuer policy. | ||
| /// This saves the application admin from the need to explicitly manage the certificate rollover | ||
| /// (either via portal or PowerShell/CLI operation). For details see https://aka.ms/msal-net-sni | ||
| /// This API allow you to associate the tokens acquired from Azure AD with the certificate serial number. | ||
| /// This can be used to partition the cache by certificate. Tokens acquired with one certificate will not be accessible to another certificate with a different serial number. | ||
| /// </summary> | ||
| /// <param name="builder"></param> | ||
| /// <param name="certificate">The X509 certificate used as credentials to prove the identity of the application to Azure AD.</param> | ||
| /// <param name="sendX5C">To send X5C with every request or not. The default is <c>false</c></param> | ||
| /// <param name="associateTokensWithCertificateSerialNumber">Determines if the application tokens acquired from Azure AD are associated with the certificate serial number</param> | ||
| /// <remarks>You should use certificates with a private key size of at least 2048 bytes. Future versions of this library might reject certificates with smaller keys. </remarks> | ||
| public static ConfidentialClientApplicationBuilder WithCertificate( | ||
| this ConfidentialClientApplicationBuilder builder, | ||
| X509Certificate2 certificate, bool sendX5C, bool associateTokensWithCertificateSerialNumber) | ||
| { | ||
| builder.WithCertificate(certificate, sendX5C); | ||
|
|
||
| if (associateTokensWithCertificateSerialNumber) | ||
| { | ||
| builder.Config.CertificateIdToAssociateWithToken = certificate.SerialNumber; | ||
| } | ||
|
|
||
| return builder; | ||
| } | ||
| } | ||
| } |
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
4 changes: 3 additions & 1 deletion
4
src/client/Microsoft.Identity.Client/PublicApi/net462/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,3 +1,5 @@ | ||
| Microsoft.Identity.Client.BrokerOptions.OperatingSystems.Linux = 2 -> Microsoft.Identity.Client.BrokerOptions.OperatingSystems | ||
| Microsoft.Identity.Client.AssertionRequestOptions.ClientCapabilities.get -> System.Collections.Generic.IEnumerable<string> | ||
| Microsoft.Identity.Client.AssertionRequestOptions.ClientCapabilities.set -> void | ||
| Microsoft.Identity.Client.AssertionRequestOptions.ClientCapabilities.set -> void | ||
trwalke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Microsoft.Identity.Client.RP.ConfidentialClientApplicationBuilderForResourceProviders | ||
| static Microsoft.Identity.Client.RP.ConfidentialClientApplicationBuilderForResourceProviders.WithCertificate(this Microsoft.Identity.Client.ConfidentialClientApplicationBuilder builder, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate, bool sendX5C, bool associateTokensWithCertificateSerialNumber) -> Microsoft.Identity.Client.ConfidentialClientApplicationBuilder | ||
4 changes: 3 additions & 1 deletion
4
src/client/Microsoft.Identity.Client/PublicApi/net472/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,3 +1,5 @@ | ||
| Microsoft.Identity.Client.BrokerOptions.OperatingSystems.Linux = 2 -> Microsoft.Identity.Client.BrokerOptions.OperatingSystems | ||
| Microsoft.Identity.Client.AssertionRequestOptions.ClientCapabilities.get -> System.Collections.Generic.IEnumerable<string> | ||
| Microsoft.Identity.Client.AssertionRequestOptions.ClientCapabilities.set -> void | ||
| Microsoft.Identity.Client.AssertionRequestOptions.ClientCapabilities.set -> void | ||
| Microsoft.Identity.Client.RP.ConfidentialClientApplicationBuilderForResourceProviders | ||
| static Microsoft.Identity.Client.RP.ConfidentialClientApplicationBuilderForResourceProviders.WithCertificate(this Microsoft.Identity.Client.ConfidentialClientApplicationBuilder builder, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate, bool sendX5C, bool associateTokensWithCertificateSerialNumber) -> Microsoft.Identity.Client.ConfidentialClientApplicationBuilder |
2 changes: 2 additions & 0 deletions
2
src/client/Microsoft.Identity.Client/PublicApi/net8.0-android/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,3 +1,5 @@ | ||
| Microsoft.Identity.Client.BrokerOptions.OperatingSystems.Linux = 2 -> Microsoft.Identity.Client.BrokerOptions.OperatingSystems | ||
| Microsoft.Identity.Client.AssertionRequestOptions.ClientCapabilities.get -> System.Collections.Generic.IEnumerable<string> | ||
| Microsoft.Identity.Client.AssertionRequestOptions.ClientCapabilities.set -> void | ||
| Microsoft.Identity.Client.RP.ConfidentialClientApplicationBuilderForResourceProviders | ||
| static Microsoft.Identity.Client.RP.ConfidentialClientApplicationBuilderForResourceProviders.WithCertificate(this Microsoft.Identity.Client.ConfidentialClientApplicationBuilder builder, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate, bool sendX5C, bool associateTokensWithCertificateSerialNumber) -> Microsoft.Identity.Client.ConfidentialClientApplicationBuilder |
2 changes: 2 additions & 0 deletions
2
src/client/Microsoft.Identity.Client/PublicApi/net8.0-ios/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,3 +1,5 @@ | ||
| Microsoft.Identity.Client.BrokerOptions.OperatingSystems.Linux = 2 -> Microsoft.Identity.Client.BrokerOptions.OperatingSystems | ||
| Microsoft.Identity.Client.AssertionRequestOptions.ClientCapabilities.get -> System.Collections.Generic.IEnumerable<string> | ||
| Microsoft.Identity.Client.AssertionRequestOptions.ClientCapabilities.set -> void | ||
| Microsoft.Identity.Client.RP.ConfidentialClientApplicationBuilderForResourceProviders | ||
| static Microsoft.Identity.Client.RP.ConfidentialClientApplicationBuilderForResourceProviders.WithCertificate(this Microsoft.Identity.Client.ConfidentialClientApplicationBuilder builder, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate, bool sendX5C, bool associateTokensWithCertificateSerialNumber) -> Microsoft.Identity.Client.ConfidentialClientApplicationBuilder |
2 changes: 2 additions & 0 deletions
2
src/client/Microsoft.Identity.Client/PublicApi/net8.0/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,3 +1,5 @@ | ||
| Microsoft.Identity.Client.BrokerOptions.OperatingSystems.Linux = 2 -> Microsoft.Identity.Client.BrokerOptions.OperatingSystems | ||
| Microsoft.Identity.Client.AssertionRequestOptions.ClientCapabilities.get -> System.Collections.Generic.IEnumerable<string> | ||
| Microsoft.Identity.Client.AssertionRequestOptions.ClientCapabilities.set -> void | ||
| Microsoft.Identity.Client.RP.ConfidentialClientApplicationBuilderForResourceProviders | ||
| static Microsoft.Identity.Client.RP.ConfidentialClientApplicationBuilderForResourceProviders.WithCertificate(this Microsoft.Identity.Client.ConfidentialClientApplicationBuilder builder, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate, bool sendX5C, bool associateTokensWithCertificateSerialNumber) -> Microsoft.Identity.Client.ConfidentialClientApplicationBuilder |
2 changes: 2 additions & 0 deletions
2
src/client/Microsoft.Identity.Client/PublicApi/netstandard2.0/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,3 +1,5 @@ | ||
| Microsoft.Identity.Client.BrokerOptions.OperatingSystems.Linux = 2 -> Microsoft.Identity.Client.BrokerOptions.OperatingSystems | ||
| Microsoft.Identity.Client.AssertionRequestOptions.ClientCapabilities.get -> System.Collections.Generic.IEnumerable<string> | ||
| Microsoft.Identity.Client.AssertionRequestOptions.ClientCapabilities.set -> void | ||
| Microsoft.Identity.Client.RP.ConfidentialClientApplicationBuilderForResourceProviders | ||
| static Microsoft.Identity.Client.RP.ConfidentialClientApplicationBuilderForResourceProviders.WithCertificate(this Microsoft.Identity.Client.ConfidentialClientApplicationBuilder builder, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate, bool sendX5C, bool associateTokensWithCertificateSerialNumber) -> Microsoft.Identity.Client.ConfidentialClientApplicationBuilder |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trwalke - please remove this.