Skip to content

Commit

Permalink
Move Google API key to secret
Browse files Browse the repository at this point in the history
withinfocus committed Mar 11, 2024
1 parent 5a797f8 commit 0b97d64
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -2,10 +2,8 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Net;
using System.Net.Http.Json;

const string GoogleApiKey = "***REMOVED***";
var httpClient = new HttpClient();

var hostBuilder = Host.CreateApplicationBuilder(args);
@@ -64,8 +62,15 @@
return null;
}

var googleApiKey = hostBuilder.Configuration["GoogleApiKey"];
if (string.IsNullOrEmpty(googleApiKey) || googleApiKey == "SECRET")
{
logger.LogError("No Google API key secret provided.");
return null;
}

using HttpResponseMessage tokenResponse = await httpClient.PostAsync(
$"https://securetoken.googleapis.com/v1/token?key={GoogleApiKey}",
$"https://securetoken.googleapis.com/v1/token?key={googleApiKey}",
new FormUrlEncodedContent(new Dictionary<string, string>
{
["grant_type"] = "refresh_token",
3 changes: 2 additions & 1 deletion appsettings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"RefreshToken": "SECRET"
"RefreshToken": "SECRET",
"GoogleApiKey": "SECRET"
}

0 comments on commit 0b97d64

Please sign in to comment.