-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding withCertificate overload to use cert serial number (#5151)
* Adding withCertificate overload to use cert serial number * Updating summary * Updating new api * Adding test cases Refactoring * Apply suggestions from code review Co-authored-by: Gladwin Johnson <[email protected]> * Refactoring * Updating comments * Updating tests to reset static caches --------- Co-authored-by: trwalke <[email protected]> Co-authored-by: Gladwin Johnson <[email protected]>
- Loading branch information
1 parent
5587cb3
commit 68dc10f
Showing
13 changed files
with
275 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 |
4 changes: 3 additions & 1 deletion
4
src/client/Microsoft.Identity.Client/PublicApi/net472/PublicAPI.Unshipped.txt
This file contains 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 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 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 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 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 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.