gitauthenticator.cpp 970 B

12345678910111213141516171819202122232425262728293031
  1. #include "gitauthenticator.h"
  2. #include <QDir>
  3. #include <QDebug>
  4. #include <git2/transport.h>
  5. namespace {
  6. QString DefaultPublicKey = QDir::homePath() + QString("/.ssh/id_rsa.pub");
  7. QString DefaultPrivateKey = QDir::homePath() + QString("/.ssh/id_rsa");
  8. }
  9. GitAuthenticator::GitAuthenticator()
  10. {
  11. }
  12. int GitAuthenticator::authenticate(GitRemote *remote, git_cred **credentials, const char *usernameFromUrl, unsigned int allowedTypes)
  13. {
  14. if(allowedTypes & GIT_CREDTYPE_SSH_KEY) {
  15. return authenticateSsh(remote, credentials, usernameFromUrl);
  16. } else {
  17. qWarning() << "Only ssh key-based authentication possible";
  18. }
  19. return -1;
  20. }
  21. int GitAuthenticator::authenticateSsh(GitRemote* remote, git_cred **credentials, const char* usernameFromUrl)
  22. {
  23. //TODO: here might be advanced logic for key authentication
  24. return git_cred_ssh_key_new(credentials, usernameFromUrl, DefaultPublicKey.toUtf8().data(), DefaultPrivateKey.toUtf8().data(), "");
  25. }