コード例 #1
0
ファイル: Startup.cs プロジェクト: Dev-Lynx/Chop9ja.API
        IServiceCollection ConfigureOptions(IServiceCollection services)
        {
            services.AddOptions();

            var auth = Configuration.GetSection(AuthSettings.ConfigKey).Get <AuthSettings>();

            byte[] bytes = Encoding.ASCII.GetBytes(auth.Key);

            services.AddScoped <ITokenGenerator, TokenGenerator>(s => new TokenGenerator(bytes));

            services.Configure <EmailSettings>(Configuration.GetSection(EmailSettings.ConfigKey));
            services.Configure <SMSOptions>(Configuration.GetSection(SMSOptions.ConfigKey));
            services.Configure <AuthSettings>(Configuration.GetSection(AuthSettings.ConfigKey));
            services.Configure <PaystackOptions>(Configuration.GetSection(PaystackOptions.ConfigKey));

            services.Configure <JwtIssuerOptions>(opt =>
            {
                SymmetricSecurityKey key = new SymmetricSecurityKey(bytes);
                JwtIssuerOptions         = Configuration.GetSection(JwtIssuerOptions.ConfigKey)
                                           .Get <JwtIssuerOptions>();
                JwtIssuerOptions.SigningCredentials = new SigningCredentials(key,
                                                                             SecurityAlgorithms.HmacSha512Signature);

                var options            = JwtIssuerOptions;
                opt.Audience           = options.Audience;
                opt.Issuer             = options.Issuer;
                opt.SigningCredentials = JwtIssuerOptions.SigningCredentials;
                opt.Subject            = opt.Subject;
            });

            var mongoDbOptions = Configuration.GetSection(MongoDBOptions.CONFIG_KEY).Get <MongoDBOptions>();

            ConnectionString = Configuration.GetConnectionString("MongoDBAtlasConnection");
            ConnectionString = ConnectionString.BindTo(mongoDbOptions);
            DatabaseName     = mongoDbOptions.DatabaseName;
            services.Configure <MongoDBOptions>((opt) => opt = mongoDbOptions);

            return(services);
        }