Skip to content

Commit 95e30f0

Browse files
committed
1 parent 79a6db3 commit 95e30f0

6 files changed

Lines changed: 25 additions & 11 deletions

File tree

CompanionAppService/CompanionAppService.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using EddiCompanionAppService.Exceptions;
22
using JetBrains.Annotations;
3+
using Microsoft.Extensions.Configuration;
34
using Newtonsoft.Json.Linq;
45
using System;
56
using System.Collections.Generic;
@@ -114,8 +115,10 @@ private CompanionAppService ()
114115
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd( $"{Constants.EDDI_NAME}/{Constants.EDDI_VERSION}" );
115116
httpClient.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue( "application/json" ) );
116117

117-
clientID = ClientId.ID;
118-
if (clientID == null)
118+
var secrets = new ConfigurationBuilder().AddUserSecrets<CompanionAppService>().Build();
119+
clientID = secrets[ "CompanionAppService:ClientId" ]; // We don't need the Client Secret for PKCE authentication
120+
121+
if ( clientID == null)
119122
{
120123
CurrentState = State.NoClientIDConfigured;
121124
return;
@@ -127,7 +130,7 @@ private CompanionAppService ()
127130
}
128131

129132
// Our access token may have expired. Use our refresh token to obtain a new access token.
130-
RefreshTokenAsync().SafeFireAndForget( ex =>
133+
RefreshTokenAsync().SafeFireAndForget( _ =>
131134
{
132135
if ( Credentials.refreshToken != null )
133136
{
@@ -136,7 +139,6 @@ private CompanionAppService ()
136139

137140
CurrentState = State.LoggedOut;
138141
} );
139-
return;
140142
}
141143

142144
/// <summary>Initialize a custom URL responder for OAuth callbacks. This responder uses DDE and should only be called if the UI dispatcher is available.</summary>

CompanionAppService/EddiCompanionAppService.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<PropertyGroup>
33
<OutputType>Library</OutputType>
44
<UseWPF>true</UseWPF>
5+
<UserSecretsId>f4a50135-32d4-48e3-9c98-bdd23c70368c</UserSecretsId>
56
</PropertyGroup>
67
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
78
<OutputPath>..\bin\Debug\</OutputPath>
@@ -15,6 +16,7 @@
1516
<ItemGroup>
1617
<PackageReference Include="JetBrains.Annotations" />
1718
<PackageReference Include="Microsoft.CSharp" />
19+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" />
1820
<PackageReference Include="Newtonsoft.Json" />
1921
</ItemGroup>
2022
<ItemGroup>

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<PackageVersion Include="JetBrains.Annotations" Version="2025.2.4" />
1212
<PackageVersion Include="MathNet.Numerics" Version="5.0.0" />
1313
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
14+
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
1415
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
1516
<PackageVersion Include="Microsoft.NETCore.Platforms" Version="7.0.4" />
1617
<PackageVersion Include="MSTest.TestAdapter" Version="4.1.0" />

Tests/OAuthClientIDTests.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1+
using EddiCompanionAppService;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
24

35
namespace Tests
46
{
@@ -8,7 +10,8 @@ public class OAuthClientIDTests
810
[TestMethod]
911
public void TestClientIDNotNull()
1012
{
11-
var clientID = EddiCompanionAppService.ClientId.ID;
13+
var secrets = new ConfigurationBuilder().AddUserSecrets<CompanionAppService>().Build();
14+
var clientID = secrets[ "CompanionAppService:ClientId" ];
1215
Assert.IsInstanceOfType( clientID, typeof(string));
1316
Assert.IsNotNull( clientID );
1417
}

Utilities/TelemetryService/Telemetry.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Rollbar;
1+
using Microsoft.Extensions.Configuration;
2+
using Rollbar;
23
using Rollbar.DTOs;
34
using System;
45
using System.Collections.Generic;
@@ -50,13 +51,16 @@ public static void Start ( string uniqueId, System.Version VoiceAttackVersion )
5051
{
5152
try
5253
{
53-
if ( string.IsNullOrEmpty( TelemetryTokens.rollbarToken ) )
54+
var secrets = new ConfigurationBuilder().AddUserSecrets<Telemetry>().Build();
55+
var rollbarToken = secrets[ "Telemetry:RollbarToken" ];
56+
57+
if ( string.IsNullOrEmpty( rollbarToken ) )
5458
{
5559
Logging.Warn("Telemetry is not configured for this client.");
5660
return;
5761
}
5862

59-
var config = new RollbarInfrastructureConfig( TelemetryTokens.rollbarToken, Constants.EDDI_VERSION.ToString() );
63+
var config = new RollbarInfrastructureConfig( rollbarToken, Constants.EDDI_VERSION.ToString() );
6064

6165
// Configure telemetry
6266
config.RollbarTelemetryOptions.Reconfigure( new RollbarTelemetryOptions( true, 250 ) );
@@ -70,7 +74,7 @@ public static void Start ( string uniqueId, System.Version VoiceAttackVersion )
7074
} );
7175

7276
// Configure Logger Options
73-
var loggerOptions = new RollbarLoggerConfig( TelemetryTokens.rollbarToken, Constants.EDDI_VERSION.ToString() );
77+
var loggerOptions = new RollbarLoggerConfig( rollbarToken, Constants.EDDI_VERSION.ToString() );
7478
loggerOptions.RollbarDataSecurityOptions.Reconfigure( new RollbarDataSecurityOptions(
7579
PersonDataCollectionPolicies.None,
7680
IpAddressCollectionPolicy.CollectAnonymized,

Utilities/Utilities.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Library</OutputType>
44
<UseWPF>true</UseWPF>
55
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
6+
<UserSecretsId>bbc0edf6-4284-46b2-9993-f59e2097c3b1</UserSecretsId>
67
</PropertyGroup>
78
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
89
<OutputPath>..\bin\Debug\</OutputPath>
@@ -14,6 +15,7 @@
1415
<PackageReference Include="JetBrains.Annotations" />
1516
<PackageReference Include="MathNet.Numerics" />
1617
<PackageReference Include="Microsoft.CSharp" />
18+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" />
1719
<PackageReference Include="Newtonsoft.Json" />
1820
<PackageReference Include="Rollbar" />
1921
<PackageReference Include="System.Collections" />

0 commit comments

Comments
 (0)