diff --git a/apps/auth-server/src/EShopOnAbp.AuthServer/EShopOnAbpAuthServerModule.cs b/apps/auth-server/src/EShopOnAbp.AuthServer/EShopOnAbpAuthServerModule.cs index 45fab514..95f4e574 100644 --- a/apps/auth-server/src/EShopOnAbp.AuthServer/EShopOnAbpAuthServerModule.cs +++ b/apps/auth-server/src/EShopOnAbp.AuthServer/EShopOnAbpAuthServerModule.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Hosting; using StackExchange.Redis; using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography.X509Certificates; @@ -72,32 +73,20 @@ namespace EShopOnAbp.AuthServer } } - private X509Certificate2 GetSigningCertificate(IWebHostEnvironment hostingEnv, IConfiguration configuration) - { - var fileName = "eshoponabp-authserver.pfx"; - var passPhrase = "780F3C11-0A96-40DE-B335-9848BE88C77D"; - var file = Path.Combine(hostingEnv.ContentRootPath, fileName); - - if (!File.Exists(file)) - { - throw new FileNotFoundException($"Signing Certificate couldn't found: {file}"); - } - - return new X509Certificate2(file, passPhrase); - } - public override void ConfigureServices(ServiceConfigurationContext context) { Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true; var hostingEnvironment = context.Services.GetHostingEnvironment(); var configuration = context.Services.GetConfiguration(); + + ConfigureSwagger(context, configuration); context.Services.AddAuthentication() .AddJwtBearer(options => { options.Authority = configuration["AuthServer:Authority"]; options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); - options.Audience = "AuthServer"; + options.Audience = "AccountService"; }); Configure(options => @@ -105,14 +94,6 @@ namespace EShopOnAbp.AuthServer options.IssuerUri = configuration["App:SelfUrl"]; }); - Configure(options => - { - options.IsEnabled = true; - }); - - // context.Services.Replace(ServiceDescriptor.Transient()); - - Configure(options => { options.RequestedClaims.AddRange(new[]{ @@ -215,11 +196,43 @@ namespace EShopOnAbp.AuthServer app.UseUnitOfWork(); app.UseIdentityServer(); app.UseAuthorization(); + app.UseSwagger(); + app.UseSwaggerUI(options => + { + options.SwaggerEndpoint("/swagger/v1/swagger.json", "Account Service API"); + }); app.UseAuditing(); app.UseConfiguredEndpoints(endpoints => { // endpoints.MapMetrics(); }); } + + private X509Certificate2 GetSigningCertificate(IWebHostEnvironment hostingEnv, IConfiguration configuration) + { + var fileName = "eshoponabp-authserver.pfx"; + var passPhrase = "780F3C11-0A96-40DE-B335-9848BE88C77D"; + var file = Path.Combine(hostingEnv.ContentRootPath, fileName); + + if (!File.Exists(file)) + { + throw new FileNotFoundException($"Signing Certificate couldn't found: {file}"); + } + + return new X509Certificate2(file, passPhrase); + } + + private void ConfigureSwagger(ServiceConfigurationContext context, IConfiguration configuration) + { + SwaggerWithAuthConfigurationHelper.Configure( + context: context, + authority: configuration["AuthServer:Authority"], + scopes: new Dictionary /* Requested scopes for authorization code request and descriptions for swagger UI only */ + { + {"AccountService", "Account Service API"}, + }, + apiTitle: "Account Service API" + ); + } } } \ No newline at end of file diff --git a/apps/auth-server/src/EShopOnAbp.AuthServer/appsettings.json b/apps/auth-server/src/EShopOnAbp.AuthServer/appsettings.json index d7771935..775b5032 100644 --- a/apps/auth-server/src/EShopOnAbp.AuthServer/appsettings.json +++ b/apps/auth-server/src/EShopOnAbp.AuthServer/appsettings.json @@ -13,7 +13,9 @@ }, "AuthServer": { "Authority": "https://localhost:44330", - "RequireHttpsMetadata": "true" + "RequireHttpsMetadata": "true", + "SwaggerClientId": "AccountService_Swagger", + "SwaggerClientSecret": "1q2w3e*" }, "AllowedHosts": "*", "ConnectionStrings": {