Skip to content

Commit db658f8

Browse files
committed
SecureString is OK
1 parent 8b5bc7b commit db658f8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

source/Public/Connect-FabricAccount.ps1

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function Connect-FabricAccount {
1414
The Client ID (AppId) of the service principal used for authentication.
1515
1616
.PARAMETER ServicePrincipalSecret
17-
String representing the service principal secret.
17+
The **secure string** representing the service principal secret.
1818
1919
.PARAMETER Credential
2020
A PSCredential object representing a user credential (username and secure password).
@@ -70,9 +70,9 @@ function Connect-FabricAccount {
7070
[Alias('AppId')]
7171
[guid] $ServicePrincipalId,
7272

73-
[Parameter(Mandatory = $false, HelpMessage = "Secret of the service principal.")]
73+
[Parameter(Mandatory = $false, HelpMessage = "Secure secret of the service principal.")]
7474
[Alias('AppSecret')]
75-
[String] $ServicePrincipalSecret,
75+
[SecureString] $ServicePrincipalSecret,
7676

7777
[Parameter(Mandatory = $false, HelpMessage = "User credential.")]
7878
[PSCredential] $Credential,
@@ -91,7 +91,12 @@ function Connect-FabricAccount {
9191
if ($PSBoundParameters.ContainsKey('AppSecret') -and -not $PSBoundParameters.ContainsKey('AppId'))
9292
{
9393
Write-Message -Message "AppId is required when using AppSecret." -Level Error
94-
throw "AppId is required when using AppId."
94+
throw "AppId is required when using AppSecret."
95+
}
96+
# Warn if both Credential and AppId are provided
97+
if ($PSBoundParameters.ContainsKey('Credential') -and $PSBoundParameters.ContainsKey('AppId'))
98+
{
99+
Write-Message -Message "Provided Credential will be ignored when AppId/ServicePrincipalId is also provided." -Level Warning
95100
}
96101
}
97102

@@ -102,9 +107,8 @@ function Connect-FabricAccount {
102107
}
103108
if (!$azContext) {
104109
if ($ServicePrincipalId) {
105-
Write-Message "Connecting to Azure Account using provided servicePrincipalId..." -Level Verbose
106-
$ServicePrincipalSecretSecure = ($ServicePrincipalSecret | ConvertTo-SecureString -AsPlainText -Force)
107-
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ServicePrincipalId, $ServicePrincipalSecretSecure
110+
Write-Message "Connecting to Azure Account using provided ServicePrincipalId..." -Level Verbose
111+
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ServicePrincipalId, $ServicePrincipalSecret
108112
$null = Connect-AzAccount -ServicePrincipal -TenantId $TenantId -Credential $credential
109113
}
110114
elseif ($null -ne $Credential) {

0 commit comments

Comments
 (0)