Пример #1
0
        public IActionResult Get()
        {
            Console.WriteLine();
            Console.WriteLine($"AccessKey = {_endpointInfo.AccessKey}");
            Console.WriteLine();

            var validUntilUtc = DateTime.UtcNow + _endpointInfo.Ttl;

            var authorization = SharedAccessSignatureTokenProviderEx.GetSharedAccessSignature(
                _endpointInfo.KeyName,
                _endpointInfo.AccessKey,
                _endpointInfo.Resource,
                _endpointInfo.Ttl);

            var result = new AnalyticsEndpointInfoResponseModel()
            {
                HttpVerb      = "POST",
                Url           = _endpointInfo.Resource,
                ContentType   = "application/json",
                Authorization = authorization,
                ValidUntilUtc = validUntilUtc
            };

            return(Ok(result));
        }
Пример #2
0
        public void ShouldBeAbleToGetSharedAccessSignature()
        {
            // Arrange
            var servicebusNamespace = "myservicebusnamespace";
            var eventhubName        = "eventhubname";
            var keyName             = "nether";
            var sharedAccessKey     = "w8UXwPyDp6a0oxbeUyFoy6HEUOzJ0cYnVjt7muyzps4=";
            var resource            = $"https://{servicebusNamespace}.servicebus.windows.net/{eventhubName}/messages";
            var tokenTimeToLive     = TimeSpan.FromDays(365);

            // Act
            var sasToken = SharedAccessSignatureTokenProviderEx.GetSharedAccessSignature(keyName, sharedAccessKey, resource, tokenTimeToLive);

            // Assert

            // Signature will come out differently every time, hence the need to use RegEx to validate the token and not a fixed string
            Assert.Matches($"SharedAccessSignature sr=https%3A%2F%2F{servicebusNamespace}.servicebus.windows.net%2F{eventhubName}%2Fmessages&sig=.*&se=.*&skn={keyName}",
                           sasToken);
        }