public static void InitializeAzureStorage() { string storageConnectionString = CloudConfigurationManager.GetSetting("StorageConnectionString"); string ocrQueueName = RoleEnvironment.GetConfigurationSettingValue("OCRQueueName"); string imageBlobContainerName = RoleEnvironment.GetConfigurationSettingValue("ImageBlobContainerName"); string ocrJobTableName = RoleEnvironment.GetConfigurationSettingValue("OCRJobTableName"); // Email queue and Text blob container won't be used in Web Role so we'll just pass nulls. // Sure, in this situation AzureQueues and AzureBlobs classes don't look like good design but let's keep it simple. // I don't want to use tons of interfaces, DI and statelessness and in a simple 1K LOC project like this. AzureQueues.Initialize(storageConnectionString, ocrQueueName, null); AzureBlobs.Initialize(storageConnectionString, imageBlobContainerName, null); AzureTables.Initialize(storageConnectionString, ocrJobTableName); }
private void InitializeAzureStorage() { Trace.TraceInformation("Initializing Azure Storage."); Trace.TraceInformation("Loading storage settings."); string storageConnectionString = RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"); string textBlobContainerName = RoleEnvironment.GetConfigurationSettingValue("TextBlobContainerName"); string emailQueueName = RoleEnvironment.GetConfigurationSettingValue("EmailQueueName"); string ocrJobTableName = RoleEnvironment.GetConfigurationSettingValue("OCRJobTableName"); Trace.TraceInformation("Initializing Blobs."); AzureBlobs.Initialize(storageConnectionString, null, textBlobContainerName); Trace.TraceInformation("Initializing Queues."); AzureQueues.Initialize(storageConnectionString, null, emailQueueName); Trace.TraceInformation("Initializing Tables."); AzureTables.Initialize(storageConnectionString, ocrJobTableName); }
private Startup() { Configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); var tables = AzureTables.InitializeAzureTables(Configuration["ConnectionStrings:DefaultConnection"], "Auth"); foreach (var table in tables) { AzureTableRepo.Collection.Add(table.Name, table); } AuthUtility = new Nivra.AzureOperations.Utility(Configuration["ConnectionStrings:DefaultConnection"], "Auth"); UserTokenUtility = new Nivra.AzureOperations.Utility(Configuration["ConnectionStrings:DefaultConnection"], "UserTokens"); Dict.Add("Email", $"{Helper.GenerateRandomString(9, options: GenerateRandomStringOptions.IncludeAlphabets)}@{Helper.GenerateRandomString(5, GenerateRandomStringOptions.IncludeAlphabets)}.com"); Dict.Add("Password", $"{Helper.GenerateRandomString(9, GenerateRandomStringOptions.CaseSensitive | GenerateRandomStringOptions.IncludeAlphabets | GenerateRandomStringOptions.IncludeDigits | GenerateRandomStringOptions.IncludeNonAlphaNumericCharacters)}"); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddIdentityCore <AzureTableUser>(options => options.SignIn.RequireConfirmedAccount = true ) //.AddTokenProvider<EmailConfirmationTokenProvider<AzureTableUser>>(TokenOptions.DefaultProvider) .AddTokenProvider <PasswordResetTokenProvider <AzureTableUser> >(TokenOptions.DefaultProvider) //.AddTokenProvider<ChangePhoneNumberTokenProvider<AzureTableUser>>(TokenOptions.DefaultProvider) //.AddTokenProvider<EmailTokenProvider<AzureTableUser>>("ChangePhoneNumber") .AddTokenProvider <UserTwoFactorTokenProvider>(TokenOptions.DefaultProvider) //.AddTokenProvider<DataProtectorTokenProvider<AzureTableUser>>(TokenOptions.DefaultProvider) .AddTokenProvider <AppEmailConfirmationTokenProvider <AzureTableUser> >("EmailConfirmationTokenProvider") //.AddTokenProvider<PasswordResetTokenProvider<AzureTableUser>>("PasswordReset") //.AddTokenProvider<ChangePhoneNumberTokenProvider<AzureTableUser>>("ChangePhoneNumber") ////.AddTokenProvider<EmailTokenProvider<AzureTableUser>>("ChangePhoneNumber") //.AddTokenProvider<UserTwoFactorTokenProvider>("TwoFactorTokenProvider") // .AddTokenProvider<DataProtectorTokenProvider<AzureTableUser>>(TokenOptions.DefaultProvider) .AddDefaultTokenProviders() ; AzureTableRepo azureTableRepo = new AzureTableRepo(); Nivra.AzureOperations.Utility utility = new Nivra.AzureOperations.Utility(Configuration["ConnectionStrings:DefaultConnection"], "Auth"); //Configuring CORS services.AddCors(config => { config.AddPolicy("AllowAll", builder => { builder.WithOrigins(Configuration["AllowedHosts"]) .AllowAnyMethod() .AllowAnyHeader(); }); }); // // Configuring PasswordHasher //services.Configure<PasswordHasherOptions>(options => //{ // options.HashAlgorithm = PasswordHasherAlgorithms.SHA1; // options.SaltSize = 16; // options.IterationCount = 8192; //}); //// Registering PasswordHasher //services.AddPasswordHasher(); //services.AddIdentity<AzureTableUser, AzureTableRole>(); JwtTokenConfigurations.Load(Configuration); services.AddGenericJwtAuthService(); var tables = AzureTables.InitializeAzureTables(Configuration["ConnectionStrings:DefaultConnection"], "Auth"); foreach (var table in tables) { azureTableRepo.Collection.Add(table.Name, table); } services.AddSingleton <IAzureTableRepo>(azureTableRepo); services.AddSingleton <Nivra.AzureOperations.Utility>(utility); // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" }); }); services.AddControllersWithViews() .AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore ); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); services.AddTransient <IEmailSender, EmailSender>(); services.Configure <AuthMessageSenderOptions>(Configuration); services.AddTransient(typeof(IUserTwoFactorTokenProvider <AzureTableUser>), typeof(UserTwoFactorTokenProvider)); services.AddSingleton(typeof(TextResourceManager)); }