Skip to content

Commit

Permalink
Managed subtransport: support Default Credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
ethomson committed May 10, 2020
1 parent 9ee00e4 commit a5ef816
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 10 additions & 2 deletions LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions LibGit2Sharp/SmartSubtransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit a5ef816

Please sign in to comment.