8000 Managed subtransport: support Default Credentials · dotdevelop/libgit2sharp@a5ef816 · GitHub
[go: up one dir, main page]

Skip to content

Commit a5ef816

Browse files
committed
Managed subtransport: support Default Credentials
1 parent 9ee00e4 commit a5ef816

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,16 @@ private HttpResponseMessage GetResponseWithRedirects()
199199
throw new InvalidOperationException("authentication cancelled");
200200
}
201201

202-
UsernamePasswordCredentials userpass = (UsernamePasswordCredentials)cred;
203-
credentials = new NetworkCredential(userpass.Username, userpass.Password);
202+
if (cred is DefaultCredentials)
203+
{
204+
credentials = CredentialCache.DefaultNetworkCredentials;
205+
}
206+
else if (cred is UsernamePasswordCredentials)
207+
{
208+
UsernamePasswordCredentials userpass = (UsernamePasswordCredentials)cred;
209+
credentials = new NetworkCredential(userpass.Username, userpass.Password);
210+
}
211+
204212
continue;
205213
}
206214
else if (response.StatusCode == HttpStatusCode.Moved || response.StatusCode == HttpStatusCode.Redirect)

LibGit2Sharp/SmartSubtransport.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ public int AcquireCredentials(out Credentials cred, string user, params Type[] m
106106
{
107107
allowed |= (int)GitCredentialType.UserPassPlaintext;
108108
}
109+
else if (method == typeof(DefaultCredentials))
110+
{
111+
allowed |= (int)GitCredentialType.Default;
112+
}
109113
else
110114
{
111115
throw new InvalidOperationException("Unknown type passes as allowed credential");
@@ -133,6 +137,9 @@ public int AcquireCredentials(out Credentials cred, string user, params Type[] m
133137
case GitCredentialType.UserPassPlaintext:
134138
cred = UsernamePasswordCredentials.FromNative((GitCredentialUserpass*) credHandle);
135139
return 0;
140+
case GitCredentialType.Default:
141+
cred = new DefaultCredentials();
142+
return 0;
136143
default:
137144
throw new InvalidOperationException("User returned an unkown credential type");
138145
}

0 commit comments

Comments
 (0)
0