Skip to content

Commit 7fb9176

Browse files
authored
Merge pull request #178 from dataplat/bug_164_spn
Log in with SPN and password as String is possible #164
2 parents a53f15d + a68af49 commit 7fb9176

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121

2222
- Fixed bug in `Update-FabricSemanticModelDefinition` - Uri was incorrect when a platform file exists
2323
- Name of new SQL database will be shown (#169)
24+
- Logging in with a Service Principal does not work (#164)
2425

2526
### Deprecated
2627

source/Public/Connect-FabricAccount.ps1

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,28 @@ function Connect-FabricAccount {
3838
```
3939
4040
.EXAMPLE
41-
Connects as Service Principal using id and secret
41+
Connects as Service Principal using AppId and secret
4242
4343
```powershell
44-
Connect-FabricAccount -TenantId 'xxx' -ServicePrincipalId 'appId' -ServicePrincipalSecret $secret
44+
$TenantID = '12345678-1234-1234-1234-123456789012'
45+
$ServicePrincipalId = '4cbbe76e-1234-1234-0000-ffffffffffff'
46+
$ServicePrincipalSecret = 'xyz'
47+
48+
$ServicePrincipalSecretSecure = ($ServicePrincipalSecret | ConvertTo-SecureString -AsPlainText -Force)
49+
Connect-FabricAccount -TenantId $TenantID -ServicePrincipalId $ServicePrincipalId -ServicePrincipalSecret $ServicePrincipalSecretSecure -Reset
50+
```
51+
52+
.EXAMPLE
53+
Connects as Service Principal using credential object
54+
55+
```powershell
56+
$TenantID = '12345678-1234-1234-1234-123456789012'
57+
$ServicePrincipalId = '4cbbe76e-1234-1234-0000-ffffffffffff'
58+
$ServicePrincipalSecret = 'xyz'
59+
60+
$ServicePrincipalSecretSecure = ($ServicePrincipalSecret | ConvertTo-SecureString -AsPlainText -Force)
61+
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ServicePrincipalId, $ServicePrincipalSecretSecure
62+
Connect-FabricAccount -TenantId $TenantID -Credential $credential -Verbose -Reset
4563
```
4664
4765
.OUTPUTS
@@ -91,7 +109,12 @@ function Connect-FabricAccount {
91109
if ($PSBoundParameters.ContainsKey('AppSecret') -and -not $PSBoundParameters.ContainsKey('AppId'))
92110
{
93111
Write-Message -Message "AppId is required when using AppSecret." -Level Error
94-
throw "AppId is required when using AppId."
112+
throw "AppId is required when using AppSecret."
113+
}
114+
# Warn if both Credential and AppId are provided
115+
if ($PSBoundParameters.ContainsKey('Credential') -and $PSBoundParameters.ContainsKey('AppId'))
116+
{
117+
Write-Message -Message "Provided Credential will be ignored when AppId/ServicePrincipalId is also provided." -Level Warning
95118
}
96119
}
97120

@@ -102,13 +125,13 @@ function Connect-FabricAccount {
102125
}
103126
if (!$azContext) {
104127
if ($ServicePrincipalId) {
105-
Write-Message "Connecting to Azure Account using provided servicePrincipalId..." -Level Verbose
128+
Write-Message "Connecting to Azure Account using provided ServicePrincipalId..." -Level Verbose
106129
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ServicePrincipalId, $ServicePrincipalSecret
107130
$null = Connect-AzAccount -ServicePrincipal -TenantId $TenantId -Credential $credential
108131
}
109132
elseif ($null -ne $Credential) {
110133
Write-Message "Connecting to Azure Account using provided credential..." -Level Verbose
111-
$null = Connect-AzAccount -Credential $Credential -Tenant $TenantId
134+
$null = Connect-AzAccount -ServicePrincipal -Credential $Credential -Tenant $TenantId
112135
}
113136
else {
114137
Write-Message "Connecting to Azure Account using current user..." -Level Verbose
@@ -151,6 +174,5 @@ function Connect-FabricAccount {
151174
}
152175

153176
}
154-
end {
155-
}
177+
end { }
156178
}

0 commit comments

Comments
 (0)