static void Main(string[] args) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile($"appsettings.json") .AddEnvironmentVariables(); var configuration = builder.Build(); var services = new ServiceCollection(); ConfigurationHelper.ConfigureSharedServices(configuration, services); services.AddScoped <IAmazonSimpleNotificationService>(s => new AmazonSimpleNotificationServiceClient(RegionEndpoint.USWest2)); services.AddScoped <ISenderService, SenderService>(); var provider = services.BuildServiceProvider(); var reminderRepository = provider.GetRequiredService <IReminderRepository>(); var senderService = provider.GetRequiredService <ISenderService>(); var logger = provider.GetRequiredService <INpgLogger>(); try { var reminderId = Int64.Parse(args[0]); var reminder = reminderRepository.GetReminderById(reminderId); senderService.SendReminder(reminder); reminderRepository.UpdateReminderLastRunTime(reminderId); } catch (Exception ex) { logger.LogError(ex); } }
// This method gets called by the runtime. Use this method to add services to the container. public virtual void ConfigureServices(IServiceCollection services) { ConfigurationHelper.ConfigureSharedServices(Configuration, services); var deployBucket = Configuration.GetSection("AWS").GetSection("S3")["DeployBucket"]; var cognitoConfigKey = Configuration.GetSection("AWS").GetSection("S3")["CognitoConfigurationKey"]; var s3Client = new AmazonS3Client(RegionEndpoint.USWest2); var storageAdapter = new AwsS3Adapter(s3Client); var cognitoAdapterConfig = JsonConvert.DeserializeObject <AwsCognitoAdapterConfig>(storageAdapter.GetObjectAsync(deployBucket, cognitoConfigKey).Result); var validIssuer = Configuration.GetValidIssuer(cognitoAdapterConfig.UserPoolId); services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. //options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.Events = new JwtBearerEvents { OnMessageReceived = context => { context.Token = context.Request.Cookies["IdToken"]; return(Task.CompletedTask); } }; options.TokenValidationParameters = new TokenValidationParameters { IssuerSigningKeyResolver = (s, token, identifier, parameters) => { var json = new WebClient().DownloadString($"{validIssuer}/.well-known/jwks.json"); var keys = JsonConvert.DeserializeObject <JsonWebKeySet>(json).Keys; return((IEnumerable <SecurityKey>)keys); }, ClockSkew = TimeSpan.FromMinutes(5), LifetimeValidator = (notBefore, expires, token, parameters) => { if (expires != null) { //return false; if (DateTime.UtcNow < expires) { return(true); } } return(false); }, ValidateIssuer = true, ValidateAudience = false, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = validIssuer }; }); services.AddScoped <AwsCognitoAdapterConfig>(s => cognitoAdapterConfig); services.AddScoped <IAwsCognitoAdapterHelper, AwsCognitoAdapterHelper>(); services.AddScoped <IAmazonCognitoIdentityProvider, AmazonCognitoIdentityProviderClient>(); services.AddScoped <IAuthAdapter, AwsCognitoAdapter>(); services.AddScoped <IUserRepository, UserRepository>(); }