我正在使用 java 开发自定义 git 凭据帮助程序,并尝试在后台实现 azure 设备代码流。作为实现的一部分,我必须在用户将用于身份验证的控制台上打印 URL 和设备代码,然后在控制台上按 ENTER,但打印 URL 和设备代码后 git 终端挂起。下面是我的代码。
public class GitHelper {
public static void main(String[] args) {
String op = args[0];
switch (op) {
case "get":
System.out.printf("username=%s\n", "oauth2");
System.out.printf("password=%s\n", getToken());
break;
default:
System.out.println(args[0]);
break;
}
}
}
public void waitForUser() {
System.out.println("To sign in, use a web browser to open the page " + URL
+ "\n and enter the code " + code
+ " to authenticate then return to this window and press ENTER.");
Callable<String> userInput = () -> new Scanner(System.in).nextLine();
String res = getUserInputWithTimeout(TIMEOUT, userInput); // 30s until timeout
if (res != null) {
System.out.println("Validating Authentication ...");
}
}
我将我的代码捆绑为一个 jar,并且在我的 gitconfig 中有以下内容。
[credential]
helper = "!java -jar D:/config/git-credential-helper.jar"
当我执行 git clone 之类的 git 操作时,我收到以下警告,它只是挂在那里
warning: invalid credential line: To sign in, use a web browser to open the page www.login.com and enter the code 324523453425 to authenticate then return to this window and press ENTER.