0

As I read at Creating a personal access token and Where to store the personal access token from GitHub? I understand that Git requires from the user on the local machine at first use to enter PAT and then stores it with Windows Credentials Manager if Windows or credentialStore for Linux/MacOS.

I created a Nodejs app that use nodegit(libgit2) to fetch or clone a git repository. For doing so, I need to provide a PAT. I tried to get the PAT from Windows Credentials Manager but couldn't find an npm package that works to do so.

What is the best practice to get the PAT for app use that use Git? Should I get it as I said in the first paragraph from the local machine using Windows Credentials Manager or credentialStore, or should I prompt the user to enter the PAT once and save it? If so, how should I save it? It will be unsafe to save the PAT in plain text as is. And where the file which I'm saving the PAT should be located? C:/users/USER or in the repository directory and add the file to .gitignore?

Tal
  • 613
  • 1
  • 7
  • 19
  • You should not need any npm package to get the credential from the credential manager. All you do is run the credential manager with the "get" command. – torek Oct 20 '21 at 19:47
  • And what about Linux/MacOS? – Tal Oct 21 '21 at 14:05
  • You'd still do the same thing: use `git config` to read the possible credential managers, then run them with `get` as Git would to have then read out the credentials. That's assuming you want to duplicate exactly what Git does: if not, do whatever it is you want to do here. You will of course still have an issue with what to do if there's no PAT found in any existing credential manager. But that's why this is a comment, not an answer. – torek Oct 21 '21 at 15:55
  • @torek Please show an exmaple of how to extract PAT from Linux. With Windows managed to do so with `git credential-wincred get`. What is the command in Linux? `git credential-store get` didn't work – Tal Oct 23 '21 at 09:23
  • See https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage for a number of examples, including a private method written in Ruby. I don't actually *use* credentials this way myself, so I have no pre-packaged examples. (I use ssh, which has its own entirely separate method.) – torek Oct 23 '21 at 20:34

0 Answers0