Azure Websites Kudu REST API - Authentication

前端 未结 2 725
Happy的楠姐
Happy的楠姐 2020-11-29 10:27

I\'m trying to use PowerShell to put an updated content file onto an Azure Website via the REST API. However, when supplying my credentials into Invoke-RestMethod -Cre

2条回答
  •  青春惊慌失措
    2020-11-29 11:15

    You can first get the website via Powershell and then use the publish credentials from the website to call the Kudu REST API. The example below will get the Kudu version.

    $website = Get-AzureWebsite -Name "WebsiteName"
    
    $username = $website.PublishingUsername
    $password = $website.PublishingPassword
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
    
    $apiBaseUrl = "https://$($website.Name).scm.azurewebsites.net/api"
    
    $kuduVersion = Invoke-RestMethod -Uri "$apiBaseUrl/environment" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET
    

提交回复
热议问题