An abstract base class for requests that can be authenticated via URL signing.
See https://developers.google.com/maps/documentation/business/webservices for details about signing.
Inheritance: GoogleApi.Entities.Maps.Common.MapsBaseRequest
Exemplo n.º 1
0
        /// <summary>
        /// Signs the request using premium subscription.
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        protected virtual Uri Sign(Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }

            if (string.IsNullOrWhiteSpace(this.Key))
            {
                throw new ArgumentException("Invalid signing key.");
            }

            if (this.ClientId == null)
            {
                throw new NullReferenceException("ClientID");
            }

            if (!this.ClientId.StartsWith("gme-"))
            {
                throw new ArgumentException("A clientId must start with 'gme-'.");
            }

            var urlSegmentToSign = uri.LocalPath + uri.Query + "&client=" + this.ClientId;
            var privateKey       = SignableRequest.FromBase64UrlString(this.Key);

            byte[] signature;

            using (var algorithm = new HMACSHA1(privateKey))
            {
                signature = algorithm.ComputeHash(Encoding.ASCII.GetBytes(urlSegmentToSign));
            }

            return(new Uri(uri.Scheme + "://" + uri.Host + urlSegmentToSign + "&signature=" + SignableRequest.ToBase64UrlString(signature)));
        }
Exemplo n.º 2
0
        internal Uri Sign(Uri _uri)
        {
            // Based on the C# sample from: https://developers.google.com/maps/documentation/business/webservices

            if (_uri == null)
            {
                throw new ArgumentNullException("_uri");
            }

            if (this.ClientId == null)
            {
                throw new NullReferenceException("ClientID");
            }

            if (string.IsNullOrWhiteSpace(this.SigningKey))
            {
                throw new ArgumentException("Invalid signing key.");
            }

            if (!this.ClientId.StartsWith("gme-"))
            {
                throw new ArgumentException("A user ID must start with 'gme-'.");
            }

            var _urlSegmentToSign = _uri.LocalPath + _uri.Query + "&client=" + this.ClientId;
            var _privateKey       = SignableRequest.FromBase64UrlString(SigningKey);

            byte[] _signature;

            using (var _algorithm = new HMACSHA1(_privateKey))
            {
                _signature = _algorithm.ComputeHash(Encoding.ASCII.GetBytes(_urlSegmentToSign));
            }

            return(new Uri(_uri.Scheme + "://" + _uri.Host + _urlSegmentToSign + "&signature=" + SignableRequest.ToBase64UrlString(_signature)));
        }