Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using AutoMapper;
- using Microsoft.AspNetCore.Authentication.JwtBearer;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.IdentityModel.Tokens;
- using Swashbuckle.AspNetCore.Swagger;
- using Microsoft.EntityFrameworkCore;
- using e_trust_API.Models;
- using e_trust_API.Filters;
- using Stripe;
- using Microsoft.AspNetCore.Http.Features;
- namespace e_trust_API
- {
- public class Startup
- {
- public IConfigurationRoot Configuration{get;set;}
- public static string ConnectionString{get;private set;}
- public static string Issuer { get; private set; }
- public static string Audience { get; private set; }
- public static string Key { get; private set; }
- public static string GoogleAPIKey { get; private set; }
- public static string ContentRootPath { get; private set; }
- public static string SiteUrl { get; set; }
- public static string EmailRegistration { get; set; }
- public static string CompanyId { get; set; }
- public static string MemberId { get; set; }
- public static string HyperAdminId { get; set; }
- public static string MemberType { get; set; }
- public static string FirstName { get; set; }
- public static string LastName { get; set; }
- public static string Email { get; set; }
- public static string Latitude { get; set; }
- public static string Longitude { get; set; }
- public static string emptyavatar { get; private set; }
- private readonly IHostingEnvironment _hostingEnvironment;
- public Startup(IHostingEnvironment env)
- {
- _hostingEnvironment = env;
- Configuration = new ConfigurationBuilder().SetBasePath(env.ContentRootPath).AddJsonFile("appSettings.json").Build();
- #if DEBUG
- StripeConfiguration.SetApiKey(Configuration["Stripe:TestKeys:SecretKey"]);
- #elif RELEASE
- // we will use the TestKeys until further notice
- StripeConfiguration.SetApiKey(Configuration["Stripe:TestKeys:SecretKey"]);
- #endif
- }
- //public Startup(IConfiguration configuration)
- //{
- // Configuration = configuration;
- //}
- //public IConfiguration Configuration { get; }
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- //services.AddJwtBearerAuthentication(Configuration);
- services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
- {
- options.TokenValidationParameters = new TokenValidationParameters
- {
- ValidateIssuer = true,
- ValidateAudience = true,
- ValidateIssuerSigningKey = true,
- ValidIssuer = Startup.Issuer,
- ValidAudience = Startup.Audience,
- IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Startup.Key))
- };
- });
- services.AddCors(options =>
- {
- options.AddPolicy("AllowAll",
- builder =>
- {
- builder
- .AllowAnyOrigin()
- .AllowAnyMethod()
- .AllowAnyHeader()
- .AllowCredentials();
- });
- });
- services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
- //To check before execution of action
- //services.AddMvc()
- // .AddMvcOptions(options =>
- // {
- // options.Filters.Add<ActionFilters>();
- // });
- //services.AddSingleton<ActionFilters>();
- //end
- var connection = Configuration["ConnectionStrings:DefaultConnection"];
- services.AddDbContext<ETrustContext>
- (options => options.UseSqlServer(connection));
- services.AddAutoMapper();
- //services.AddSwaggerGen(c =>
- //{
- // c.SwaggerDoc("v1", new Info { Title = "MY API", Version = "v1" });
- //});
- // Register the Swagger generator, defining 1 or more Swagger documents
- services.AddSwaggerGen(c =>
- {
- c.SwaggerDoc("v1", new Info
- {
- Version = "v1",
- Title = "Equanet DEV API",
- Description = "Equanet DEV API for development purpouses",
- License = new License
- {
- Name = "Use under LICX",
- Url = "https://example.com/license"
- },
- });
- var security = new Dictionary<string, IEnumerable<string>>
- {
- {"Bearer", new string[] { }},
- };
- c.AddSecurityDefinition("Bearer", new ApiKeyScheme
- {
- Description = "JWT Authorization header using the Bearer scheme. Example: \"authtoken: Bearer {token}\"",
- Name = "authtoken",
- In = "header",
- Type = "apiKey"
- });
- c.AddSecurityRequirement(security);
- // Set the comments path for the Swagger JSON and UI.
- var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
- var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
- c.IncludeXmlComments(xmlPath);
- });
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- app.UseMiddleware<ErrorHandlingMiddleware>();
- ConnectionString = Configuration["ConnectionStrings:DefaultConnection"];
- Issuer = Configuration["Issuer"];
- Audience = Configuration["Audience"];
- Key = Configuration["Key"];
- GoogleAPIKey= Configuration["GoogleAPIKey"];
- ContentRootPath = _hostingEnvironment.ContentRootPath;
- SiteUrl= Configuration["SiteUrl"];
- EmailRegistration= Configuration["EmailRegistration"];
- emptyavatar = Configuration["emptyavatar"];
- app.UseAuthentication();
- // Enable middleware to serve generated Swagger as a JSON endpoint.
- app.UseSwagger();
- // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
- // specifying the Swagger JSON endpoint.
- app.UseSwaggerUI(c =>
- {
- c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
- });
- app.UseCors("AllowAll");
- app.UseMvc();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement