Skip to content

Commit d576860

Browse files
authored
Change Get-AzAccessToken to Get-AzAccessToken -AsSecureString (#26508)
1 parent b1978c3 commit d576860

File tree

9 files changed

+14
-10
lines changed

9 files changed

+14
-10
lines changed

src/AppComplianceAutomation/AppComplianceAutomation.Autorest/custom/Utils.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ function Get-Token {
6262
[Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.DoNotExportAttribute()]
6363
param()
6464
try {
65-
return "Bearer " + (Get-AzAccessToken).Token
65+
$token = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" (Get-AzAccessToken -AsSecureString).Token
66+
return "Bearer " + $token
6667
}
6768
catch {}
6869
return ""

src/AppComplianceAutomation/AppComplianceAutomation/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Used `Get-AzAccessToken -AsSecureString` inside the `AppComplianceAutomation` for the plain text version is going to be deprecate in the next release.
2122

2223
## Version 0.1.1
2324
* Fixed secrets exposure in example documentation.

src/Functions/Functions.Autorest/custom/HelperFunctions.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,7 @@ function GetFunctionAppStackDefinition
17761776
}
17771777

17781778
Write-Debug "$DEBUG_PREFIX Get AccessToken."
1779-
$token = (Get-AzAccessToken).Token
1779+
$token = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" (Get-AzAccessToken -AsSecureString).Token
17801780
$headers = @{
17811781
Authorization="Bearer $token"
17821782
}
@@ -1814,7 +1814,7 @@ function GetFunctionAppStackDefinition
18141814
if ($result.StatusCode -eq 401)
18151815
{
18161816
# Get a new access token, create new headers and retry
1817-
$token = (Get-AzAccessToken).Token
1817+
$token = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" (Get-AzAccessToken -AsSecureString).Token
18181818

18191819
$headers = @{
18201820
Authorization = "Bearer $token"

src/Functions/Functions/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Used `Get-AzAccessToken -AsSecureString` inside the `Functions` for the plain text version is going to be deprecate in the next release.
2122

2223
## Version 4.1.0
2324
* Upgraded to Microsoft.Web API version 2023-12-01 [#25347]

src/LabServices/LabServices.Autorest/test/WebRequestHandler.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ function Get-CallerPreference {
120120

121121
function GetHeaderWithAuthToken {
122122

123-
$authToken = Get-AzAccessToken
124-
#Write-Host $authToken
123+
$token = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" (Get-AzAccessToken -AsSecureString).Token
124+
#Write-Host $token
125125

126126
$header = @{
127127
'Content-Type' = 'application/json'
128-
"Authorization" = "Bearer " + $authToken.Token
128+
"Authorization" = "Bearer " + $token
129129
"Accept" = "application/json;odata=fullmetadata"
130130
}
131131

src/SecurityInsights/SecurityInsights.Autorest/test/common.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ Function Create-ThreatIntelligenceIndicator{
519519
# $null = $env.Add(($PSVerb+'threatIntelligenceIndicatorId'), $threatIntelligenceIndicatorId)
520520
# $null = $env.Add(($PSVerb+'threatIntelligenceIndicatorIP'), $IP)
521521
#}
522-
$tiToken = (Get-AzAccessToken).Token
522+
$tiToken = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" (Get-AzAccessToken -AsSecureString).Token
523523
$tiHeaders = @{
524524
Authorization="Bearer $tiToken"
525525
Content='application/json'

src/SecurityInsights/SecurityInsights.Autorest/test/utils.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ function setupEnv() {
4545
$env.Tenant = (Get-AzContext).Tenant.Id
4646

4747
#needed for custom api call
48-
$Token = (Get-AzAccessToken).Token
48+
$token = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" (Get-AzAccessToken -AsSecureString).Token
4949
$Header = @{
50-
Authorization="Bearer $Token"
50+
Authorization="Bearer $token"
5151
Content='application/json'
5252
}
5353

src/ServiceLinker/ServiceLinker.Autorest/custom/Common.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function Set-Header {
5656
if($PSBoundParameters.ContainsKey("VNetSolutionType") -Or $PSBoundParameters.ContainsKey("SecretStoreKeyVaultId") `
5757
-Or $provider -eq "microsoft.keyvault" -Or $resourceType -eq "flexibleservers") {
5858
if(-Not $PSBoundParameters.ContainsKey('XmsServiceconnectorUserToken')){
59-
$PSBoundParameters['XmsServiceconnectorUserToken'] = (Get-AzAccessToken).Token
59+
$PSBoundParameters['XmsServiceconnectorUserToken'] = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" (Get-AzAccessToken -AsSecureString).Token
6060
}
6161
}
6262
}

src/ServiceLinker/ServiceLinker/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Used `Get-AzAccessToken -AsSecureString` inside the `ServiceLinker` for the plain text version is going to be deprecate in the next release.
2122

2223
## Version 0.2.1
2324
* Introduced secrets detection feature to safeguard sensitive data.

0 commit comments

Comments
 (0)