简体   繁体   中英

Custom git credential helper fails to authenticate on windows

I have a custom credential helper executable written in C++ on Windows 10. It basically just std::couts the username and password with endl:

std::cout << "username=myuser" << std::endl;
std::cout << "password=mypassword" << std::endl;

The credential helper gets registered:

[credential "https://github.com/myuser/myrepo.git"]
     helper = C:/Users/myuser/helper/GitCredentialManager.exe

The credential helper is called but fails to authenticate for the remote (I tested github and gitlab)

remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/myuser/myrepo.git'

2FA is disabled and I also tried to provide an access token instead of a password.

I also tried to use printf instead of std::cout. I called std::cout.flush() Is there anything that I am doing wrong / do I miss any windows particularities? This works perfectly fine on macOS .

You might be missing the protocol line, as seen in the " Under the Hood " section.

$ git credential fill (1)
protocol=https (2)
host=mygithost
(3)
protocol=https (4)
host=mygithost
username=bob
password=s3cre7

Git-credential is then waiting for input on stdin. We provide it with the things we know: the protocol and hostname.

A blank line indicates that the input is complete, and the credential system should answer with what it knows.

But don't forget you also have the Microsoft Git Credential Manager for Mac and Linux , which would handle all that in a secure way.

On windows I had to add the null terminator to make it work.

std::cout << "username=myuser\0" << std::endl;
std::cout << "password=mypassword\0" << std::endl;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM