Skip to content

Commit 1106839

Browse files
committed
More elegant way to decode token to plain text needed for request's headers
1 parent 26b8d96 commit 1106839

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

source/Public/Connect-FabricAccount.ps1

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,9 @@ function Connect-FabricAccount {
121121
if ($PSCmdlet.ShouldProcess("Setting Fabric authentication token and headers for $($azContext.Account)")) {
122122
Write-Message "Get authentication token from $($FabricSession.ResourceUrl)" -Level Verbose
123123
$FabricSession.AccessToken = (Get-AzAccessToken -ResourceUrl $FabricSession.ResourceUrl)
124-
$ssPtr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($FabricSession.AccessToken.Token)
125-
$Token = ([System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($ssPtr))
124+
$plainTextToken = $FabricSession.AccessToken.Token | ConvertFrom-SecureString -AsPlainText
126125
Write-Message "Setup headers for Fabric API calls" -Level Debug
127-
$FabricSession.HeaderParams = @{'Authorization' = "Bearer {0}" -f $Token }
126+
$FabricSession.HeaderParams = @{'Authorization' = "Bearer {0}" -f $plainTextToken }
128127

129128
# Copy session values to exposed $FabricConfig
130129
$FabricConfig.TenantId = $FabricSession.AccessToken.TenantId
@@ -135,10 +134,9 @@ function Connect-FabricAccount {
135134
if ($PSCmdlet.ShouldProcess("Setting Azure authentication token and headers for $($azContext.Account)")) {
136135
Write-Message "Get authentication token from $($AzureSession.BaseApiUrl)" -Level Verbose
137136
$AzureSession.AccessToken = (Get-AzAccessToken -ResourceUrl $AzureSession.BaseApiUrl)
138-
$ssPtr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($AzureSession.AccessToken.Token)
139-
$Token = ([System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($ssPtr))
137+
$plainTextToken = $AzureSession.AccessToken.Token | ConvertFrom-SecureString -AsPlainText
140138
Write-Message "Setup headers for Azure API calls" -Level Debug
141-
$AzureSession.HeaderParams = @{'Authorization' = "Bearer {0}" -f $Token }
139+
$AzureSession.HeaderParams = @{'Authorization' = "Bearer {0}" -f $plainTextToken }
142140
}
143141

144142
}

0 commit comments

Comments
 (0)