I am developing a custom git credential helper using java and trying to implement azure device code flow in the background. As part of implementation i have to print URL and device code on console which user will use for authentication then press ENTER on the console , but git terminal hangs after printing the URL and device code. Below is my code.
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 ...");
}
}
I have my code bundled as a jar and I have below in my gitconfig.
[credential]
helper = "!java -jar D:/config/git-credential-helper.jar"
When I do git operation like git clone I am getting below warning and it just hangs there
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.