Move logs into FirebaseDB
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
using FirebaseAdmin;
|
||||
using Google.Apis.Auth.OAuth2;
|
||||
using Google.Cloud.Firestore;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
@@ -8,10 +11,11 @@ using WebAPI;
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
var connectionString = builder.Configuration.GetConnectionString("SQLDatabase");
|
||||
builder.Services.AddDbContext<AppDbContext>(x => {
|
||||
builder.Services.AddDbContext<AppDbContext>(x =>
|
||||
{
|
||||
x.UseSqlServer(connectionString);
|
||||
x.EnableSensitiveDataLogging();
|
||||
});
|
||||
});
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
@@ -54,15 +58,28 @@ builder.Services.AddAuthentication();
|
||||
builder.Services.AddSingleton(typeof(GoogleSheetsHelper));
|
||||
builder.Services.AddSingleton(typeof(GoogleDriveHelper));
|
||||
|
||||
var fileName = "diunabi-admin-firebase.json";
|
||||
#if DEBUG
|
||||
fileName = "diunabi-admin-firebase-Development.json";
|
||||
#endif
|
||||
var credentialPath = Path.Combine(Directory.GetCurrentDirectory(), fileName);
|
||||
System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credentialPath);
|
||||
FirebaseAdmin.FirebaseApp.Create(new AppOptions()
|
||||
{
|
||||
Credential = GoogleCredential.GetApplicationDefault()
|
||||
});
|
||||
builder.Services.AddSingleton(FirestoreDb.Create("diunabi-admin"));
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
var token = context.Request.Headers.Authorization.ToString();
|
||||
if (token.Length > 0
|
||||
if (token.Length > 0
|
||||
&& !context.Request.Path.ToString().Contains("getForPowerBI")
|
||||
&& !context.Request.Path.ToString().Contains("DataInbox/Add")) {
|
||||
&& !context.Request.Path.ToString().Contains("DataInbox/Add"))
|
||||
{
|
||||
var handler = new JwtSecurityTokenHandler();
|
||||
var data = handler.ReadJwtToken(token.Split(' ')[1]);
|
||||
context.Request.Headers.Append("UserId", new Microsoft.Extensions.Primitives.StringValues(data.Subject));
|
||||
|
||||
Reference in New Issue
Block a user