public async Task <IActionResult> GetByKeyAndGroup(string keyGroup, string keyId, string token) { if (string.IsNullOrEmpty(keyGroup) || string.IsNullOrEmpty(keyId) || string.IsNullOrEmpty(token)) { return(new BadRequestObjectResult("Missing parameters")); } if (!_streamingTokenHelper.ValidateToken(token)) { return(new UnauthorizedResult()); } var keyBytes = await _keyRepository.GetKeyAsync(keyGroup, keyId); var stream = new MemoryStream(keyBytes); return(new FileStreamResult(stream, "binary/octet-stream")); }
public async Task <IActionResult> GetTopLevelManifest(string token, string url, bool audio_only = false, string language = null) { if (string.IsNullOrEmpty(token)) { return(BadRequest("Missing parameters")); } if (string.IsNullOrEmpty(url)) { if (_streamingTokenHelper.ValidateToken(token)) { url = _urlSigner.Sign(_liveOptions.HlsUrl2); } else { return(BadRequest("Missing parameters")); } } Uri uri; if (!Uri.TryCreate(url, UriKind.Absolute, out uri)) { return(BadRequest("Bad uri: " + url)); } var allowedHosts = _liveOptions.GetAllowedHosts().Split(","); if (!allowedHosts.Contains(uri.Host.ToLower())) { return(BadRequest("Host not allowed: " + uri.Host)); } var secondLevelProxyUrl = Url.Action("GetSecondLevelManifest", null, null, Request.Scheme); var manifest = await _proxyService.RetrieveAndModifyTopLevelManifest(url, secondLevelProxyUrl); if (audio_only) { manifest = _proxyService.ModifyManifestToBeAudioOnly(manifest, language); } Response.Headers.Add("X-Content-Type-Options", "nosniff"); Response.GetTypedHeaders().CacheControl = new CacheControlHeaderValue { NoStore = true, MaxAge = TimeSpan.FromSeconds(0) }; return(Content(manifest, "application/vnd.apple.mpegurl", Encoding.UTF8)); }