public GoogleSigned(string clientId, string usablePrivateKey)
 {
     usablePrivateKey = usablePrivateKey.Replace("-", "+").Replace("_", "/");
     _privateKeyBytes = Convert.FromBase64String(usablePrivateKey);
     _clientId = clientId;
     _signType = GoogleSignedType.Business;
 }
 public GoogleSigned(string clientId, string usablePrivateKey)
 {
     usablePrivateKey = usablePrivateKey.Replace("-", "+").Replace("_", "/");
     _privateKeyBytes = Convert.FromBase64String(usablePrivateKey);
     _clientId        = clientId;
     _signType        = GoogleSignedType.Business;
 }
Example #3
0
        /// <summary>
        /// Parses the value from the AppSettings[key] and generates the proper GoogleSigned instance from it.
        /// </summary>
        /// <remarks>
        /// apikey=YOUR_KEY[&secret=SHARED_SECRET]
        /// clientId=gme-YOUR_CLIENT_ID&secret=SHARED_SECRET
        /// </remarks>
        /// <param name="appSettings"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static GoogleSigned FromValueString(string value)
        {
            if (value == null)
            {
                value = "";
            }

            string[] check = new string[2] {
                "", ""
            };
            var split = value.Split('&');

            if (split.Length > 0)
            {
                check[0] = split[0] ?? "";
            }
            if (split.Length > 1)
            {
                check[1] = split[1] ?? "";
            }

            GoogleSignedType signedType = (GoogleSignedType)0;
            string           idString   = null;

            if (check[0].StartsWith("apikey", StringComparison.OrdinalIgnoreCase))
            {
                signedType = GoogleSignedType.ApiKey;
                idString   = check[0].Substring(7);
            }
            else if (check[0].StartsWith("clientId", StringComparison.OrdinalIgnoreCase))
            {
                signedType = GoogleSignedType.Business;
                idString   = check[0].Substring(9);
            }

            string usablePrivateKey = null;

            if (check[1].StartsWith("secret", StringComparison.OrdinalIgnoreCase))
            {
                usablePrivateKey = check[1].Substring(7);
            }

            if (String.IsNullOrEmpty(idString) == false)
            {
                return(new GoogleSigned(idString, usablePrivateKey, signedType));
            }

            throw
                new ArgumentException(
                    string.Format("Failed to determine Google Signing Info from '{0}'.", value),
                    nameof(value)
                    );
        }
Example #4
0
        public GoogleSigned(string apiKey, string usablePrivateKey = null, GoogleSignedType signType = GoogleSignedType.ApiKey)
        {
            if (usablePrivateKey != null)
            {
                //might come encoded as Base64 for Urls.
                //Use normal conventions for Convert.FromBase64String
                usablePrivateKey = usablePrivateKey.Replace("-", "+").Replace("_", "/");

                _privateKeyBytes = Convert.FromBase64String(usablePrivateKey);
            }

            _idString = apiKey;
            _signType = signType;
        }
 public GoogleSigned(string apiKey)
 {
     _apiKey = apiKey;
     _signType = GoogleSignedType.ApiKey;
 }
 public GoogleSigned(string apiKey)
 {
     _apiKey   = apiKey;
     _signType = GoogleSignedType.ApiKey;
 }