mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Add JWT_SECRET environment variable to Docker configurations and update JwtService to use it
This commit is contained in:
@@ -79,6 +79,7 @@ services:
|
|||||||
ASPNETCORE_URLS: "http://0.0.0.0:8080"
|
ASPNETCORE_URLS: "http://0.0.0.0:8080"
|
||||||
DOTNET_RUNNING_IN_CONTAINER: "true"
|
DOTNET_RUNNING_IN_CONTAINER: "true"
|
||||||
DB_CONNECTION_STRING: "${DB_CONNECTION_STRING}"
|
DB_CONNECTION_STRING: "${DB_CONNECTION_STRING}"
|
||||||
|
JWT_SECRET: "${JWT_SECRET}"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
networks:
|
networks:
|
||||||
- devnet
|
- devnet
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ services:
|
|||||||
DOTNET_RUNNING_IN_CONTAINER: "true"
|
DOTNET_RUNNING_IN_CONTAINER: "true"
|
||||||
MASTER_DB_CONNECTION_STRING: "${MASTER_DB_CONNECTION_STRING}"
|
MASTER_DB_CONNECTION_STRING: "${MASTER_DB_CONNECTION_STRING}"
|
||||||
DB_CONNECTION_STRING: "${DB_CONNECTION_STRING}"
|
DB_CONNECTION_STRING: "${DB_CONNECTION_STRING}"
|
||||||
|
JWT_SECRET: "${JWT_SECRET}"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
networks:
|
networks:
|
||||||
- prodnet
|
- prodnet
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
DOTNET_RUNNING_IN_CONTAINER: "true"
|
DOTNET_RUNNING_IN_CONTAINER: "true"
|
||||||
DB_CONNECTION_STRING: "${TEST_DB_CONNECTION_STRING}"
|
DB_CONNECTION_STRING: "${TEST_DB_CONNECTION_STRING}"
|
||||||
|
JWT_SECRET: "${JWT_SECRET}"
|
||||||
volumes:
|
volumes:
|
||||||
- ./test-results:/app/test-results
|
- ./test-results:/app/test-results
|
||||||
restart: "no"
|
restart: "no"
|
||||||
@@ -93,6 +94,7 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
DOTNET_RUNNING_IN_CONTAINER: "true"
|
DOTNET_RUNNING_IN_CONTAINER: "true"
|
||||||
DB_CONNECTION_STRING: "${TEST_DB_CONNECTION_STRING}"
|
DB_CONNECTION_STRING: "${TEST_DB_CONNECTION_STRING}"
|
||||||
|
JWT_SECRET: "${JWT_SECRET}"
|
||||||
volumes:
|
volumes:
|
||||||
- ./test-results:/app/test-results
|
- ./test-results:/app/test-results
|
||||||
restart: "no"
|
restart: "no"
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
@@ -6,10 +7,9 @@ using Microsoft.IdentityModel.Tokens;
|
|||||||
using JwtRegisteredClaimNames = System.IdentityModel.Tokens.Jwt.JwtRegisteredClaimNames;
|
using JwtRegisteredClaimNames = System.IdentityModel.Tokens.Jwt.JwtRegisteredClaimNames;
|
||||||
|
|
||||||
namespace ServiceCore.Services;
|
namespace ServiceCore.Services;
|
||||||
public class JwtService(IConfiguration config) : IJwtService
|
public class JwtService : IJwtService
|
||||||
{
|
{
|
||||||
// private readonly string? _secret = config["Jwt:Secret"];
|
private readonly string? _secret = Environment.GetEnvironmentVariable("JWT_SECRET");
|
||||||
private readonly string? _secret = "128490218jfklsdajfdsa90f8sd0fid0safasr31jl2k1j4AFSDR!@#$fdsafjdslajfl";
|
|
||||||
public string GenerateJwt(Guid userId, string username, DateTime expiry)
|
public string GenerateJwt(Guid userId, string username, DateTime expiry)
|
||||||
{
|
{
|
||||||
var handler = new JsonWebTokenHandler();
|
var handler = new JsonWebTokenHandler();
|
||||||
|
|||||||
Reference in New Issue
Block a user