I am able to push to remote with this piece of code
return git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)).setRemote("origin").call();
I also am able to get oauth access token with all necessary scopes. How do I push with access token?
Updating an existing Access Token If your existing token has expired, or been revoked, or you are on a new machine and do not have access to the existing token then you can regerate a new one in the Github console Settings -> Developer settings -> Personal access tokens .
You need to pass a UsernamePasswordCredentialsProvider
with the token as its user name.
String remoteUrl = "https://${token}@github.com/user/repo.git";
CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider("${token}", "");
git.push().setRemote(remoteUrl).setCredentialsProvider(credentialsProvider).call();
The above can at least be used to authenticate with a GitHub repository. Though, I can't say if this scheme works generally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With