Example #1
0
        public async Task <IActionResult> Details(Guid id, [FromServices] ICryptoServices crypto)
        {
            var model = await ApplicationDetailsViewModel.LoadAsync(_ctx, crypto, id);

            if (model != null)
            {
                return(View(model));
            }

            return(NotFound());
        }
        public async Task <Application> SaveChangesAsync(EmailServiceContext ctx, ICryptoServices crypto)
        {
            var app = CreateDbModel();

            app.PrimaryApiKey   = crypto.GeneratePrivateKey();
            app.SecondaryApiKey = crypto.GeneratePrivateKey();
            ctx.Applications.Add(app);
            await ctx.SaveChangesAsync();

            return(app);
        }
Example #3
0
 public BasicAuthenticationMiddleware(
     IApplicationKeyStore keyStore,
     ICryptoServices crypto,
     RequestDelegate next,
     ILoggerFactory loggerFactory,
     UrlEncoder encoder,
     IOptions <BasicAuthenticationOptions> options)
     : base(next, options, loggerFactory, encoder)
 {
     _crypto   = crypto;
     _keyStore = keyStore;
 }
Example #4
0
        public async Task <IActionResult> Create(CreateApplicationViewModel model, [FromServices] ICryptoServices crypto)
        {
            if (ModelState.IsValid)
            {
                var app = await model.SaveChangesAsync(_ctx, crypto);

                return(RedirectToAction(nameof(Details), new { id = app.Id }));
            }

            await model.LoadTransportAsync(_ctx);

            return(View(model));
        }
Example #5
0
 public AddModel(
     ICryptoServices cryptoServices,
     IOptions <CertificatesOptions> certificatesOptions,
     IAdminServices adminServices,
     ISessionTenantAccessor sessionTenantAccessor,
     ILogger <AddModel> logger)
 {
     _cryptoServices        = cryptoServices;
     _certificatesOptions   = certificatesOptions.Value;
     _adminServices         = adminServices;
     _sessionTenantAccessor = sessionTenantAccessor;
     _logger = logger;
 }
        public async Task SaveChangesAsync(EmailServiceContext ctx, ICryptoServices crypto)
        {
            var app = await ctx.FindApplicationAsync(Id);

            if (app != null)
            {
                if (IsPrimary)
                {
                    app.PrimaryApiKey = crypto.GeneratePrivateKey();
                }
                else if (IsSecondary)
                {
                    app.SecondaryApiKey = crypto.GeneratePrivateKey();
                }

                await ctx.SaveChangesAsync();
            }
        }
Example #7
0
        public async Task <IActionResult> RegenerateKey(Guid id, RegenerateKeyViewModel model, [FromServices] ICryptoServices crypto)
        {
            if (ModelState.IsValid)
            {
                await model.SaveChangesAsync(_ctx, crypto);

                return(RedirectToAction(nameof(Details), new { id }));
            }

            return(View(model));
        }
        public static async Task <ApplicationDetailsViewModel> LoadAsync(EmailServiceContext ctx, ICryptoServices crypto, Guid id)
        {
            var app = await ctx.Applications
                      .Include(a => a.Templates)
                      .Include(a => a.Transports)
                      .ThenInclude(t => t.Transport)
                      .FirstOrDefaultAsync(a => a.Id == id);

            if (app != null)
            {
                return(new ApplicationDetailsViewModel
                {
                    Id = app.Id,
                    Name = app.Name,
                    Description = app.Description,
                    SenderAddress = app.SenderAddress,
                    SenderName = app.SenderName,
                    PrimaryApiKey = crypto.GetApiKey(app.Id, app.PrimaryApiKey),
                    SecondaryApiKey = crypto.GetApiKey(app.Id, app.SecondaryApiKey),
                    CreatedUtc = app.CreatedUtc,
                    IsActive = app.IsActive,
                    Templates = app.Templates.Select(t => new KeyValuePair <Guid, string>(t.Id, t.Name)).ToList(),
                    Transports = app.Transports.Select(t => new KeyValuePair <Guid, string>(t.TransportId, t.Transport.Name)).ToList()
                });
            }

            return(null);
        }
Example #9
0
 public BasicAuthenticationHandler(ICryptoServices crypto, IApplicationKeyStore keyStore)
 {
     _crypto   = crypto;
     _keyStore = keyStore;
 }