Road to ALM

Using Personal Access Tokens to access Visual Studio Online

Published by

on

People who use Visual Studio Online for a while are probably familiar with the alternate credentials. These are used when accessing the REST API or when using an external client for accessing your Git repositories.

You configure your alternate credentials on your [My Profile] page and fill a username and password of your choice.

image

Once you enable your credentials, you can use these credentials when doing a REST call or (easier to test) clone a Git repository

image

This is great but not the most secure way of doing things.

Personal Access Tokens

In the update of July 7th, we now have the ability to use Personal Access Tokens as an alternative to the Alternate Credentials. Instead of sending our username and password over the wire we an now use a secure token that we can scope to a timeframe and to functionality within VSO. On the [My Profile] page you can configure one or more Personal Access Tokens. For example a token to access Code Features.

image

When you create the token, you see a token (only visible after creation !) that you should copy and keep safe.

image

This token alone is sufficient to authenticate against VSO. So when you now clone a Git repository you only have to fill in this token in the password box. Username can be empty or any value

image

The great thing is that you can revoke rights or the token afterwards and make sure that people cannot access stuff anymore.

Hope this helps!

24 responses to “Using Personal Access Tokens to access Visual Studio Online”

  1. Travis Avatar
    Travis

    How do you actually use one of these things? Do I just send the personal access token as the value of the authorization header in the request? Does it have to be formatted some certain way? I’m using Casablanca for a command line tool and I can’t get it to authenticate using a personal access token against the REST APIs. This all seems to be too new to have much around the net about using it, this and one other blog post announcing it are all I found. Any docs that get into the specifics of the handshake?

    1. Rene van Osnabrugge Avatar

      I used Postman in Google Chrone as App Postman sends the value in the header. Just like the basic authentication. Hope this helps !

  2. […] a Personal Access Token (PAT) to access Visual Studio Online through the app. Personal Access Tokens are a more secure way of […]

  3. […] also use the newly introduced personal access tokens (you can read more about that in this post of Rene van […]

  4. Morious Avatar
    Morious

    Is there a way to set the access token in a config so I don’t have to copy paste it?
    I know VSO is working on SSH support but in the meanwhile….
    Thx.

    1. Rene van Osnabrugge Avatar

      What config do you mean ?

    2. Zhong Xun Avatar

      I use powershell to read token from config file and replace it to url like this https://token@xxx.visualstudio.com/DefaultCollection/XXX/_git/xxx

  5. Zhong Xun Avatar

    Sorry for an irrelevant question! Which tool you used for drawing frame and curved line?

    1. Rene van Osnabrugge Avatar

      Paint.net 🙂

      1. zhongxun1975 Avatar

        That tool is cool. Your article is great!

  6. mkruger777 Avatar

    Silly Question :- )
    But is this functionality also available in the normal “non-cloud version” of TFS 2015 ?

    1. Rene van Osnabrugge Avatar

      Nope…

      1. mkruger777 Avatar

        Bummer.Thanks for your answer!

  7. Call VSTS REST API from Release Management | The Road to ALM Avatar

    […] Instead of the variable you get out of the box, you need to create a Personal Access Token (PAT). I describe how to do that in this blogpost […]

  8. Controlling build quality using Build Tags and VSTS Release Management | The Road to ALM Avatar

    […] I also have a RestToken as a parameter. When we do not use the Release pipeline, we can just send a Personal Access Token to use this script from the command line as […]

  9. Programmatically promote your package quality with Release Views in VSTS | The Road to ALM Avatar

    […] First create a Personal Access Token (as described here ) […]

  10. […] First create a Personal Access Token (as described here ) […]

  11. Using VSTS Package Management as a private Powershell Gallery | The Road to ALM Avatar

    […] Now that you have published your module to the Package Repo, you can use it in Powershell. To connect securely you need your VSTS user account (email) and Personal Access Token (See here how to generate one) […]

  12. Using VSTS Package Management as a private Chocolatey Gallery | The Road to ALM Avatar

    […] Generate  a Personal Access Token to use the functionality of Package Management […]