diff --git a/docker-compose.yml b/docker-compose.yml index 054a2ed..492a5b2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: - ASPNETCORE_ENVIRONMENT=Development - ConnectionStrings__DefaultConnection=Server=${SQL_SERVER};Database=${SQL_DATABASE};User Id=${SQL_USER_ID};Password=${SQL_PASSWORD};Encrypt=false;TrustServerCertificate=true;MultipleActiveResultSets=true; - ASPNETCORE_URLS=http://+:8080 - - Auth0__Domain=${AUTH0_ISSUER_BASE_URL} + - Auth0__Authority=${AUTH0_DOMAIN} - Auth0__Audience=${AUTH0_AUDIENCE} depends_on: - mssql @@ -32,7 +32,7 @@ services: - AUTH0_CLIENT_ID=${AUTH0_CLIENT_ID} - AUTH0_CLIENT_SECRET=${AUTH0_CLIENT_SECRET} - AUTH0_AUDIENCE=${AUTH0_AUDIENCE} - - AUTH0_SCOPE=openid profile email read:shows + - AUTH0_SCOPE=${AUTH0_SCOPE} - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} - NEXT_PUBLIC_AUTH0_CLIENT_ID=${NEXT_PUBLIC_AUTH0_CLIENT_ID} - NEXT_PUBLIC_AUTH0_DOMAIN=${NEXT_PUBLIC_AUTH0_DOMAIN} diff --git a/src/Imprink.WebApi/Startup.cs b/src/Imprink.WebApi/Startup.cs index 42fe7a3..683a413 100644 --- a/src/Imprink.WebApi/Startup.cs +++ b/src/Imprink.WebApi/Startup.cs @@ -1,4 +1,3 @@ -using System.Security.Claims; using Imprink.Application; using Imprink.Application.Products.Handlers; using Imprink.Domain.Repositories; @@ -7,7 +6,6 @@ using Imprink.Infrastructure.Database; using Imprink.Infrastructure.Repositories; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.EntityFrameworkCore; -using Microsoft.IdentityModel.Tokens; namespace Imprink.WebApi; @@ -32,18 +30,17 @@ public static class Startup cfg.RegisterServicesFromAssembly(typeof(CreateProductHandler).Assembly); }); - services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) - .AddJwtBearer(options => - { - options.Authority = $"https://{builder.Configuration["Auth0:Domain"]}/"; - options.Audience = builder.Configuration["Auth0:Audience"]; - options.TokenValidationParameters = new TokenValidationParameters - { - NameClaimType = ClaimTypes.NameIdentifier - }; - }); + services.AddAuthentication(options => + { + options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + }).AddJwtBearer(options => + { + options.Authority = builder.Configuration["Auth0:Authority"]; + options.Audience = builder.Configuration["Auth0:Audience"]; + }); - builder.Services.AddAuthorization(); + services.AddAuthorization(); services.AddControllers(); services.AddSwaggerGen(); @@ -66,25 +63,20 @@ public static class Startup } } - // if (env.IsDevelopment()) - // { - // app.UseSwagger(); - // app.UseSwaggerUI(); - // app.UseDeveloperExceptionPage(); - // } - // else - // { - // app.UseExceptionHandler("/Error"); - // app.UseHsts(); - // app.UseHttpsRedirection(); - // } - - app.UseSwagger(); - app.UseSwaggerUI(); - app.UseDeveloperExceptionPage(); + if (env.IsDevelopment()) + { + app.UseSwagger(); + app.UseSwaggerUI(); + app.UseDeveloperExceptionPage(); + } + else + { + app.UseExceptionHandler("/Error"); + app.UseHsts(); + app.UseHttpsRedirection(); + } app.UseRouting(); - app.UseAuthentication(); app.UseAuthorization(); diff --git a/webui/src/lib/auth0.js b/webui/src/lib/auth0.js index 4c63bf2..866f6f4 100644 --- a/webui/src/lib/auth0.js +++ b/webui/src/lib/auth0.js @@ -2,7 +2,7 @@ import { Auth0Client } from "@auth0/nextjs-auth0/server"; export const auth0 = new Auth0Client({ authorizationParameters: { - scope: 'openid profile email', - audience: 'imprink-front' + scope: process.env.AUTH0_SCOPE, + audience: process.env.AUTH0_AUDIENCE } }); \ No newline at end of file