private bool ValidateApiKey(string handle) { var apiKey = Request.Headers["API-Key"]; if (_apiKeyProvider.CheckBase64(handle, apiKey)) { return(true); } _logger.LogWarning(EventIds.PresenterInvalidApiKey, "Invalid API key."); return(false); }
public async Task <IActionResult> Start(string handle, [FromBody] StartShow startShow, CancellationToken ct) { var apiKey = Request.Headers["API-Key"]; if (!_apiKeyProvider.CheckBase64(handle, apiKey)) { _logger.LogWarning(EventIds.PresenterInvalidApiKey, "Invalid API key."); return(Forbid()); } startShow.Presenter = handle; var show = await _shows.Start(startShow, ct).ConfigureAwait(false); return(CreatedAtAction("Show", "Live", new { presenter = startShow.Presenter, slug = startShow.Slug }, show)); }
private Task Put(string place, string presenter, string show, string index, HttpContext context) { var apiKey = context.Request.Headers["API-Key"]; if (!_apiKeyProvider.CheckBase64(presenter, apiKey)) { _logger.LogWarning(EventIds.PresenterInvalidApiKey, "Invalid API key."); context.Response.StatusCode = 403; return(Task.CompletedTask); } return(_putPolicy.ExecuteAsync(async() => { var directory = await GetDirectory(place, presenter, show, true); var blob = directory.GetBlockBlobReference($"{index}.jpg"); blob.Properties.ContentType = context.Request.ContentType; await blob.UploadFromStreamAsync(context.Request.Body); await blob.SetPropertiesAsync(); context.Response.StatusCode = 201; })); }