Compare commits
1 Commits
feature/fi
...
feature/up
| Author | SHA1 | Date | |
|---|---|---|---|
| 04faddbb9a |
13
src/GameIdeas/.idea/.idea.GameIdeas/.idea/.gitignore
generated
vendored
13
src/GameIdeas/.idea/.idea.GameIdeas/.idea/.gitignore
generated
vendored
@@ -1,13 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Rider ignored files
|
|
||||||
/projectSettingsUpdater.xml
|
|
||||||
/.idea.GameIdeas.iml
|
|
||||||
/modules.xml
|
|
||||||
/contentModel.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="UserContentModel">
|
|
||||||
<attachedFolders />
|
|
||||||
<explicitIncludes />
|
|
||||||
<explicitExcludes />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
51
src/GameIdeas/.vscode/launch.json
vendored
51
src/GameIdeas/.vscode/launch.json
vendored
@@ -1,51 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"dotNetConfig": {},
|
|
||||||
"name": "Debug Blazor Application",
|
|
||||||
"type": "blazorwasm",
|
|
||||||
"request": "launch",
|
|
||||||
"browser": "chrome",
|
|
||||||
"cwd": "${workspaceFolder}/Client/GameIdeas.BlazorApp",
|
|
||||||
"url": "http://localhost:5172",
|
|
||||||
"presentation": {
|
|
||||||
"group": "group 2: Single",
|
|
||||||
"order": 2
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Debug API Server",
|
|
||||||
"type": "coreclr",
|
|
||||||
"request": "launch",
|
|
||||||
"preLaunchTask": "Build API Server",
|
|
||||||
"program": "${workspaceFolder}/Server/GameIdeas.WebAPI/bin/Debug/net9.0/GameIdeas.WebAPI.dll",
|
|
||||||
"cwd": "${workspaceFolder}/Server/GameIdeas.WebAPI",
|
|
||||||
"stopAtEntry": false,
|
|
||||||
"env": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
},
|
|
||||||
"presentation": {
|
|
||||||
"group": "group 2: Single",
|
|
||||||
"order": 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"compounds": [
|
|
||||||
{
|
|
||||||
"name": "Launch GameIdeas",
|
|
||||||
"configurations": [
|
|
||||||
"Debug API Server",
|
|
||||||
"Debug Blazor Application"
|
|
||||||
],
|
|
||||||
"stopAll": true,
|
|
||||||
"presentation": {
|
|
||||||
"group": "group 1: Group",
|
|
||||||
"order": 1
|
|
||||||
},
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
27
src/GameIdeas/.vscode/tasks.json
vendored
27
src/GameIdeas/.vscode/tasks.json
vendored
@@ -1,27 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "2.0.0",
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"type": "shell",
|
|
||||||
"command": "dotnet build",
|
|
||||||
"label": "Build API Server",
|
|
||||||
"isBackground": true,
|
|
||||||
"options": {
|
|
||||||
"cwd": "${workspaceFolder}"
|
|
||||||
},
|
|
||||||
"problemMatcher":{
|
|
||||||
"pattern": {
|
|
||||||
"regexp": "^.*$",
|
|
||||||
"file": 0,
|
|
||||||
"location": 1,
|
|
||||||
"message": 2
|
|
||||||
},
|
|
||||||
"background": {
|
|
||||||
"activeOnStart": true,
|
|
||||||
"beginsPattern": ".*",
|
|
||||||
"endsPattern": "Compiled|Failed|compiled|failed|ready"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
9
src/GameIdeas/GameIdeas.Shared/Enum/BucketType.cs
Normal file
9
src/GameIdeas/GameIdeas.Shared/Enum/BucketType.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace GameIdeas.Shared.Enum;
|
||||||
|
|
||||||
|
public enum BucketType
|
||||||
|
{
|
||||||
|
GameIcon,
|
||||||
|
GameCover,
|
||||||
|
GameMedia,
|
||||||
|
UserIcon
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace GameIdeas.Shared.Exceptions;
|
||||||
|
|
||||||
|
public class BucketTypeMissingException(string message) : Exception(message);
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
namespace GameIdeas.Shared.Exceptions;
|
namespace GameIdeas.Shared.Exceptions;
|
||||||
|
|
||||||
public class EnvironmentVariableMissingException(string message) : Exception(message);
|
public class EnvironmentVariableMissingException(string valueName) :
|
||||||
|
Exception($"Missing environment variable with key: {valueName}");
|
||||||
|
|||||||
19
src/GameIdeas/GameIdeas.Shared/Extensions/BucketExtension.cs
Normal file
19
src/GameIdeas/GameIdeas.Shared/Extensions/BucketExtension.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using GameIdeas.Shared.Enum;
|
||||||
|
using GameIdeas.Shared.Exceptions;
|
||||||
|
|
||||||
|
namespace GameIdeas.Shared.Extensions;
|
||||||
|
|
||||||
|
public static class BucketExtension
|
||||||
|
{
|
||||||
|
public static string GetBucket(this BucketType bucketType)
|
||||||
|
{
|
||||||
|
return bucketType switch
|
||||||
|
{
|
||||||
|
BucketType.GameIcon => "icons",
|
||||||
|
BucketType.GameCover => "covers",
|
||||||
|
BucketType.GameMedia => "medias",
|
||||||
|
BucketType.UserIcon => "users",
|
||||||
|
_ => throw new BucketTypeMissingException($"Bucket type {bucketType} not exist")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
namespace GameIdeas.Shared.Options;
|
|
||||||
|
|
||||||
public class GameIdeasOptions
|
|
||||||
{
|
|
||||||
public string DbHost { get; set; } = string.Empty;
|
|
||||||
public string DbUsername { get; set; } = string.Empty;
|
|
||||||
public string DbPassword { get; set; } = string.Empty;
|
|
||||||
public string DbDatabase { get; set; } = string.Empty;
|
|
||||||
public string JwtKey { get; set; } = string.Empty;
|
|
||||||
public string JwtIssuer { get; set; } = string.Empty;
|
|
||||||
public string JwtAudience { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using GameIdeas.Shared.Enum;
|
||||||
|
using GameIdeas.WebAPI.Services.Files;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace GameIdeas.WebAPI.Controllers;
|
||||||
|
|
||||||
|
public class FileController(
|
||||||
|
IFileService fileService,
|
||||||
|
ILoggerFactory loggerFactory) : Controller
|
||||||
|
{
|
||||||
|
private readonly ILogger<FileController> Logger = loggerFactory.CreateLogger<FileController>();
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[RequestSizeLimit(100_000_000_000)] // 100 GB
|
||||||
|
public async Task<IActionResult> UploadFile([FromForm] IFormFile file, [FromQuery] BucketType type)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Ok(await fileService.UploadFile(file, type));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.LogError(e, "Failed uploading files");
|
||||||
|
return StatusCode(500, e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using GameIdeas.Shared.Constants;
|
using GameIdeas.Shared.Constants;
|
||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
using GameIdeas.Shared.Exceptions;
|
using GameIdeas.WebAPI.Exceptions;
|
||||||
using GameIdeas.WebAPI.Services.Users;
|
using GameIdeas.WebAPI.Services.Users;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
namespace GameIdeas.Shared.Exceptions;
|
namespace GameIdeas.WebAPI.Exceptions;
|
||||||
|
|
||||||
public class UserInvalidException(string message) : Exception(message);
|
public class UserInvalidException(string message) : Exception(message);
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
namespace GameIdeas.Shared.Exceptions;
|
namespace GameIdeas.WebAPI.Exceptions;
|
||||||
|
|
||||||
public class UserUnauthorizedException(string message) : Exception(message);
|
public class UserUnauthorizedException(string message) : Exception(message);
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
using GameIdeas.Shared.Exceptions;
|
|
||||||
using GameIdeas.Shared.Options;
|
|
||||||
|
|
||||||
namespace GameIdeas.WebAPI.Extensions;
|
|
||||||
|
|
||||||
public static class ServiceCollectionExtension
|
|
||||||
{
|
|
||||||
public static IServiceCollection AddGameIdeasOptions(this IServiceCollection services)
|
|
||||||
{
|
|
||||||
#if DEBUG
|
|
||||||
var dictionary = LoadEnvironmentVariable("../../../../.env");
|
|
||||||
#else
|
|
||||||
var dictionary = LoadEnvironmentVariable("../.env");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
services.Configure<GameIdeasOptions>(options =>
|
|
||||||
{
|
|
||||||
options.DbHost = GetEnvVar("DB_HOST", dictionary);
|
|
||||||
options.DbUsername = GetEnvVar("DB_USERNAME", dictionary);
|
|
||||||
options.DbPassword = GetEnvVar("DB_PASSWORD", dictionary);
|
|
||||||
options.DbDatabase = GetEnvVar("DB_DATABASE", dictionary);
|
|
||||||
options.JwtKey = GetEnvVar("JWT_KEY", dictionary);
|
|
||||||
options.JwtIssuer = GetEnvVar("JWT_ISSUER", dictionary);
|
|
||||||
options.JwtAudience = GetEnvVar("JWT_AUDIENCE", dictionary);
|
|
||||||
});
|
|
||||||
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetEnvVar(string name, Dictionary<string, string> dictionary)
|
|
||||||
{
|
|
||||||
return Environment.GetEnvironmentVariable(name)
|
|
||||||
?? dictionary.GetValueOrDefault(name)
|
|
||||||
?? throw new EnvironmentVariableMissingException($"Missing environment variable with key: {name}");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Dictionary<string, string> LoadEnvironmentVariable(string filePath)
|
|
||||||
{
|
|
||||||
if (!File.Exists(filePath))
|
|
||||||
return [];
|
|
||||||
|
|
||||||
return File.ReadAllLines(filePath)
|
|
||||||
.Select(line => line.Split('=', StringSplitOptions.RemoveEmptyEntries))
|
|
||||||
.Where(parts => parts.Length == 2)
|
|
||||||
.ToDictionary(parts => parts[0], parts => parts[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Minio" Version="6.0.4" />
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -10,18 +10,37 @@ using Microsoft.AspNetCore.Identity;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using GameIdeas.WebAPI.Extensions;
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
var services = builder.Services;
|
var services = builder.Services;
|
||||||
|
|
||||||
services.AddGameIdeasOptions();
|
#if DEBUG
|
||||||
services.AddDbContext<GameIdeasContext>(ContextOptions);
|
LoadEnvironmentVariable("../../../../.env");
|
||||||
|
#else
|
||||||
|
LoadEnvironmentVariable("../.env");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Action<DbContextOptionsBuilder> dbContextOptions = options =>
|
||||||
|
{
|
||||||
|
options.UseNpgsql(
|
||||||
|
GetConnectionString(),
|
||||||
|
npgOption =>
|
||||||
|
{
|
||||||
|
npgOption.CommandTimeout(60);
|
||||||
|
npgOption.MigrationsAssembly("GameIdeas.WebAPI");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add services to the container.
|
||||||
|
services.AddDbContext<GameIdeasContext>(dbContextOptions);
|
||||||
|
|
||||||
services.AddIdentity<User, IdentityRole>()
|
services.AddIdentity<User, IdentityRole>()
|
||||||
.AddEntityFrameworkStores<GameIdeasContext>()
|
.AddEntityFrameworkStores<GameIdeasContext>()
|
||||||
.AddDefaultTokenProviders();
|
.AddDefaultTokenProviders();
|
||||||
|
|
||||||
|
var jwtKey = Environment.GetEnvironmentVariable("JWT_KEY")
|
||||||
|
?? throw new ArgumentNullException(message: "Invalid key for JWT token", null);
|
||||||
|
|
||||||
services.AddAuthentication(options =>
|
services.AddAuthentication(options =>
|
||||||
{
|
{
|
||||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
@@ -67,6 +86,7 @@ services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
|||||||
|
|
||||||
services.AddControllers();
|
services.AddControllers();
|
||||||
|
|
||||||
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||||
services.AddOpenApi();
|
services.AddOpenApi();
|
||||||
|
|
||||||
services.AddCors(option => option.AddDefaultPolicy(policy =>
|
services.AddCors(option => option.AddDefaultPolicy(policy =>
|
||||||
@@ -98,16 +118,6 @@ app.UseAuthorization();
|
|||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
return;
|
|
||||||
|
|
||||||
void ContextOptions(DbContextOptionsBuilder options)
|
|
||||||
{
|
|
||||||
options.UseNpgsql(GetConnectionString(), npgOption =>
|
|
||||||
{
|
|
||||||
npgOption.CommandTimeout(60);
|
|
||||||
npgOption.MigrationsAssembly("GameIdeas.WebAPI");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async Task LoadTranslations()
|
async Task LoadTranslations()
|
||||||
{
|
{
|
||||||
@@ -124,6 +134,7 @@ async Task LoadTranslations()
|
|||||||
|
|
||||||
app.Services.GetRequiredService<TranslationService>().Initialize(dictionary);
|
app.Services.GetRequiredService<TranslationService>().Initialize(dictionary);
|
||||||
ResourcesKey.Initialize(app.Services.GetRequiredService<Translations>());
|
ResourcesKey.Initialize(app.Services.GetRequiredService<Translations>());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string GetConnectionString()
|
string GetConnectionString()
|
||||||
@@ -135,3 +146,21 @@ string GetConnectionString()
|
|||||||
|
|
||||||
return $"Host={host};Username={login};Password={pass};Database={database}";
|
return $"Host={host};Username={login};Password={pass};Database={database}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void LoadEnvironmentVariable(string filePath)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filePath))
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (var line in File.ReadAllLines(filePath))
|
||||||
|
{
|
||||||
|
var parts = line.Split(
|
||||||
|
'=',
|
||||||
|
StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
if (parts.Length != 2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Environment.SetEnvironmentVariable(parts[0], parts[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
using Minio;
|
||||||
|
using GameIdeas.Shared.Exceptions;
|
||||||
|
using Minio.DataModel.Args;
|
||||||
|
using GameIdeas.Shared.Enum;
|
||||||
|
using GameIdeas.Shared.Extensions;
|
||||||
|
|
||||||
|
namespace GameIdeas.WebAPI.Services.Files;
|
||||||
|
|
||||||
|
public class FileService : IFileService
|
||||||
|
{
|
||||||
|
private readonly IMinioClient MinioClient;
|
||||||
|
|
||||||
|
public FileService()
|
||||||
|
{
|
||||||
|
var minioEndpoint = Environment.GetEnvironmentVariable("MINIO_ENDPOINT")
|
||||||
|
?? throw new EnvironmentVariableMissingException("MINIO_ENDPOINT");
|
||||||
|
|
||||||
|
var minioAccessKey = Environment.GetEnvironmentVariable("MINIO_ACCESS_KEY")
|
||||||
|
?? throw new EnvironmentVariableMissingException("MINIO_ACCESS_KEY");
|
||||||
|
|
||||||
|
var minioSecretKey= Environment.GetEnvironmentVariable("MINIO_SECRET_KEY")
|
||||||
|
?? throw new EnvironmentVariableMissingException("MINIO_SECRET_KEY");
|
||||||
|
|
||||||
|
MinioClient = new MinioClient()
|
||||||
|
.WithEndpoint(minioEndpoint)
|
||||||
|
.WithCredentials(minioAccessKey, minioSecretKey)
|
||||||
|
.Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> UploadFile(IFormFile file, BucketType bucketType)
|
||||||
|
{
|
||||||
|
var fileName = Path.GetFileName(file.FileName);
|
||||||
|
var bucket = bucketType.GetBucket();
|
||||||
|
|
||||||
|
bool found = await MinioClient.BucketExistsAsync(new BucketExistsArgs().WithBucket(bucket));
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
await MinioClient.MakeBucketAsync(new MakeBucketArgs().WithBucket(bucket));
|
||||||
|
}
|
||||||
|
|
||||||
|
using var stream = file.OpenReadStream();
|
||||||
|
|
||||||
|
var args = new PutObjectArgs()
|
||||||
|
.WithBucket(bucket)
|
||||||
|
.WithObject(fileName)
|
||||||
|
.WithStreamData(stream)
|
||||||
|
.WithObjectSize(file.Length)
|
||||||
|
.WithContentType(file.ContentType);
|
||||||
|
|
||||||
|
await MinioClient.PutObjectAsync(args);
|
||||||
|
|
||||||
|
return $"/{bucket}/{fileName}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using GameIdeas.Shared.Enum;
|
||||||
|
|
||||||
|
namespace GameIdeas.WebAPI.Services.Files;
|
||||||
|
|
||||||
|
public interface IFileService
|
||||||
|
{
|
||||||
|
Task<string> UploadFile(IFormFile file, BucketType bucketType);
|
||||||
|
}
|
||||||
@@ -4,22 +4,19 @@ using GameIdeas.Shared.Constants;
|
|||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
using GameIdeas.Shared.Model;
|
using GameIdeas.Shared.Model;
|
||||||
using GameIdeas.WebAPI.Context;
|
using GameIdeas.WebAPI.Context;
|
||||||
|
using GameIdeas.WebAPI.Exceptions;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using GameIdeas.Shared.Exceptions;
|
|
||||||
using GameIdeas.Shared.Options;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
|
|
||||||
namespace GameIdeas.WebAPI.Services.Users;
|
namespace GameIdeas.WebAPI.Services.Users;
|
||||||
|
|
||||||
public class UserReadService(
|
public class UserReadService(
|
||||||
UserManager<User> userManager,
|
UserManager<User> userManager,
|
||||||
GameIdeasContext context,
|
GameIdeasContext context,
|
||||||
IOptions<GameIdeasOptions> options,
|
|
||||||
IMapper mapper) : IUserReadService
|
IMapper mapper) : IUserReadService
|
||||||
{
|
{
|
||||||
public async Task<IEnumerable<RoleDto>> GetRoles()
|
public async Task<IEnumerable<RoleDto>> GetRoles()
|
||||||
@@ -128,11 +125,14 @@ public class UserReadService(
|
|||||||
authClaims.AddRange((await userManager.GetRolesAsync(user))
|
authClaims.AddRange((await userManager.GetRolesAsync(user))
|
||||||
.Select(r => new Claim(ClaimTypes.Role, r)));
|
.Select(r => new Claim(ClaimTypes.Role, r)));
|
||||||
|
|
||||||
var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(options.Value.JwtKey));
|
var jwtKey = Environment.GetEnvironmentVariable("JWT_KEY")
|
||||||
|
?? throw new ArgumentNullException(message: ResourcesKey.InvalidToken, null);
|
||||||
|
|
||||||
|
var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtKey));
|
||||||
|
|
||||||
var token = new JwtSecurityToken(
|
var token = new JwtSecurityToken(
|
||||||
issuer: options.Value.JwtIssuer,
|
issuer: Environment.GetEnvironmentVariable("JWT_ISSUER"),
|
||||||
audience: options.Value.JwtAudience,
|
audience: Environment.GetEnvironmentVariable("JWT_AUDIENCE"),
|
||||||
expires: DateTime.Now.AddHours(GlobalConstants.JWT_DURATION_HOUR),
|
expires: DateTime.Now.AddHours(GlobalConstants.JWT_DURATION_HOUR),
|
||||||
claims: authClaims,
|
claims: authClaims,
|
||||||
signingCredentials: new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256)
|
signingCredentials: new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using GameIdeas.Resources;
|
using GameIdeas.Resources;
|
||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
using GameIdeas.Shared.Exceptions;
|
|
||||||
using GameIdeas.Shared.Model;
|
using GameIdeas.Shared.Model;
|
||||||
|
using GameIdeas.WebAPI.Exceptions;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
|
||||||
namespace GameIdeas.WebAPI.Services.Users;
|
namespace GameIdeas.WebAPI.Services.Users;
|
||||||
|
|||||||
Reference in New Issue
Block a user