FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
git2cpp/src/utils/credentials.cpp at 0.0.12 · QuantStack/git2cpp · GitHub
QuantStack
git2cpp
Repository navigation
Code
Issues
6
(6)
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
git2cpp
/
src
/
utils
/
credentials.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (45 loc) · 1.51 KB
Breadcrumbs
git2cpp
/
src
/
utils
/
credentials.cpp
Copy path
File metadata and controls
55 lines (45 loc) · 1.51 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
47
48
49
50
51
52
53
54
55
#
include
"
credentials.hpp
"
#
include
<
iostream
>
#
include
<
git2/credential.h
>
#
include
"
input_output.hpp
"
//
git_credential_acquire_cb
int
user_credentials
(
git_credential** out,
const
char
* url,
const
char
* username_from_url,
unsigned
int
allowed_types,
void
* payload
)
{
//
Check for cached credentials here, if desired.
//
It might be necessary to make this function stateful to avoid repeating unnecessary checks.
*out =
nullptr
;
if
(allowed_types &
GIT_CREDENTIAL_USERPASS_PLAINTEXT
)
{
std::string username = username_from_url ? username_from_url :
"
"
;
if
(username.
empty
())
{
username =
trim
(
prompt_input
(
"
Username:
"
));
}
if
(username.
empty
())
{
giterr_set_str
(
GIT_ERROR_HTTP
,
"
No username specified
"
);
return
GIT_EAUTH
;
}
std::string password =
trim
(
prompt_input
(
"
Password:
"
,
false
));
if
(password.
empty
())
{
giterr_set_str
(
GIT_ERROR_HTTP
,
"
No password specified
"
);
return
GIT_EAUTH
;
}
//
If successful, this will create and return a git_credential* in the out argument.
return
git_credential_userpass_plaintext_new
(out, username.
c_str
(), password.
c_str
());
}
giterr_set_str
(
GIT_ERROR_HTTP
,
"
Unexpected credentials request
"
);
return
GIT_ERROR
;
}
bool
want_user_credentials
()
{
const
char
* env_var =
std::getenv
(
"
GIT_CREDENTIAL_CALLBACK
"
);
return
env_var ==
nullptr
||
std::string_view
(env_var) !=
"
0
"
;
}
Back
|
FazBrowse Home
|
New Git URL