// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { #region Google OAuth 2.0 GoogleAuthorizationCodeFlow.Initializer authInitializer = new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = new ClientSecrets { ClientId = _configuration["Authentication:Google:ClientId"], ClientSecret = _configuration["Authentication:Google:ClientSecret"] }, DataStore = GoogleDataStores.GOOGLE_AUTH_TOKEN_STORE, IncludeGrantedScopes = true, Scopes = new string[] { @"https://www.googleapis.com/auth/userinfo.profile", }, }; _ = services.AddScoped(elem => authInitializer); _ = services.AddScoped <GoogleCredentialManager>(); #endregion #region chance // This is an implementation of the corresponding .js library Chance chance = new ConcurrentChance(); _ = services.AddSingleton(chance); #endregion #region routing _ = services.AddControllers(); #endregion #region authentication _ = services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { /* The normal login system cannot combine with an OAuth 2.0 system * as the app cannot 300 the user to the google login page. */ options.Events = new CustomCookieAuthenticationEvents(); }); #endregion #region authorization _ = services.AddAuthorization(); #endregion #region Swashbuckle string version = APIVERSION.ToString(); _ = services.AddSwaggerGen(options => { options.SwaggerDoc(version, new OpenApiInfo { Title = APPNAME, Version = version }); }); #endregion #region HttpContext _ = services.AddHttpContextAccessor(); #endregion #region YouTube _ = services.AddScoped <YouTubeServiceAccessor>(); #endregion #region Google Cloud Translate _ = services.AddScoped <GoogleCloudTranslateServiceAccessor>(); #endregion }
static void Main(string[] args) { chance = new ConcurrentChance(); server = WebServer.Create <UserSession>(Options.Host, Options.Port, Options.SessionLifetime); server.LogLevel = LogLevels.All; server.OnLog += (s, arg) => Console.WriteLine(arg.Line); /* * Register content providers */ StaticResourceProvider css = new StaticResourceProvider(GetPath("app/css"), "/css", ContentType.Css); server.Add("/css/*.css", css.OnRequest); StaticResourceProvider js = new StaticResourceProvider(GetPath("app/js"), "/js", ContentType.Javascript); server.Add("/js/*.js", js.OnRequest); StaticResourceProvider png = new StaticResourceProvider(GetPath("app/img"), "/img", ContentType.Image); server.Add("/img/*", png.OnRequest); WatermarkedResourceProvider evtImg = new WatermarkedResourceProvider(Options.StoragePath("eventimg"), "/eventimg"); server.Add("/eventimg/*", evtImg.OnRequest); ResizedResourceProvider evtThumb = new ResizedResourceProvider(Options.StoragePath("eventimg"), "/eventthumb", Options.EventThumbnailWidth, Options.EventThumbnailHeight); server.Add("/eventthumb/*", evtThumb.OnRequest); /* * Start event scheduler */ scheduler = new EventScheduler(); scheduler.Start(); /* * Register API */ Api api = new Api(server); HtmlProvider pages = new HtmlProvider(); server.Add("/", pages.Index); server.Add("/index", pages.Index); server.Add("/events", pages.Events); server.Add("/event/*", pages.Event); server.Add("/profile", pages.Profile); server.Add("/admin", pages.Admin); server.Start(); Console.WriteLine("Press CTRL-C to shut down."); /* * Main thread now awaits SIGTERM */ if (IsLinux()) { SignalWaiter.Instance.WaitExitSignal(); Shutdown(); } else { Console.CancelKeyPress += (s, e) => Shutdown(); while (true) { Thread.Sleep(1000); } } }