[英]Custom git credential helper fails to authenticate on windows
我在 Windows 10 上有一个用 C++ 编写的自定义凭据帮助程序可执行文件。它基本上只是 std::couts 使用 endl 的用户名和密码:
std::cout << "username=myuser" << std::endl;
std::cout << "password=mypassword" << std::endl;
凭证助手被注册:
[credential "https://github.com/myuser/myrepo.git"]
helper = C:/Users/myuser/helper/GitCredentialManager.exe
调用凭证助手但无法对远程进行身份验证(我测试了 github 和 gitlab)
remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/myuser/myrepo.git'
2FA 已禁用,我还尝试提供访问令牌而不是密码。
我还尝试使用 printf 而不是 std::cout。 我打电话给 std::cout.flush() 有什么我做错了/我错过了任何 windows 的特殊性吗? 这在 macOS 上运行良好。
您可能缺少协议行,如“ 幕后”部分所示。
$ git credential fill (1)
protocol=https (2)
host=mygithost
(3)
protocol=https (4)
host=mygithost
username=bob
password=s3cre7
然后 Git-credential 正在等待 stdin 上的输入。 我们为它提供我们知道的东西:协议和主机名。
空白行表示输入已完成,凭证系统应以它所知道的内容进行回答。
但不要忘记,您还拥有适用于 Mac 的 Microsoft Git Credential Manager 和 Linux ,它们将以安全的方式处理所有这些。
在 windows 上,我必须添加 null 终结器才能使其工作。
std::cout << "username=myuser\0" << std::endl;
std::cout << "password=mypassword\0" << std::endl;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.