Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/shared/Core/Authentication/OAuth/OAuth2Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ public async Task<OAuth2TokenResult> GetTokenByRefreshTokenAsync(string refreshT
{
return result;
}

throw CreateExceptionFromResponse(json);
}
}
Expand Down
46 changes: 25 additions & 21 deletions src/shared/Core/Core.csproj
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OSPlatform)'=='windows'">net6.0;net472</TargetFrameworks>
<AssemblyName>gcmcore</AssemblyName>
<RootNamespace>GitCredentialManager</RootNamespace>
<IsTestProject>false</IsTestProject>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OSPlatform)'=='windows'">net6.0;net472</TargetFrameworks>
<AssemblyName>gcmcore</AssemblyName>
<RootNamespace>GitCredentialManager</RootNamespace>
<IsTestProject>false</IsTestProject>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
<Reference Include="System.Net.Http" />
<Reference Include="System.Web" />
<PackageReference Include="Microsoft.Identity.Client.Desktop" Version="4.37.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.37.0" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.19.2" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21216.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
<Reference Include="System.Net.Http" />
<Reference Include="System.Web" />
<PackageReference Include="Microsoft.Identity.Client.Desktop" Version="4.37.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.37.0" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.19.2" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21216.1" />
</ItemGroup>

</Project>
25 changes: 17 additions & 8 deletions src/shared/Core/GenericHostProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,27 @@ private async Task<ICredential> GetOAuthAccessToken(Uri remoteUri, string userNa
ICredential refreshToken = Context.CredentialStore.Get(refreshService, userName);
if (refreshToken != null)
{
var refreshResult = await client.GetTokenByRefreshTokenAsync(refreshToken.Password, CancellationToken.None);
try
{
var refreshResult = await client.GetTokenByRefreshTokenAsync(refreshToken.Password, CancellationToken.None);

// Store new refresh token if we have been given one
if (!string.IsNullOrWhiteSpace(refreshResult.RefreshToken))
{
Context.CredentialStore.AddOrUpdate(refreshService, refreshToken.Account, refreshToken.Password);
}
// Store new refresh token if we have been given one
if (!string.IsNullOrWhiteSpace(refreshResult.RefreshToken))
{
Context.CredentialStore.AddOrUpdate(refreshService, refreshToken.Account, refreshToken.Password);
}

// Return the new access token
// Return the new access token
return new GitCredential(oauthUser,refreshResult.AccessToken);
}
}
catch (OAuth2Exception ex)
{
Context.Trace.WriteLine($"OAuth2Exception: {ex.Message},remove it");
Context.CredentialStore.Remove(refreshService, refreshToken.Account);
throw;
}

}
// Determine which interactive OAuth mode to use. Start by checking for mode preference in config
var supportedModes = OAuthAuthenticationModes.All;
if (Context.Settings.TryGetSetting(
Expand Down