Skip to content

Commit

Permalink
updating google auth setup for deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
efonsecab committed Apr 12, 2024
1 parent 34e1ad5 commit 9c63810
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 97 deletions.
8 changes: 0 additions & 8 deletions azure.yaml

This file was deleted.

69 changes: 0 additions & 69 deletions next-steps.md

This file was deleted.

41 changes: 28 additions & 13 deletions src/FairPlayCombinedSln/FairPlayCombinedSln.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@

var builder = DistributedApplication.CreateBuilder(args);
builder.Configuration.AddUserSecrets<Program>();
string googleAuthClientInfo = string.Empty;
try
{
var googleAuthClientSecretsFilePath = builder.Configuration["GoogleAuthClientSecretsFilePath"] ??
throw new InvalidOperationException("'GoogleAuthClientSecretsFilePath' not found");
googleAuthClientInfo = System.IO.File.ReadAllText(googleAuthClientSecretsFilePath);
}
catch (Exception)
{
googleAuthClientInfo = builder.Configuration["GoogleAuthClientSecretsFileInfo"] ??
throw new InvalidOperationException("'GoogleAuthClientSecretsFileInfo' not found");
}

var googleAuthClientId = builder.Configuration["GoogleAuthClientId"] ??
throw new InvalidOperationException("'GoogleAuthClientId' not found");

var googleAuthProjectId = builder.Configuration["GoogleAuthProjectId"] ??
throw new InvalidOperationException("'GoogleAuthProjectId' not found");

var googleAuthUri = builder.Configuration["GoogleAuthUri"] ??
throw new InvalidOperationException("'GoogleAuthUri' not found");

var googleAuthTokenUri = builder.Configuration["GoogleAuthTokenUri"] ??
throw new InvalidOperationException("'GoogleAuthTokenUri' not found");

var googleAuthProviderCertUri = builder.Configuration["GoogleAuthProviderCertUri"] ??
throw new InvalidOperationException("'GoogleAuthProviderCertUri' not found");

var googleAuthClientSecret = builder.Configuration["GoogleAuthClientSecret"] ??
throw new InvalidOperationException("'GoogleAuthClientSecret' not found");

var googleAuthRedirectUri = builder.Configuration["GoogleAuthRedirectUri"] ??
throw new InvalidOperationException("'GoogleAuthRedirectUri' not found");

IResourceBuilder<IResourceWithConnectionString> sqlResourceWithConnectionString =
builder.AddConnectionString("FairPlayCombinedDb");
Expand All @@ -35,7 +44,13 @@
builder.AddProject<Projects.FairPlayTube>(nameof(Projects.FairPlayTube).ToLower())
.WithEnvironment(callback =>
{
callback.EnvironmentVariables.Add("GoogleAuthClientInfo", googleAuthClientInfo);
callback.EnvironmentVariables.Add("GoogleAuthClientId", googleAuthClientId);
callback.EnvironmentVariables.Add("GoogleAuthProjectId", googleAuthProjectId);
callback.EnvironmentVariables.Add("GoogleAuthUri", googleAuthUri);
callback.EnvironmentVariables.Add("GoogleAuthTokenUri", googleAuthTokenUri);
callback.EnvironmentVariables.Add("GoogleAuthProviderCertUri", googleAuthProviderCertUri);
callback.EnvironmentVariables.Add("GoogleAuthClientSecret", googleAuthClientSecret);
callback.EnvironmentVariables.Add("GoogleAuthRedirectUri", googleAuthRedirectUri);
})
.WithReference(sqlResourceWithConnectionString);
builder.AddProject<Projects.FairPlayTube_VideoIndexing>("fairplaytubevideoindexing")
Expand Down
38 changes: 34 additions & 4 deletions src/FairPlayCombinedSln/FairPlayTube/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,40 @@
builder.Services.AddScoped<IdentityRedirectManager>();
builder.Services.AddScoped<AuthenticationStateProvider, IdentityRevalidatingAuthenticationStateProvider>();

var googleAuthClientInfoJson = Environment.GetEnvironmentVariable("GoogleAuthClientInfo") ??
throw new InvalidOperationException("'GoogleAuthClientInfo' not found");
GoogleAuthClientSecretInfo googleAuthClientSecretInfo =
System.Text.Json.JsonSerializer.Deserialize<GoogleAuthClientSecretInfo>(googleAuthClientInfoJson)!;
var googleAuthClientId = builder.Configuration["GoogleAuthClientId"] ??
throw new InvalidOperationException("'GoogleAuthClientId' not found");

var googleAuthProjectId = builder.Configuration["GoogleAuthProjectId"] ??
throw new InvalidOperationException("'GoogleAuthProjectId' not found");

var googleAuthUri = builder.Configuration["GoogleAuthUri"] ??
throw new InvalidOperationException("'GoogleAuthUri' not found");

var googleAuthTokenUri = builder.Configuration["GoogleAuthTokenUri"] ??
throw new InvalidOperationException("'GoogleAuthTokenUri' not found");

var googleAuthProviderCertUri = builder.Configuration["GoogleAuthProviderCertUri"] ??
throw new InvalidOperationException("'GoogleAuthProviderCertUri' not found");

var googleAuthClientSecret = builder.Configuration["GoogleAuthClientSecret"] ??
throw new InvalidOperationException("'GoogleAuthClientSecret' not found");

var googleAuthRedirectUri = builder.Configuration["GoogleAuthRedirectUri"] ??
throw new InvalidOperationException("'GoogleAuthRedirectUri' not found");

GoogleAuthClientSecretInfo googleAuthClientSecretInfo = new()
{
installed = new Installed()
{
auth_provider_x509_cert_url = googleAuthProviderCertUri,
auth_uri = googleAuthUri,
client_id = googleAuthClientId,
client_secret = googleAuthClientSecret,
project_id = googleAuthProjectId,
redirect_uris = [googleAuthRedirectUri],
token_uri = googleAuthTokenUri
}
};
builder.Services.AddSingleton<YouTubeClientServiceConfiguration>(new YouTubeClientServiceConfiguration()
{
GoogleAuthClientSecretInfo = googleAuthClientSecretInfo
Expand Down
6 changes: 3 additions & 3 deletions src/FairPlayCombinedSln/next-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To troubleshoot any issues, see [troubleshooting](#troubleshooting).

### Infrastructure configuration

To describe the infrastructure and application and `azure.yaml` was added with the following directory structure:
To describe the infrastructure and application, an `azure.yaml` was added with the following directory structure:

```yaml
- azure.yaml # azd project configuration
Expand All @@ -52,7 +52,7 @@ In addition, for each project resource referenced by your app host, a `container

## Billing

Visit the *Cost Management + Billing* page in Azure Portal to track current spend. For more information about how you're billed, and how you can monitor the costs incurred in your Azure subscriptions, visit [billing overview](https://learn.microsoft.com/en-us/azure/developer/intro/azure-developer-billing).
Visit the *Cost Management + Billing* page in Azure Portal to track current spend. For more information about how you're billed, and how you can monitor the costs incurred in your Azure subscriptions, visit [billing overview](https://learn.microsoft.com/azure/developer/intro/azure-developer-billing).

## Troubleshooting

Expand All @@ -66,4 +66,4 @@ A: Your service may have failed to start or misconfigured. To investigate furthe
4. Observe the log output to identify any errors.
5. If logs are written to disk, examine the local logs or debug the application by using the *Console* to connect to a shell within the running container.

For additional information about setting up your `azd` project, visit our official [docs](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/make-azd-compatible?pivots=azd-convert).
For additional information about setting up your `azd` project, visit our official [docs](https://learn.microsoft.com/azure/developer/azure-developer-cli/make-azd-compatible?pivots=azd-convert).

0 comments on commit 9c63810

Please sign in to comment.