Skip to content

Commit 22819a0

Browse files
committed
github: store the PAT on 'get' request for SAML SSO
In order to allow a user that requires SAML SSO to be manually enabled on their newly generated PATs to access org repos, we must store the PAT as soon as we generate it. This then allows the user the ability to visit the web UI, enable SSO, and then repeat their Git operation using the _same PAT_. Workaround for issue: #133
1 parent 86290d7 commit 22819a0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/shared/GitHub/GitHubHostProvider.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,16 @@ public override async Task<ICredential> GenerateCredentialAsync(InputArguments i
8989
switch (promptResult.AuthenticationMode)
9090
{
9191
case AuthenticationModes.Basic:
92-
return await GeneratePersonalAccessTokenAsync(targetUri, promptResult.BasicCredential);
92+
ICredential patCredential = await GeneratePersonalAccessTokenAsync(targetUri, promptResult.BasicCredential);
93+
// HACK: Store the PAT immediately in case this PAT is not valid for SSO.
94+
// We don't know if this PAT is valid for SAML SSO and if it's not Git will fail
95+
// with a 403 and call neither 'store' or 'erase'. The user is expected to fiddle with
96+
// the PAT permissions manually on the web and then retry the Git operation.
97+
// We must store the PAT now so they can resume/repeat the operation with the same,
98+
// now SSO authorized, PAT.
99+
// See: https://github.com/microsoft/Git-Credential-Manager-Core/issues/133
100+
Context.CredentialStore.AddOrUpdate(GetCredentialKey(input), patCredential);
101+
return patCredential;
93102

94103
case AuthenticationModes.OAuth:
95104
return await GenerateOAuthCredentialAsync(targetUri);

0 commit comments

Comments
 (0)