如何以自动化方式管理 VSTS 扩展密钥?

How to manage VSTS extension keys in automated manner?

我正在使用我的 VSTS extension key to authenticate request to my service。获得我所知道的扩展的唯一方法是通过 VSTS Marketplace UI,如链接文档中所述。

我的问题是:

  1. 是否有自动访问扩展密钥的方法,以便我可以自动轮换它?
  2. 密钥什么时候过期?我怎样才能自己解决这个问题?

关于key过期,可以在这里查看:https://jwt.io/ or programming, such as PowerShell: Validating JSON Web Token (JWT) with PowerShell

您可以使用 Powershell RestAPI 获取证书:

首先,您需要从您的 VSTS 帐户创建个人访问令牌(确保 PAT 用于 "All accessible account"),您可以将 PAT 的范围仅限于市场或 "All Scopes" - 您的选择.

然后在 Powershell 中使用此代码:

# Define credentials
$credPair = "YourMailAccount:YourPAT"
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair))                        
$certificateUrl = 'https://marketplace.visualstudio.com/_apis/gallery/publishers/<YourPublisherName>/extensions/<ExtensionId>/certificates/latest'

# Call the REST API
Invoke-RestMethod -Uri $certificateUrl -OutFile "ExtensionCert.txt"  -Headers @{Authorization = "Basic $encodedCredentials"}