Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 2c20161

Browse files
committed
Create the git: credential on login.
Previously `WindowsLoginCache` was only creating a `https://github.com` entry with the username and token in the windows credential manager. It also needs to create a `git:https://github.com` entry. Fixes #1173.
1 parent 8cd4641 commit 2c20161

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/GitHub.Api/WindowsLoginCache.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ public Task SaveLogin(string userName, string password, HostAddress hostAddress)
3939
Guard.ArgumentNotEmptyString(password, nameof(password));
4040
Guard.ArgumentNotNull(hostAddress, nameof(hostAddress));
4141

42+
var keyGit = GetKeyGit(hostAddress.CredentialCacheKeyHost);
4243
var keyHost = GetKeyHost(hostAddress.CredentialCacheKeyHost);
4344

45+
using (var credential = new Credential(userName, password, keyGit))
46+
{
47+
credential.Save();
48+
}
49+
4450
using (var credential = new Credential(userName, password, keyHost))
4551
{
4652
credential.Save();
@@ -54,8 +60,16 @@ public Task EraseLogin(HostAddress hostAddress)
5460
{
5561
Guard.ArgumentNotNull(hostAddress, nameof(hostAddress));
5662

63+
var keyGit = GetKeyGit(hostAddress.CredentialCacheKeyHost);
5764
var keyHost = GetKeyHost(hostAddress.CredentialCacheKeyHost);
5865

66+
using (var credential = new Credential())
67+
{
68+
credential.Target = keyGit;
69+
credential.Type = CredentialType.Generic;
70+
credential.Delete();
71+
}
72+
5973
using (var credential = new Credential())
6074
{
6175
credential.Target = keyHost;
@@ -66,6 +80,17 @@ public Task EraseLogin(HostAddress hostAddress)
6680
return Task.CompletedTask;
6781
}
6882

83+
static string GetKeyGit(string key)
84+
{
85+
key = FormatKey(key);
86+
// it appears this is how MS expects the host key
87+
if (!key.StartsWith("git:", StringComparison.Ordinal))
88+
key = "git:" + key;
89+
if (key.EndsWith("/", StringComparison.Ordinal))
90+
key = key.Substring(0, key.Length - 1);
91+
return key;
92+
}
93+
6994
static string GetKeyHost(string key)
7095
{
7196
key = FormatKey(key);

0 commit comments

Comments
 (0)