// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.AddRazorPages(); services.AddMvc(); services.AddEntityFrameworkSqlite().AddDbContext <TwaspDbContext>(); services.AddAuthentication(options => { options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; }) //TwitterAPIをDBから取得 .AddTwitter(twitterOptions => { var option = new DbContextOptionsBuilder <TwaspDbContext>(); var connectionString = "Twasp.db"; option.UseSqlite(connectionString); using var context = new TwaspDbContext(option.Options); var enviroment = context.Enviroment.Single(); var key = enviroment.Akey; var secretKey = enviroment.ASecretKey; twitterOptions.ConsumerKey = key; twitterOptions.ConsumerSecret = secretKey; twitterOptions.Events.OnCreatingTicket = async context => { var identity = (ClaimsIdentity)context.Principal.Identity; identity.AddClaim(new Claim("ScreenName", context.ScreenName)); identity.AddClaim(new Claim("UserId", context.UserId)); }; }).AddCookie(options => { options.LoginPath = "/Auth/Login"; }); }
//コンストラクタ public FavoriteController(TwaspDbContext context) { this.context = context; }
//コンストラクタ public EnviromentController(TwaspDbContext context) { this.context = context; }