Skip to content

Commit

Permalink
Change Get-AzAccessToken to Get-AzAccessToken -AsSecureString (Azure#…
Browse files Browse the repository at this point in the history
  • Loading branch information
msJinLei authored Oct 29, 2024
1 parent b1978c3 commit d576860
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ function Get-Token {
[Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.DoNotExportAttribute()]
param()
try {
return "Bearer " + (Get-AzAccessToken).Token
$token = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" (Get-AzAccessToken -AsSecureString).Token
return "Bearer " + $token
}
catch {}
return ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Used `Get-AzAccessToken -AsSecureString` inside the `AppComplianceAutomation` for the plain text version is going to be deprecate in the next release.

## Version 0.1.1
* Fixed secrets exposure in example documentation.
Expand Down
4 changes: 2 additions & 2 deletions src/Functions/Functions.Autorest/custom/HelperFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,7 @@ function GetFunctionAppStackDefinition
}

Write-Debug "$DEBUG_PREFIX Get AccessToken."
$token = (Get-AzAccessToken).Token
$token = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" (Get-AzAccessToken -AsSecureString).Token
$headers = @{
Authorization="Bearer $token"
}
Expand Down Expand Up @@ -1814,7 +1814,7 @@ function GetFunctionAppStackDefinition
if ($result.StatusCode -eq 401)
{
# Get a new access token, create new headers and retry
$token = (Get-AzAccessToken).Token
$token = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" (Get-AzAccessToken -AsSecureString).Token

$headers = @{
Authorization = "Bearer $token"
Expand Down
1 change: 1 addition & 0 deletions src/Functions/Functions/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Used `Get-AzAccessToken -AsSecureString` inside the `Functions` for the plain text version is going to be deprecate in the next release.

## Version 4.1.0
* Upgraded to Microsoft.Web API version 2023-12-01 [#25347]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ function Get-CallerPreference {

function GetHeaderWithAuthToken {

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ Function Create-ThreatIntelligenceIndicator{
# $null = $env.Add(($PSVerb+'threatIntelligenceIndicatorId'), $threatIntelligenceIndicatorId)
# $null = $env.Add(($PSVerb+'threatIntelligenceIndicatorIP'), $IP)
#}
$tiToken = (Get-AzAccessToken).Token
$tiToken = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" (Get-AzAccessToken -AsSecureString).Token
$tiHeaders = @{
Authorization="Bearer $tiToken"
Content='application/json'
Expand Down
4 changes: 2 additions & 2 deletions src/SecurityInsights/SecurityInsights.Autorest/test/utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ function setupEnv() {
$env.Tenant = (Get-AzContext).Tenant.Id

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

Expand Down
2 changes: 1 addition & 1 deletion src/ServiceLinker/ServiceLinker.Autorest/custom/Common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function Set-Header {
if($PSBoundParameters.ContainsKey("VNetSolutionType") -Or $PSBoundParameters.ContainsKey("SecretStoreKeyVaultId") `
-Or $provider -eq "microsoft.keyvault" -Or $resourceType -eq "flexibleservers") {
if(-Not $PSBoundParameters.ContainsKey('XmsServiceconnectorUserToken')){
$PSBoundParameters['XmsServiceconnectorUserToken'] = (Get-AzAccessToken).Token
$PSBoundParameters['XmsServiceconnectorUserToken'] = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" (Get-AzAccessToken -AsSecureString).Token
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ServiceLinker/ServiceLinker/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Used `Get-AzAccessToken -AsSecureString` inside the `ServiceLinker` for the plain text version is going to be deprecate in the next release.

## Version 0.2.1
* Introduced secrets detection feature to safeguard sensitive data.
Expand Down

0 comments on commit d576860

Please sign in to comment.