Example #1
0
        public ActionResult <UrlDto> GetHls()
        {
            var expiryTime = DateTimeOffset.UtcNow.AddHours(6);
            var token      = _streamingTokenHelper.Generate(expiryTime);

            var url = _urlSigner.Sign(_liveOptions.Value.HlsUrl2);

            return(new UrlDto {
                Url = Url.Action("GetTopLevelManifest", "CmafProxy", null, Request.Scheme) + "?url=" + HttpUtility.UrlEncode(url) + "&token=" + token,
                ExpiryTime = expiryTime
            });
        }
Example #2
0
        public string GetCoverUrl(string userId, int bookId, string coverName)
        {
            var       coverPath   = $"{_baseBookPath}{userId}/{bookId}/{coverName}";
            var       initializer = new ServiceAccountCredential.Initializer(_googleCloudStorageSettings.Id);
            UrlSigner urlSgSigner = UrlSigner.FromServiceAccountCredential(
                new ServiceAccountCredential(initializer.FromPrivateKey(_googleCloudStorageSettings.PrivateKey)));
            string url = urlSgSigner.Sign(_googleCloudStorageSettings.BucketName, coverPath, TimeSpan.FromDays(5));

            return(url);
        }
Example #3
0
        public string GetDownloadUrl(string userId, int bookId, string bookFileName)
        {
            var       bookPath    = $"{_baseBookPath}{userId}/{bookId}/{bookFileName}";
            var       initializer = new ServiceAccountCredential.Initializer(_googleCloudStorageSettings.Id);
            UrlSigner urlSgSigner = UrlSigner.FromServiceAccountCredential(
                new ServiceAccountCredential(initializer.FromPrivateKey(_googleCloudStorageSettings.PrivateKey)));
            string url = urlSgSigner.Sign(_googleCloudStorageSettings.BucketName, bookPath, TimeSpan.FromMinutes(10),
                                          HttpMethod.Get);

            return(url);
        }
        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));
        }
    public string GenerateV4SignedReadUrl(
        string bucketName         = "your-unique-bucket-name",
        string objectName         = "your-object-name",
        string credentialFilePath = "my-local-path/my-credential-file-name")
    {
        UrlSigner urlSigner = UrlSigner.FromServiceAccountPath(credentialFilePath);
        // V4 is the default signing version.
        string url = urlSigner.Sign(bucketName, objectName, TimeSpan.FromHours(1), HttpMethod.Get);

        Console.WriteLine("Generated GET signed URL:");
        Console.WriteLine(url);
        Console.WriteLine("You can use this URL with any user agent, for example:");
        Console.WriteLine($"curl '{url}'");
        return(url);
    }