Inizio progetto integrato con FirebaseAdmin

This commit is contained in:
Samuele Locatelli
2024-04-16 18:30:34 +02:00
parent 190c01a82d
commit ff01671939
9 changed files with 203 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Eqn.Sender", "Eqn.Sender\Eqn.Sender.csproj", "{848023DA-74A9-45AA-A974-925FCF47174F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{848023DA-74A9-45AA-A974-925FCF47174F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{848023DA-74A9-45AA-A974-925FCF47174F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{848023DA-74A9-45AA-A974-925FCF47174F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{848023DA-74A9-45AA-A974-925FCF47174F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7392D053-FA21-4398-BB2E-5174B60860D3}
EndGlobalSection
EndGlobal
@@ -0,0 +1,54 @@
using FirebaseAdmin;
using FirebaseAdmin.Auth;
using Google.Apis.Auth.OAuth2;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace Eqn.Sender.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class FBMSendController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<FBMSendController> _logger;
private FirebaseApp fbApp;
public FBMSendController(ILogger<FBMSendController> logger)
{
_logger = logger;
string filePath = Path.Combine(Directory.GetCurrentDirectory(), "firebase.json");
fbApp = FirebaseApp.Create(new AppOptions()
{
//Credential = GoogleCredential.GetApplicationDefault(),
Credential = GoogleCredential.FromFile(filePath),
ProjectId = "hybrid-bastion-406",
});
_logger.LogInformation(fbApp.Name);
// Retrieve services by passing the fbApp variable...
var defaultAuth = FirebaseAuth.GetAuth(fbApp);
// ... or use the equivalent shorthand notation
defaultAuth = FirebaseAuth.DefaultInstance;
}
[HttpGet(Name = "GetStatus")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}
+15
View File
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>352f62a7-3b7d-40cd-ab21-b55a5fefae44</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FirebaseAdmin" Version="2.4.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
</Project>
+25
View File
@@ -0,0 +1,25 @@
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
+41
View File
@@ -0,0 +1,41 @@
{
"profiles": {
"Eqn.Sender": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7033;http://localhost:5199"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WSL": {
"commandName": "WSL2",
"launchBrowser": true,
"launchUrl": "https://localhost:7033/swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "https://localhost:7033;http://localhost:5199"
},
"distributionName": ""
}
},
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:14501",
"sslPort": 44353
}
}
}
+13
View File
@@ -0,0 +1,13 @@
namespace Eqn.Sender
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
+13
View File
@@ -0,0 +1,13 @@
{
"type": "service_account",
"project_id": "hybrid-bastion-406",
"private_key_id": "beac71a21266e3f50920024e5a93e01152d404d0",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDbOcvoBcKNN70a\n/SKsR86hhI8XfSTqE2C9oiiujz7qoJx3aPIse6DglgkXX6d86aAOZIGJeSqtDAa0\nOknhtG9JDSOwIMCqbC9JhFwSg6Mqm1ponVN0Hlq2Hxh8g0n+Cjnx/tI+7Mrrl1lH\nIqt+JPNKJ4fetFnncKeKFtii0kPQAmHFsN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twKBgBvF\nQO63PuWD0cMgNyt6Nf1j/FFK/lyKpmNxEzT3HBtrvIxHw63w3t7qa677H/wS6qoj\nY0qqU4BfWk/nP9MA5i2RFQRT0XOE/xxkwWf0mfFEpy/rtPeV1QijEzzu6CnFMbB6\ngC/1v36MkE2gDo7Ur1yjYFK8ZsdXKhPwrb6cpP2NAoGBANhMNPfedto1jyJyTEl4\nBGb78YDZoRFiCMn/sJOBUFfLZag4Us9TlxU15FsntLRj4OGuTLPUSor+4NTvI8VH\nbStF6F5q5zu0fLkt6pLr7bHJIagn4//jjB3nzVu0AW5nH4Zi1dfAg0Ezp4osaktd\nTb6oAk09oXxE+F0urW95UKFU\n-----END PRIVATE KEY-----\n",
"client_email": "firebase-adminsdk-o3m3l@hybrid-bastion-406.iam.gserviceaccount.com",
"client_id": "104088314886127994232",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-o3m3l%40hybrid-bastion-406.iam.gserviceaccount.com",
"universe_domain": "googleapis.com"
}