Skip to content

Commit 10cc8f4

Browse files
Use AAD auth for PublishAzureWebApps (#21628)
* Use AAD auth for PublishAzureWebApps * Update ChangeLog.md --------- Co-authored-by: Yunchi Wang <[email protected]>
1 parent 03a6109 commit 10cc8f4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/Websites/Websites/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 AAD Auth instead of Basic Auth for PublishAzureWebApps
2122

2223
## Version 2.15.0
2324
* Fixed Tag parameter issues with ASE for `New-AzWebApp`

src/Websites/Websites/Cmdlets/WebApps/PublishAzureWebApp.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// ----------------------------------------------------------------------------------
1515

1616

17+
using Microsoft.Azure.Commands.Common.Authentication;
1718
using Microsoft.Azure.Commands.WebApps.Models;
1819
using Microsoft.Azure.Management.WebSites.Models;
1920
using Microsoft.WindowsAzure.Commands.Utilities.Common;
@@ -22,6 +23,7 @@
2223
using System.Management.Automation;
2324
using System.Net;
2425
using System.Net.Http;
26+
using System.Net.Http.Headers;
2527
using System.Text;
2628
using System.Threading;
2729

@@ -85,8 +87,9 @@ public override void ExecuteCmdlet()
8587
client.Timeout = TimeSpan.FromMilliseconds(Timeout);
8688
}
8789

88-
var byteArray = Encoding.ASCII.GetBytes(user.PublishingUserName + ":" + user.PublishingPassword);
89-
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
90+
var token = WebsitesClient.GetAccessToken(DefaultContext);
91+
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token.AccessToken);
92+
9093
HttpContent fileContent = new StreamContent(s);
9194
fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/zip");
9295
r = client.PostAsync(deployUrl, fileContent).Result;
@@ -126,6 +129,5 @@ public override void ExecuteCmdlet()
126129
PSSite app = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, Name, Slot));
127130
WriteObject(app);
128131
}
129-
130132
}
131133
}

0 commit comments

Comments
 (0)