Cloning Git Repo using TFS Personal Access Token

后端 未结 4 1267
醉话见心
醉话见心 2021-02-02 17:23

I am trying to programmatically clone a git repository. My ASP.NET MVC application is creating and starting a process. The code to handle the processes works correctly however t

4条回答
  •  轮回少年
    2021-02-02 17:42

    I was a bit confused after reading the article from MS. After trying out some ways, I was finally able to use my PAT against TFS and VSTS GIT Repos.

    The only way I was able to get a clone of my GIT repo using a PAT was setting the http.extraheader in the GIT commandline.
    The authorization tag must point to basic authentication, the protocol must be HTTPS, and the token must be BASE64 encoded, including a (fictional) user name.

    Example:

    git -c http.extraheader="AUTHORIZATION: Basic TXlHaXRTeW5jVXNlcjo2bHFqNXJkcHEzdXBxZWVmd2o3bDduZXN5NTR3d3gxNHFobDVlanl5NTVkb2g0M3d4YzRh" clone https://tfs.address/tfs/Collection/Project/_git/RepoName
    

    Used basic token BASE64 encoded:

    TXlHaXRTeW5jVXNlcjo2bHFqNXJkcHEzdXBxZWVmd2o3bDduZXN5NTR3d3gxNHFobDVlanl5NTVkb2g0M3d4YzRh

    Basic Token BASE64 decoded:

    MyGitSyncUser:6lqj5rdpq3upqeefwj7l7nesy54wwx14qhl5ejyy55doh43wxc4a

    Token is constructed from :

    In this example:

    Fictional user name: MyGitSyncUser Used PAT: 6lqj5rdpq3upqeefwj7l7nesy54wwx14qhl5ejyy55doh43wxc4a

    PAT scope: Code (Read)

    The TFS/VSTS doesn't accept "AUTHORIZATION: Bearer" headers at the moment :(

    Maybe this will help someone using the PATs in TFS/VSTS.

    Note: HTTPS is needed for BASIC Authentication!

提交回复
热议问题