Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

[WIP] Add Azure region to support regional ESTS-r #71

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Get-MsalToken.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,21 @@ function Get-MsalToken {

# Specifies the timeout threshold for MSAL.net operations.
[Parameter(Mandatory = $false)]
[timespan] $Timeout
[timespan] $Timeout,

# Specifies the Azure region to use for token acquisition.
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientSecret', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientCertificate', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientClaims', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientAssertion', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientSecret-AuthorizationCode', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientSecret', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientSecret-AuthorizationCode', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientSecret-OnBehalfOf', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientCertificate', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientCertificate-AuthorizationCode', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientCertificate-OnBehalfOf', ValueFromPipelineByPropertyName = $true)]
[string] $AzureRegion = [Microsoft.Identity.Client.ConfidentialClientApplication]::AttemptRegionDiscovery
)

begin {
Expand Down
10 changes: 8 additions & 2 deletions src/New-MsalClientApplication.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ function New-MsalClientApplication {
[Microsoft.Identity.Client.PublicClientApplicationOptions] $PublicClientOptions,
# Confidential client application options
[Parameter(Mandatory = $true, ParameterSetName = 'ConfidentialClient-InputObject', Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Microsoft.Identity.Client.ConfidentialClientApplicationOptions] $ConfidentialClientOptions
[Microsoft.Identity.Client.ConfidentialClientApplicationOptions] $ConfidentialClientOptions,
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientSecret', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientCertificate', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientClaims', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientAssertion', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClient-InputObject', ValueFromPipelineByPropertyName = $true)]
[string] $AzureRegion = [Microsoft.Identity.Client.ConfidentialClientApplication]::AttemptRegionDiscovery
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a parameter of type string? ESTS-R SHOULD most certainly not be enabled by default.

Note that for ESTS-R to work you need Certificate with SN/I, via the "sendX5C" param. Is this exposed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter was of type string. Here i was simply setting it to the TryAutoDetect const that the library provides. The SendX5C parameter is exposed yes

)

switch -Wildcard ($PSCmdlet.ParameterSetName) {
Expand Down Expand Up @@ -127,7 +133,7 @@ function New-MsalClientApplication {
if ($ClientClaims) { [void] $ClientApplicationBuilder.WithClientClaims($ClientCertificate, (ConvertTo-Dictionary $ClientClaims -KeyType ([string]) -ValueType ([string]))) }
elseif ($ClientCertificate) { [void] $ClientApplicationBuilder.WithCertificate($ClientCertificate) }
if ($RedirectUri) { [void] $ClientApplicationBuilder.WithRedirectUri($RedirectUri.AbsoluteUri) }

[void] $ClientApplicationBuilder.WithAzureRegion($AzureRegion)
$ClientOptions = $ConfidentialClientOptions
}
"*" {
Expand Down
6 changes: 5 additions & 1 deletion src/Select-MsalClientApplication.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ function Select-MsalClientApplication {
[Microsoft.Identity.Client.PublicClientApplicationOptions] $PublicClientOptions,
# Confidential client application options
[Parameter(Mandatory = $true, ParameterSetName = 'ConfidentialClient-InputObject', Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Microsoft.Identity.Client.ConfidentialClientApplicationOptions] $ConfidentialClientOptions
[Microsoft.Identity.Client.ConfidentialClientApplicationOptions] $ConfidentialClientOptions,
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientSecret', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClientCertificate', ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $false, ParameterSetName = 'ConfidentialClient-InputObject', ValueFromPipelineByPropertyName = $true)]
[string] $AzureRegion = [Microsoft.Identity.Client.ConfidentialClientApplication]::AttemptRegionDiscovery
)

$paramNewMsalClientApplication = Select-PsBoundParameters $PSBoundParameters -CommandName New-MsalClientApplication -ExcludeParameters ErrorAction
Expand Down