簡體   English   中英

自定義 git 憑證助手無法在 windows 上進行身份驗證

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM