How do I authenticate to Visual Studio Team Services and Team Foundation Server with a Personal Access Token?

有些话、适合烂在心里 提交于 2019-12-04 13:48:16

问题


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)?


回答1:


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

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)")) } 

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.



来源:https://stackoverflow.com/questions/33734201/how-do-i-authenticate-to-visual-studio-team-services-and-team-foundation-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!