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

Commit 6b38183

Browse files
committed
Add alternate ApiClientConfiguration file for public users
1 parent ba3a7b7 commit 6b38183

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

src/GitHub.App/Api/ApiClient.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Globalization;
33
using System.Linq;
44
using System.Net;
@@ -17,13 +17,11 @@
1717

1818
namespace GitHub.Api
1919
{
20-
public class ApiClient : IApiClient
20+
public partial class ApiClient : IApiClient
2121
{
2222
static readonly Logger log = LogManager.GetCurrentClassLogger();
2323

2424
const string ProductName = Info.ApplicationInfo.ApplicationDescription;
25-
const string clientId = "";
26-
const string clientSecret = "";
2725

2826
readonly IObservableGitHubClient gitHubClient;
2927
// There are two sets of authorization scopes, old and new:
@@ -34,12 +32,18 @@ public class ApiClient : IApiClient
3432
readonly static Lazy<string> lazyNote = new Lazy<string>(() => ProductName + " on " + GetMachineNameSafe());
3533
readonly static Lazy<string> lazyFingerprint = new Lazy<string>(GetFingerprint);
3634

35+
string ClientId { get; set; }
36+
string ClientSecret { get; set; }
37+
3738
public ApiClient(HostAddress hostAddress, IObservableGitHubClient gitHubClient)
3839
{
40+
Configure();
3941
HostAddress = hostAddress;
4042
this.gitHubClient = gitHubClient;
4143
}
4244

45+
partial void Configure();
46+
4347
public IObservable<Repository> CreateRepository(NewRepository repository, string login, bool isUser)
4448
{
4549
Guard.ArgumentNotEmptyString(login, "login");
@@ -76,14 +80,14 @@ public IObservable<ApplicationAuthorization> GetOrCreateApplicationAuthenticatio
7680

7781
return string.IsNullOrEmpty(authenticationCode)
7882
? authorizationsClient.CreateAndDeleteExistingApplicationAuthorization(
79-
clientId,
80-
clientSecret,
83+
ClientId,
84+
ClientSecret,
8185
newAuthorization,
8286
dispatchedHandler,
8387
true)
8488
: authorizationsClient.CreateAndDeleteExistingApplicationAuthorization(
85-
clientId,
86-
clientSecret,
89+
ClientId,
90+
ClientSecret,
8791
newAuthorization,
8892
dispatchedHandler,
8993
authenticationCode,
@@ -116,7 +120,7 @@ public IObservable<LicenseMetadata> GetLicenses()
116120
return gitHubClient.Miscellaneous.GetAllLicenses();
117121
}
118122

119-
public HostAddress HostAddress { get; private set; }
123+
public HostAddress HostAddress { get; }
120124

121125
public ITwoFactorChallengeHandler TwoFactorChallengeHandler { get; private set; }
122126

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace GitHub.Api
2+
{
3+
public partial class ApiClient : IApiClient
4+
{
5+
const string clientId = "YOUR CLIENT ID HERE";
6+
const string clientSecret = "YOUR CLIENT SECRET HERE";
7+
8+
partial void Configure()
9+
{
10+
ClientId = clientId;
11+
ClientSecret = clientSecret;
12+
}
13+
}
14+
}

src/GitHub.App/GitHub.App.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<RunCodeAnalysis>true</RunCodeAnalysis>
1919
<CodeAnalysisRuleSet>..\..\script\GitHubVS.ruleset</CodeAnalysisRuleSet>
2020
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
21+
<BuildType Condition="Exists('..\..\script\ApiClientConfiguration.cs')">Internal</BuildType>
2122
</PropertyGroup>
2223
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2324
<DebugSymbols>true</DebugSymbols>
@@ -135,6 +136,10 @@
135136
<Compile Include="..\common\SolutionInfo.cs">
136137
<Link>Properties\SolutionInfo.cs</Link>
137138
</Compile>
139+
<Compile Include="..\..\script\ApiClientConfiguration.cs" Condition="$(Buildtype) == 'Internal'">
140+
<Link>Api\ApiClientConfiguration.cs</Link>
141+
</Compile>
142+
<Compile Include="Api\ApiClientConfiguration.cs" Condition="$(Buildtype) != 'Internal'" />
138143
</ItemGroup>
139144
<ItemGroup>
140145
<None Include="AkavacheSqliteLinkerOverride.cs" />

0 commit comments

Comments
 (0)