diff --git a/.github/workflows/compose-build.yml b/.github/workflows/compose-build.yml index f5bcd15..d76aff6 100644 --- a/.github/workflows/compose-build.yml +++ b/.github/workflows/compose-build.yml @@ -22,21 +22,18 @@ jobs: - name: Start Docker Compose run: docker compose up -d -# ToDo -# - name: Health Check AuthService -# run: | -# echo "Checking health..." -# for i in {1..10}; do -# curl --fail http://localhost:8000/auth/health && break || sleep 5 -# curl --fail http://gateway:8000/auth/health && break || sleep 5 -# done -# curl --fail http://localhost:8000/auth/health || exit 1 -# -# - name: Health Check PostService -# run: | -# echo "Checking health..." -# for i in {1..10}; do -# curl --fail http://localhost:8000/post/health && break || sleep 5 -# curl --fail http://gateway:8000/post/health && break || sleep 5 -# done -# curl --fail http://localhost:8000/post/health || exit 1 \ No newline at end of file + - name: Health Check AuthService + run: | + echo "Checking health..." + for i in {1..10}; do + curl --fail http://0.0.0.0:8000/auth/health && break || sleep 5 + done + curl --fail http://0.0.0.0:8000/auth/health || exit 1 + + - name: Health Check PostService + run: | + echo "Checking health..." + for i in {1..10}; do + curl --fail http://0.0.0.0:8000/post/health && break || sleep 5 + done + curl --fail http://0.0.0.0:8000/post/health || exit 1 \ No newline at end of file diff --git a/backend/src/AuthService/AuthService.Infrastructure/DependencyInjection.cs b/backend/src/AuthService/AuthService.Infrastructure/DependencyInjection.cs index 6b54ba6..3719245 100644 --- a/backend/src/AuthService/AuthService.Infrastructure/DependencyInjection.cs +++ b/backend/src/AuthService/AuthService.Infrastructure/DependencyInjection.cs @@ -29,8 +29,6 @@ public static IServiceCollection AddInfrastructureServices(this IServiceCollecti keycloakSection[AppSettingsConstants.AdminPassword] ); - var rsaSecurityKey = GetRsaSecurityKeyFromKeycloak(keycloakConfig.Url, keycloakConfig.Realm); - services.AddSingleton(keycloakConfig); services.AddHttpClient("KeycloakClient", client => @@ -63,7 +61,6 @@ public static IServiceCollection AddInfrastructureServices(this IServiceCollecti ValidAudience = "account", ValidateLifetime = true, ValidateIssuerSigningKey = false, - IssuerSigningKey = rsaSecurityKey, SignatureValidator = (token, parameters) => { var jwt = new JsonWebToken(token); @@ -80,46 +77,4 @@ public static IServiceCollection AddInfrastructureServices(this IServiceCollecti return services; } - - private static RsaSecurityKey GetRsaSecurityKeyFromKeycloak(string keycloakUrl, string realm) - { - using var httpClient = new HttpClient(); - var certsUrl = $"{keycloakUrl}/realms/{realm}/protocol/openid-connect/certs"; - var response = httpClient.GetStringAsync(certsUrl).Result; - - var jwks = JsonDocument.Parse(response).RootElement; - var key = jwks.GetProperty("keys")[0]; - - var modulusBase64 = key.GetProperty("n").GetString()?.Trim(); - var exponentBase64 = key.GetProperty("e").GetString()?.Trim(); - - if (string.IsNullOrEmpty(modulusBase64) || string.IsNullOrEmpty(exponentBase64)) - { - throw new FormatException("Invalid modulus or exponent in the public key"); - } - - try - { - modulusBase64 = ConvertUrlBase64ToStandardBase64(modulusBase64); - exponentBase64 = ConvertUrlBase64ToStandardBase64(exponentBase64); - - var modulus = Convert.FromBase64String(modulusBase64); - var exponent = Convert.FromBase64String(exponentBase64); - - return new RsaSecurityKey(new RSAParameters - { - Modulus = modulus, - Exponent = exponent - }); - } - catch (FormatException ex) - { - throw new FormatException("Base64 decoding failed for modulus or exponent", ex); - } - } - - private static string ConvertUrlBase64ToStandardBase64(string urlBase64) - { - return urlBase64.Replace('-', '+').Replace('_', '/') + new string('=', (4 - urlBase64.Length % 4) % 4); - } } \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 699b58d..b3e7801 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,7 @@ services: depends_on: gateway: condition: service_healthy - networks: + networks: - microservices gateway: @@ -36,7 +36,7 @@ services: interval: 10s timeout: 5s retries: 3 - networks: + networks: - microservices auth-service: @@ -113,9 +113,9 @@ services: - "8080:8080" command: [ "start-dev" ] restart: always - networks: + networks: - microservices - + rabittmq: image: rabbitmq:4-management container_name: rabbitmq @@ -134,4 +134,4 @@ services: - microservices volumes: - postgres-data: + postgres-data: \ No newline at end of file