Skip to content

Commit 8be3f95

Browse files
authored
Merge pull request #16 from Microsoft/users/aldoms/userAgent
Users/aldoms/user agent
2 parents 66555b3 + 54de0c6 commit 8be3f95

File tree

7 files changed

+47
-7
lines changed

7 files changed

+47
-7
lines changed

CredentialProvider.Microsoft.VSIX/Microsoft.CredentialProvider.swixproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Import Project="packages\MicroBuild.Core.0.3.0\build\MicroBuild.Core.props" />
44

55
<PropertyGroup>
6-
<ProductVersion>0.1.1</ProductVersion>
6+
<ProductVersion>0.1.2</ProductVersion>
77
<ProjectGuid>4966bd57-3289-44a3-9698-f750a35b726b</ProjectGuid>
88
<SchemaVersion>2.0</SchemaVersion>
99
<OutputArchitecture>neutral</OutputArchitecture>

CredentialProvider.Microsoft.VSIX/Microsoft.CredentialProvider.swr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use vs
22

33
package name=Microsoft.CredentialProvider
4-
version=0.1.1
4+
version=0.1.2
55

66
folder InstallDir:\Common7\IDE\CommonExtensions\Microsoft\NuGet\Plugins\CredentialProvider.Microsoft
77
file source=$(PluginBinPath)\CredentialProvider.Microsoft.exe

CredentialProvider.Microsoft/CredentialProvider.Microsoft.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
66
<LangVersion>latest</LangVersion>
77
<ApplicationIcon>helpericons.ico</ApplicationIcon>
8-
<Version>0.1.1</Version>
8+
<Version>0.1.2</Version>
99
</PropertyGroup>
1010

1111
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

CredentialProvider.Microsoft/CredentialProvider.Microsoft.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<metadata>
44
<id>Microsoft.NuGet.CredentialProvider</id>
5-
<version>0.1.1$VersionSuffix$</version>
5+
<version>0.1.2$VersionSuffix$</version>
66
<title>Microsoft Credential Provider for NuGet</title>
77
<authors>Microsoft</authors>
88
<owners>microsoft,nugetvss</owners>

CredentialProvider.Microsoft/CredentialProviders/Vsts/IAuthUtil.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ protected virtual async Task<HttpResponseHeaders> GetResponseHeadersAsync(Uri ur
115115
using (var httpClient = new HttpClient())
116116
using (var request = new HttpRequestMessage(HttpMethod.Get, uri))
117117
{
118+
foreach (var userAgent in Program.UserAgent)
119+
{
120+
httpClient.DefaultRequestHeaders.UserAgent.Add(userAgent);
121+
}
122+
123+
118124
logger.Verbose($"GET {uri}");
119125
using (var response = await httpClient.SendAsync(request, cancellationToken))
120126
{

CredentialProvider.Microsoft/CredentialProviders/Vsts/VstsSessionTokenClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public async Task<string> CreateSessionTokenAsync(DateTime validTo, Cancellation
3838
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
3939
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken);
4040

41+
foreach (var userAgent in Program.UserAgent)
42+
{
43+
httpClient.DefaultRequestHeaders.UserAgent.Add(userAgent);
44+
}
45+
4146
var content = new StringContent(
4247
JsonConvert.SerializeObject(
4348
new VstsSessionToken()

CredentialProvider.Microsoft/Program.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.IO;
8+
using System.Net.Http.Headers;
89
using System.Reflection;
910
using System.Threading;
1011
using System.Threading.Tasks;
@@ -22,6 +23,35 @@ namespace NuGetCredentialProvider
2223
{
2324
public static class Program
2425
{
26+
internal static string Name => name.Value;
27+
internal static string Version => version.Value;
28+
29+
internal static IList<ProductInfoHeaderValue> UserAgent
30+
{
31+
get
32+
{
33+
return new List<ProductInfoHeaderValue>()
34+
{
35+
new ProductInfoHeaderValue(Name, Version),
36+
#if NETFRAMEWORK
37+
new ProductInfoHeaderValue("(netfx)"),
38+
#else
39+
new ProductInfoHeaderValue("(netcore)"),
40+
#endif
41+
};
42+
}
43+
}
44+
45+
private static Lazy<string> name = new Lazy<string>(() =>
46+
{
47+
return typeof(Program).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyProductAttribute>()?.Product ?? "CredentialProvider.Microsoft";
48+
});
49+
50+
private static Lazy<string> version = new Lazy<string>(() =>
51+
{
52+
return typeof(Program).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "";
53+
});
54+
2555
public static async Task<int> Main(string[] args)
2656
{
2757
CancellationTokenSource tokenSource = new CancellationTokenSource();
@@ -57,13 +87,12 @@ public static async Task<int> Main(string[] args)
5787
{ MessageMethod.SetCredentials, new SetCredentialsRequestHandler(multiLogger) },
5888
};
5989

60-
var version = typeof(Program).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
61-
multiLogger.Verbose(string.Format(Resources.CommandLineArgs, version.InformationalVersion, Environment.CommandLine));
90+
multiLogger.Verbose(string.Format(Resources.CommandLineArgs, Program.Version, Environment.CommandLine));
6291

6392
// Help
6493
if (parsedArgs.Help)
6594
{
66-
Console.WriteLine(string.Format(Resources.CommandLineArgs, version.InformationalVersion, Environment.CommandLine));
95+
Console.WriteLine(string.Format(Resources.CommandLineArgs, Program.Version, Environment.CommandLine));
6796
Console.WriteLine(ArgUsage.GenerateUsageFromTemplate<CredentialProviderArgs>());
6897
Console.WriteLine(
6998
string.Format(

0 commit comments

Comments
 (0)