Esempio n. 1
0
 public static void ConfigureServices(IServiceCollection services, SwaggerConfiguration swaggerConfiguration, AuthConfiguration authConfiguration)
 {
     services.AddSwaggerGen(c =>
     {
         c.SwaggerDoc("v1",
                      new Info
         {
             Version        = "v1",
             Title          = "Swashbuckle Sample API",
             Description    = "A sample API for testing Swashbuckle",
             TermsOfService = "Some terms ..."
         }
                      );
         if (authConfiguration?.IsEnabled == true)
         {
             c.AddSecurityDefinition("oauth2", new OAuth2Scheme
             {
                 Type             = "oauth2",
                 Flow             = "implicit",
                 AuthorizationUrl = $"{authConfiguration.Authority}/connect/authorize",
                 Scopes           = new Dictionary <string, string>
                 {
                     //{"openid","openid"},
                     { $"{authConfiguration.Scope}", authConfiguration.Scope }
                 }
             });
             c.OperationFilter <SecurityRequirementsOperationFilter>();
         }
     });
     services.ConfigureSwaggerGen(c =>
     {
         c.IncludeXmlComments(GetXmlCommentsPath(PlatformServices.Default.Application));
     });
 }
Esempio n. 2
0
        public static void Configure(IApplicationBuilder app, SwaggerConfiguration swaggerConfiguration, AuthConfiguration authConfiguration)
        {
            app.UseSwagger(c =>
            {
                c.PreSerializeFilters.Add((swagger, httpReq) => swagger.Host = httpReq.Host.Value);
            });

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1 Docs");

                if (authConfiguration?.IsEnabled == true)
                {
                    c.OAuthClientId(swaggerConfiguration.ClientId);
                    c.OAuthRealm(authConfiguration.Application);
                    c.OAuthAppName(swaggerConfiguration.ApplicationName);
                    c.OAuthScopeSeparator(" ");
                }
            });
        }