如何使用个人访问令牌向Visual Studio Team Services和Team Foundation Server进行身份验证? [英] How do I authenticate to Visual Studio Team Services and Team Foundation Server with a Personal Access Token?

查看:139
本文介绍了如何使用个人访问令牌向Visual Studio Team Services和Team Foundation Server进行身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从PowerShell中使用个人访问令牌(PAT)对我的Visual Studio Team Services(VSTS)帐户或本地Team Foundation Server(TFS)进行身份验证?

From PowerShell, how do I use Personal Access Tokens (PAT) to authenticate to my Visual Studio Team Services (VSTS) account or on-premises Team Foundation Server (TFS)?

推荐答案

As of July 2015, Visual Studio Online allows users to create Personal Access Tokens (PAT) as a more secure option than alternate credentials.

要通过 REST API 进行身份验证,只需使用PAT作为基本身份验证 HTTP标头中的密码部分以及您的REST请求.

To authenticate to the REST APIs, all you need to do is use the PAT as the password portion in a Basic Auth HTTP Header along with your REST request.

$personalAccessToken = "your-personal-access-token-here"
$uri = "https://your-account.visualstudio.com/DefaultCollection/_apis/wit/workitems?api-version=1.0&ids=1,2,3,4"

Invoke-RestMethod `
-Uri $uri `
-Headers @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($personalAccessToken)")) } 

请注意,当您使用个人访问令牌时,基本身份验证标头的用户名部分将被完全忽略.您可以改用("BLAHBLAH:$($personalAccessToken)")),它仍然可以正常工作.

Note, that the username portion of the Basic Auth header is completely ignored when you use a personal access token. You could have ("BLAHBLAH:$($personalAccessToken)")) instead and it will still work fine.

这篇关于如何使用个人访问令牌向Visual Studio Team Services和Team Foundation Server进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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