Search code examples
azureazure-devopsoauth-2.0

Using OAuth2 token of Azure DevOps Services Application to Clone a Git repository


I have an Azure DevOps Services Application, the kind which you make at https://app.vsaex.visualstudio.com/me and it has vso.code vso.graph vso.identity vso.project scopes. I have an OAuth2 access token for this application, which I've used to work with the Azure DevOps REST API, and that works fine.

Now I want to use this token to clone a git repository from a private project.

I have tried:

"https://roklenarcic0820:<FORM encoded access token>@dev.azure.com/roklenarcic0820/PrivateProj/_git/PrivateProj"

I've form encoded the access token because it contains characters that cannot be used in URL. This doesn't work.

Is there some way to accomplish this, without PATs?


Solution

  • Yes, the OAuth2 access token will indeed work in this case, the trick is that you should not encode the access token, just pass it in the git command like below.

    git clone https://orgname:<access_token>@dev.azure.com/orgname/projectname/_git/reponame
    

    Also have test with an access token with the same permissions as yours, it works fine on my side.:

    enter image description here

    enter image description here