-
Notifications
You must be signed in to change notification settings - Fork 2
/
Authenticable.cpp
46 lines (38 loc) · 1.6 KB
/
Authenticable.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "Authenticable.h"
using Authenticable = Git::Authenticable;
git_cred_acquire_cb Authenticable::getCredentialsCallbackWrapper(AuthenticationCallback getUserCredentialsCallback
/* = nullptr */
) const
{
if(nullptr == getUserCredentialsCallback)
{
return git_cred_userpass;
}
else
{
return [](git_cred** credentials
, const char* url
, const char *username_from_url
, unsigned int allowed_types
, void* payload
) -> int
{
(void)url;
(void)username_from_url;
(void)allowed_types;
AuthenticationCallback& applicationCallback =
*static_cast<AuthenticationCallback*>(payload);
Authenticable::Credentials applicationCredentials = applicationCallback();
if(applicationCredentials.isEmpty())
{
return GIT_EUSER;
}
std::string username = applicationCredentials.getUsername();
std::string password = applicationCredentials.getPassword();
return git_cred_userpass_plaintext_new(credentials
, username.c_str()
, password.c_str()
);
};
}
}