예제 #1
0
        internal async Task <string> GetTokenAsyncInternal(DateTime startTime, TimeSpan ttl)
        {
            string audience = this.moduleId
                              .Map(m => SasTokenHelper.BuildAudience(this.iotHubHostName, this.deviceId, m))
                              .GetOrElse(() => SasTokenHelper.BuildAudience(this.iotHubHostName, this.deviceId));
            string expiresOn = SasTokenHelper.BuildExpiresOn(startTime, ttl);
            string data      = string.Join(
                "\n",
                new List <string>
            {
                audience,
                expiresOn
            });

            try
            {
                string signature = await this.signatureProvider.SignAsync(data);

                return(SasTokenHelper.BuildSasToken(audience, signature, expiresOn));
            }
            catch (SignatureProviderException e)
            {
                throw new TokenProviderException(e);
            }
        }
예제 #2
0
        public async Task<string> GetTokenAsync(Option<TimeSpan> ttl)
        {
            DateTime startTime = DateTime.UtcNow;
            string audience = SasTokenHelper.BuildAudience(this.iotHubHostName, this.deviceId, this.moduleId);
            string expiresOn = SasTokenHelper.BuildExpiresOn(startTime, ttl.GetOrElse(this.defaultTtl));
            string data = string.Join("\n", new List<string> { audience, expiresOn });
            string signature = await this.signatureProvider.SignAsync(data).ConfigureAwait(false);

            return SasTokenHelper.BuildSasToken(audience, signature, expiresOn);
        }