Exemplo n.º 1
0
 public AccountController(IUserRepository context, IMapper mapper, ILogger logger, IOptions <SecretOptions> secretsOptions)
 {
     _context        = context;
     _mapper         = mapper;
     _logger         = logger;
     _secretsOptions = secretsOptions.Value;
 }
Exemplo n.º 2
0
 public AuthController(UserManager <ApplicationUser> userManager, IAuthService authService, IEmailService emailService, IMapper mapper, IOptions <FrontEndOptions> frontEndOptions, IOptions <SecretOptions> secretOptions)
 {
     _userManager     = userManager;
     _authService     = authService;
     _emailService    = emailService;
     _mapper          = mapper;
     _frontEndOptions = frontEndOptions.Value;
     _secretOptions   = secretOptions.Value;
 }
Exemplo n.º 3
0
 public WebHookController(
     IPushEventProcessor pushEventProcessor,
     IEventLogRepository eventLogRepository,
     IOptions <SecretOptions> secrets,
     ILogger <WebHookController> log)
 {
     _secrets            = secrets.Value;
     _pushEventProcessor = pushEventProcessor;
     _eventLogRepository = eventLogRepository;
     _log = log;
 }
Exemplo n.º 4
0
 public AuthenticateHandler(IUserRepository repositoryUser, IOptions <SecretOptions> options)
 {
     _repositoryUser = repositoryUser;
     _options        = options.Value;
 }
Exemplo n.º 5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // add DB connection string
            var connectionString = Configuration.GetConnectionString("OplevOgDelDb");

            // create a db connection for EF to use using the connection string
            services.AddDbContext <OplevOgDelDbContext>(x => x.UseSqlServer(connectionString, opt => opt.EnableRetryOnFailure()));

            // initialize auto mapper library
            services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            // initialize kisslogger library
            services.AddScoped((context) =>
            {
                return(Logger.Factory.Get());
            });

            // configured our controllers to ignore reference loops when converting object to json
            services.AddControllers()
            .AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

            // get options from appsettings.json initialized into options classes
            swaggerOptions = Configuration.GetSection(SwaggerOptions.Swagger).Get <SwaggerOptions>();
            secretsOptions = Configuration.GetSection(SecretOptions.Secret).Get <SecretOptions>();

            // configure and set up swagger documentation generation
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc(swaggerOptions.Version, new OpenApiInfo
                {
                    Version        = swaggerOptions.Version,
                    Title          = swaggerOptions.Title,
                    Description    = swaggerOptions.Description,
                    TermsOfService = new Uri(swaggerOptions.TermsOfService),
                    Contact        = new OpenApiContact
                    {
                        Name  = swaggerOptions.ContactName,
                        Email = swaggerOptions.ContactEmail,
                        Url   = new Uri(swaggerOptions.ContactUrl)
                    },
                    License = new OpenApiLicense
                    {
                        Name = swaggerOptions.LicenseName,
                        Url  = new Uri(swaggerOptions.LicenseUrl)
                    }
                });

                // tell it to use our XML documentation on the code files
                var filepath = Path.Combine(AppContext.BaseDirectory, "OplevOgDel.Api.xml");
                c.IncludeXmlComments(filepath);
            });

            services.ConfigureSwaggerGen(c =>
            {
                c.CustomSchemaIds(x => x.FullName);
            });

            // add our repository and configuration options classes to the dependency injection container
            services.AddScoped <IExperienceRepository, ExperienceRepository>();
            services.AddScoped <ICategoryRepository, CategoryRepository>();
            services.AddScoped <IProfileRepository, ProfileRepository>();
            services.AddScoped <IReviewReportRepository, ReviewReportRepository>();
            services.AddScoped <IExperienceReportRepository, ExperienceReportRepository>();
            services.AddScoped <IReviewRepository, ReviewRepository>();
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IPictureRepository, PictureRepository>();
            services.Configure <FileUploadOptions>(Configuration.GetSection(FileUploadOptions.FileUpload));
            services.Configure <SecretOptions>(Configuration.GetSection(SecretOptions.Secret));

            // configure authentication
            services.AddAuthentication(x =>
            {
                // we want to use the bearer authentication scheme
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x =>
            {
                x.SaveToken = true;
                x.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secretsOptions.Signature)),
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidIssuer   = secretsOptions.Issuer,
                    ValidAudience = secretsOptions.Audience,
                    ClockSkew     = TimeSpan.Zero
                };
            });
        }