public static PlatformBuilder ConfigureWebApi(this PlatformBuilder builder, Action <PlatformexWebApiOptions> optionsBuilder) { var options = new PlatformexWebApiOptions("api"); optionsBuilder(options); builder.AddConfigureServicesActions(collection => { collection.AddSingleton(options); }); return(builder); }
public static PlatformBuilder WithConsole(this PlatformBuilder builder, Action <PlatformexGraphQlConsoleOptions> builderOptions) { var options = new PlatformexGraphQlConsoleOptions("graphql-console"); builderOptions(options); builder.AddConfigureServicesActions(services => { services.AddSingleton(options); }); return(builder); }
public static PlatformBuilder ConfigureGraphQl(this PlatformBuilder builder, Action <PlatformexGraphQlOptions> optionsBuilder) { var options = new PlatformexGraphQlOptions("graphql"); builder.AddConfigureServicesActions(services => { optionsBuilder?.Invoke(options); services.AddSingleton(options); //services.AddSingleton<IDocumentExecuter, DocumentExecuter>(); //services.AddSingleton<IDocumentWriter, DocumentWriter>(); services.AddSingleton <Root>(); services.AddSingleton <ISchema, GraphSchemaInternal>(); services.AddGraphQL(_ => { _.EnableMetrics = true; //_.ExposeExceptions = true; }) .AddSystemTextJson() .AddErrorInfoProvider(opt => opt.ExposeExceptionStackTrace = true); //services.AddTransient<IGraphQLRequestDeserializer, GraphQLRequestDeserializer>(); foreach (var query in builder.Definitions.Queries) { var handlerType = typeof(GraphQueryHandler <,>).MakeGenericType(query.Value.QueryType, query.Value.ResultType); var handlerFullType = typeof(IGraphQueryHandler <,>).MakeGenericType(query.Value.QueryType, query.Value.ResultType); services.AddSingleton(handlerFullType, handlerType); //services.AddSingleton(provider => (IGraphQueryHandler) provider.GetService(handlerFullType)); } }); UseExtensions.AddPreUseAction(app => { if (app.ApplicationServices.GetService(typeof(PlatformexGraphQlOptions)) is PlatformexGraphQlOptions optionsGraphQl) { app.UseGraphQL <ISchema>("/" + optionsGraphQl.BasePath.Trim('/')); } if (app.ApplicationServices.GetService(typeof(PlatformexGraphQlConsoleOptions)) is PlatformexGraphQlConsoleOptions optionsConsole) { app.UseGraphQLPlayground("/" + optionsConsole.BasePath.Trim('/')); } }); return(builder); }
public static PlatformBuilder ConfigureServices(this PlatformBuilder builder, Action <IServiceCollection, IConfiguration> configAction) { var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{environment}.json", optional: true) .AddEnvironmentVariables() .Build(); builder.AddConfigureServicesActions(collection => { configAction(collection, configuration); }); return(builder); }
public static PlatformBuilder ConfigureIdentity(this PlatformBuilder builder, Action <PlatformexIdentityOptions> optionsBuilder) { var opt = new PlatformexIdentityOptions { IdentityServerUri = "https://localhost:5000" }; builder.AddConfigureServicesActions(services => { optionsBuilder?.Invoke(opt); //services.AddAuthentication("Bearer") // .AddIdentityServerAuthentication("Bearer", options => // { // // required audience of access tokens // options.ApiName = "platformex"; // // auth server base endpoint (this will be used to search for disco doc) // options.Authority = opt.IdentityServerUri; // }); services.AddAuthentication("Bearer") .AddJwtBearer("Bearer", options => { options.Authority = opt.IdentityServerUri; options.TokenValidationParameters = new TokenValidationParameters { ValidateAudience = false, NameClaimType = JwtClaimTypes.Subject, RoleClaimType = JwtClaimTypes.Role }; }); }); UseExtensions.AddPreUseAction(app => { app.UseAuthentication(); app.UseAuthorization(); }); return(builder); }
public static PlatformBuilder WithOpenApi(this PlatformBuilder builder, Action <PlatformexOpenApiOptions> optionsBuilder) { var options = new PlatformexOpenApiOptions("swagger", Assembly.GetEntryAssembly()?.GetName().Name); optionsBuilder(options); builder.AddConfigureServicesActions(services => { services.AddSingleton(options); services.TryAdd(ServiceDescriptor .Transient <IApiDescriptionGroupCollectionProvider, CommandsApiDescriptionGroupCollectionProvider>()); services.AddSingleton <IApiDescriptionGroupCollectionProvider, CommandsApiDescriptionGroupCollectionProvider>(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = options.Name + " API", Version = "v1" }); c.OperationFilter <DescriptionFilter>(); c.OperationFilter <AuthorizeCheckOperationFilter>(); c.SchemaFilter <ReadOnlyFilter>(); c.CustomSchemaIds(i => i.FullName); c.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme { Type = SecuritySchemeType.OAuth2, Flows = new OpenApiOAuthFlows { AuthorizationCode = new OpenApiOAuthFlow { AuthorizationUrl = new Uri("https://localhost:5000/connect/authorize"), TokenUrl = new Uri("https://localhost:5000/connect/token"), Scopes = new Dictionary <string, string> { { "openid", "User Profile" }, { "platformex", "Platformex API - full access" } } } } }); c.DocInclusionPredicate((docName, apiDesc) => apiDesc.TryGetMethodInfo(out _) && apiDesc.HttpMethod != null); /*var basePath = AppDomain.CurrentDomain.BaseDirectory; * var files = Directory.GetFiles(basePath, "*.xml"); * foreach (var file in files) * { * c.IncludeXmlComments(file); * }*/ }); }); UseExtensions.AddPreUseAction(app => { app.UseSwagger(); var apiOptions = app.ApplicationServices.GetRequiredService <PlatformexOpenApiOptions>(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/" + apiOptions.Url.Trim('/') + "/v1/swagger.json", apiOptions.Name); c.OAuthClientId("swagger"); c.OAuthAppName("Platformex Open API"); c.OAuthUsePkce(); }); }); return(builder); }