From a5ef816147adcc0776440b93bca684ef8cc2a160 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sun, 10 May 2020 22:50:47 +0100 Subject: [PATCH] Managed subtransport: support Default Credentials --- LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs | 12 ++++++++++-- LibGit2Sharp/SmartSubtransport.cs | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs b/LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs index 8af18398f..573121f6e 100644 --- a/LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs +++ b/LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs @@ -199,8 +199,16 @@ private HttpResponseMessage GetResponseWithRedirects() throw new InvalidOperationException("authentication cancelled"); } - UsernamePasswordCredentials userpass = (UsernamePasswordCredentials)cred; - credentials = new NetworkCredential(userpass.Username, userpass.Password); + if (cred is DefaultCredentials) + { + credentials = CredentialCache.DefaultNetworkCredentials; + } + else if (cred is UsernamePasswordCredentials) + { + UsernamePasswordCredentials userpass = (UsernamePasswordCredentials)cred; + credentials = new NetworkCredential(userpass.Username, userpass.Password); + } + continue; } else if (response.StatusCode == HttpStatusCode.Moved || response.StatusCode == HttpStatusCode.Redirect) diff --git a/LibGit2Sharp/SmartSubtransport.cs b/LibGit2Sharp/SmartSubtransport.cs index a8156ef54..66fcd12bf 100644 --- a/LibGit2Sharp/SmartSubtransport.cs +++ b/LibGit2Sharp/SmartSubtransport.cs @@ -106,6 +106,10 @@ public int AcquireCredentials(out Credentials cred, string user, params Type[] m { allowed |= (int)GitCredentialType.UserPassPlaintext; } + else if (method == typeof(DefaultCredentials)) + { + allowed |= (int)GitCredentialType.Default; + } else { throw new InvalidOperationException("Unknown type passes as allowed credential"); @@ -133,6 +137,9 @@ public int AcquireCredentials(out Credentials cred, string user, params Type[] m case GitCredentialType.UserPassPlaintext: cred = UsernamePasswordCredentials.FromNative((GitCredentialUserpass*) credHandle); return 0; + case GitCredentialType.Default: + cred = new DefaultCredentials(); + return 0; default: throw new InvalidOperationException("User returned an unkown credential type"); }