Skip to content

Commit e5183c4

Browse files
authored
Merge pull request #2699 from nayanshah/nayanshah/sni-auth
Add flag to send certificate chain for subject name / issuer based auth in Connect-MgGraph
2 parents 44ed6a0 + 632a34a commit e5183c4

File tree

6 files changed

+10
-2
lines changed

6 files changed

+10
-2
lines changed

src/Authentication/Authentication.Core/Interfaces/IAuthContext.cs

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public interface IAuthContext
4747
string Account { get; set; }
4848
string CertificateThumbprint { get; set; }
4949
string CertificateSubjectName { get; set; }
50+
bool SendCertificateChain { get; set; }
5051
X509Certificate2 Certificate { get; set; }
5152
ContextScope ContextScope { get; set; }
5253
Version PSHostVersion { get; set; }

src/Authentication/Authentication.Core/Utilities/AuthenticationHelpers.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ private static async Task<ClientCertificateCredential> GetClientCertificateCrede
184184
var clientCredentialOptions = new ClientCertificateCredentialOptions
185185
{
186186
AuthorityHost = new Uri(GetAuthorityUrl(authContext)),
187-
TokenCachePersistenceOptions = GetTokenCachePersistenceOptions(authContext)
187+
TokenCachePersistenceOptions = GetTokenCachePersistenceOptions(authContext),
188+
SendCertificateChain = authContext.SendCertificateChain
188189
};
189190
var clientCertificateCredential = new ClientCertificateCredential(authContext.TenantId, authContext.ClientId, GetCertificate(authContext), clientCredentialOptions);
190191
return await Task.FromResult(clientCertificateCredential).ConfigureAwait(false);

src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public class ConnectMgGraph : PSCmdlet, IModuleAssemblyInitializer, IModuleAssem
4646
[Parameter(ParameterSetName = Constants.AppCertificateParameterSet, Position = 3, HelpMessage = HelpMessages.CertificateThumbprint)]
4747
public string CertificateThumbprint { get; set; }
4848

49+
[Parameter(ParameterSetName = Constants.AppCertificateParameterSet, HelpMessage = HelpMessages.SendCertificateChain)]
50+
public bool SendCertificateChain { get; set; }
51+
4952
[Parameter(Mandatory = false, ParameterSetName = Constants.AppCertificateParameterSet, HelpMessage = HelpMessages.Certificate)]
5053
public X509Certificate2 Certificate { get; set; }
5154

@@ -200,6 +203,7 @@ private async Task ProcessRecordAsync()
200203
authContext.ClientId = ClientId;
201204
authContext.CertificateThumbprint = CertificateThumbprint;
202205
authContext.CertificateSubjectName = CertificateSubjectName;
206+
authContext.SendCertificateChain = SendCertificateChain;
203207
authContext.Certificate = Certificate;
204208
// Default to Process but allow the customer to change this via `-ContextScope`.
205209
authContext.ContextScope = this.IsParameterBound(nameof(ContextScope)) ? ContextScope : ContextScope.Process;

src/Authentication/Authentication/Constants.cs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static class HelpMessages
3535
public const string ClientId = "The client id of your application.";
3636
public const string CertificateSubjectName = "The subject distinguished name of a certificate. The Certificate will be retrieved from the current user's certificate store.";
3737
public const string CertificateThumbprint = "The thumbprint of your certificate. The Certificate will be retrieved from the current user's certificate store.";
38+
public const string SendCertificateChain = "Include x5c header in client claims when acquiring a token to enable subject name / issuer based authentication using given certificate.";
3839
public const string Certificate = "An X.509 certificate supplied during invocation.";
3940
public const string ClientSecretCredential = "The PSCredential object provides the application ID and client secret for service principal credentials. For more information about the PSCredential object, type Get-Help Get-Credential.";
4041
public const string AccessToken = "Specifies a bearer token for Microsoft Graph service. Access tokens do timeout and you'll have to handle their refresh.";

src/Authentication/Authentication/Models/AuthContext.cs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class AuthContext : IAuthContext
1919
public TokenCredentialType TokenCredentialType { get; set; }
2020
public string CertificateThumbprint { get; set; }
2121
public string CertificateSubjectName { get; set; }
22+
public bool SendCertificateChain { get; set; }
2223
public string Account { get; set; }
2324
public string AppName { get; set; }
2425
public ContextScope ContextScope { get; set; }

src/Authentication/Authentication/test/Connect-MgGraph.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Describe 'Connect-MgGraph ParameterSets' {
3232
It 'Should have AppCertificateParameterSet' {
3333
$AppCertificateParameterSet = $ConnectMgGraphCommand.ParameterSets | Where-Object Name -eq 'AppCertificateParameterSet'
3434
$AppCertificateParameterSet | Should -Not -BeNull
35-
@('ClientId', 'TenantId', 'CertificateSubjectName', 'CertificateThumbprint', 'ContextScope', 'Environment', 'ClientTimeout') | Should -BeIn $AppCertificateParameterSet.Parameters.Name
35+
@('ClientId', 'TenantId', 'CertificateSubjectName', 'CertificateThumbprint', 'SendCertificateChain', 'ContextScope', 'Environment', 'ClientTimeout') | Should -BeIn $AppCertificateParameterSet.Parameters.Name
3636
$MandatoryParameters = $AppCertificateParameterSet.Parameters | Where-Object IsMandatory
3737
$MandatoryParameters | Should -HaveCount 1
3838
$MandatoryParameters.Name | Should -Be 'ClientId'

0 commit comments

Comments
 (0)