Azure 网站 Kudu REST API - 身份验证 [英] Azure Websites Kudu REST API - Authentication

查看:34
本文介绍了Azure 网站 Kudu REST API - 身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PowerShell 通过 REST API 将更新的内容文件放到 Azure 网站上.但是,当将我的凭据提供给 Invoke-RestMethod -Credentials 时,我会返回标准 Azure 登录页面的 HTML.

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 -Credentials I am returned the HTML of the standard Azure login page.

如何从 PowerShell 使用 Kudu 进行身份验证?谢谢.

How can I authenticate with Kudu from PowerShell? Thanks.

推荐答案

您可以先通过 Powershell 获取网站,然后使用网站的发布凭据调用 Kudu REST API.下面的示例将获得 Kudu 版本.

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

这篇关于Azure 网站 Kudu REST API - 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆