Esempio n. 1
0
        protected internal ApplicationRegistration.Application AddApiKey(ApplicationRegistrationRepository repo, ApplicationRegistration.Application app, out ApplicationRegistration.ApiKey key)
        {
            ApiKeyInfo keyInfo = GenerateApiKeyInfo(app);

            key           = ApplicationRegistration.ApiKey.FromKeyInfo(keyInfo);
            key.Created   = DateTime.UtcNow;
            key.CreatedBy = CurrentUser.UserName;
            app.ApiKeys.Add(key);
            app = repo.Save(app);
            return(app);
        }
Esempio n. 2
0
        public ApiKeyInfo GetApiKeyInfo(IApplicationNameProvider nameProvider)
        {
            string     clientId = GetApplicationClientId(nameProvider);
            ApiKeyInfo info     = new ApiKeyInfo()
            {
                ApiKey = GetApplicationApiKey(clientId, GetActiveApiKeyIndex(nameProvider)),
                ApplicationClientId = clientId
            };

            return(info);
        }
Esempio n. 3
0
        public void GetCharacters()
        {
            var apiKeyInfo = new ApiKeyInfo()
            {
                KeyId = 2979031,
                VCode = "jb25Tppy5VgfEE3SR8ghVSNz33TfLNWmE2o3Jhcn8I2hJM34bm4buizVS80CAFwf"
            };

            var info = new GeneralRepo().GetCharacters(apiKeyInfo);

            Assert.IsNotNull(info.result);
        }
Esempio n. 4
0
        private static ApiKeyInfo ParseApiKeyInfoXml(XElement result)
        {
            DateTimeOffset expiry                = default(DateTimeOffset);
            int            accessMask            = 0;
            var            type                  = ApiKeyType.Invalid;
            ApiKeyInfo     keyInfo               = null;
            IEnumerable <AccountCharacter> chars = new AccountCharacter[0];

            // get the key element in the result
            XElement keyElement = result.Element(ApiConstants.Key);

            if (keyElement != null)
            {
                // get details from the attributes
                foreach (XAttribute attribute in keyElement.Attributes())
                {
                    switch (attribute.Name.LocalName)
                    {
                    case "accessMask":
                        int.TryParse(attribute.Value, out accessMask);
                        break;

                    case "type":
                        Enum.TryParse(attribute.Value, out type);
                        break;

                    case "expires":
                        DateTime temp;
                        expiry = DateTime.TryParse(attribute.Value, out temp)
                                ? new DateTimeOffset(temp, TimeSpan.Zero)
                                : default(DateTimeOffset);
                        break;
                    }
                }

                // get the character rowset that might be present in the result
                XElement characterSet = keyElement.Element(ApiConstants.Rowset);
                if (characterSet != null)
                {
                    chars = GetCharactersFromRowSet(characterSet);
                }

                keyInfo = new ApiKeyInfo {
                    AccessMask = accessMask, ApiType = type, Expires = expiry, Characters = chars
                };
            }

            return(keyInfo);
        }
Esempio n. 5
0
        public static string GetSign(IDictionary <string, string> pars, ApiKeyInfo apiKeyInfo)
        {
            StringBuilder sb = new StringBuilder();

            foreach (var item in pars.OrderBy(x => x.Key))
            {
                sb.Append(item.Key);
                sb.Append("=");
                sb.Append(item.Value);
                sb.Append("&");
            }
            var results = sb.ToString().TrimEnd('&');

            results = results + apiKeyInfo.Secret;
            return("&sign=" + Utils.ToMD5(results).ToLower());
        }
Esempio n. 6
0
        public static string GetSign(string url, ApiKeyInfo apiKeyInfo)
        {
            string        result;
            string        str  = url.Substring(url.IndexOf("?", 4) + 1);
            List <string> list = str.Split('&').ToList();

            list.Sort();
            StringBuilder stringBuilder = new StringBuilder();

            foreach (string str1 in list)
            {
                stringBuilder.Append((stringBuilder.Length > 0 ? "&" : string.Empty));
                stringBuilder.Append(str1);
            }
            stringBuilder.Append(apiKeyInfo.Secret);
            result = Utils.ToMD5(stringBuilder.ToString()).ToLower();
            return("&sign=" + result);
        }
Esempio n. 7
0
        public void TestDeleteKey()
        {
            var client      = new DefaultOneNETClient(url, appkey, "");
            var permissions = new List <Permission>
            {
                new Permission
                {
                    Access_Methods = new[]
                    {
                        HttpRequestMethod.Get.GetMethodString(),
                HttpRequestMethod.Delete.GetMethodString()
                    },
                    Resources = new List <KeyResource>
                    {
                        new KeyResource {
                            Dev_Id = "768672"
                        }
                    }
                }
            };
            var data = new ApiKeyInfo
            {
                Title       = "test delete key",
                Permissions = permissions
            };
            var req = new NewKeyRequest {
                KeyInfo = data
            };

            var rsp = client.Execute(req);

            Console.WriteLine("key to delete has added:   " + rsp.Body);
            Assert.IsFalse(rsp.IsError);
            Assert.IsNotNull(rsp.Data);
            Assert.IsNotNull(rsp.Data.Key);

            var c1   = new DefaultOneNETClient(url, appkey, "");
            var req1 = new DeleteKeyRequest {
                KeyString = rsp.Data.Key
            };
            var rsp1 = c1.Execute(req1);

            Assert.IsFalse(rsp1.IsError);
        }
Esempio n. 8
0
 public ApiKeyInfo GetApiKeyInfo(IApplicationNameProvider nameProvider)
 {
     if (_apiKeyInfo == null)
     {
         if (File.Exists(ApiKeyFilePath))
         {
             _apiKeyInfo = ApiKeyFilePath.FromJsonFile <ApiKeyInfo>();
         }
         else
         {
             FireEvent(ApiKeyFileNotFound);
             _apiKeyInfo = ApplicationRegistryService.GetClientApiKeyInfo();
             _apiKeyInfo.ApplicationName = nameProvider.GetApplicationName();
             EnsureApiKeyFileDirectory();
             _apiKeyInfo.ToJsonFile(ApiKeyFilePath);
         }
     }
     return(_apiKeyInfo);
 }
Esempio n. 9
0
        public static Ticket ForApiKey(string apikey)
        {
            if (apikey == null)
            {
                throw new ArgumentNullException(apikey);
            }

            ApiKeyInfo inf;

            lock (apikeys_lock) {
                if (!apikeys.TryGetValue(apikey, out inf))
                {
                    apikeys [apikey] = inf = new ApiKeyInfo();
                }
            }

            lock (inf) {
                if (inf.tkt == null || inf.tkt.Expires < DateTime.UtcNow.AddSeconds(60))
                {
                    string[] parts    = apikey.Split('-');
                    JObject  loginRes = Requester.SyncJsonRequest("User.login~1", null, new JObject {
                        { "type", "apikey" }, { "keystring", parts [0] }, { "secret", parts [1] }
                    });
                    Ticket authn = Verify(loginRes ["session"].AsString(null));
                    if (authn == null)
                    {
                        throw new RPCException("internal", "Invalid session ticket returned from user.login");
                    }

                    JObject authzRes = Requester.SyncJsonRequest("Auth.authorize~1", null, new JObject {
                        { "ticket", authn.String }
                    });
                    Ticket authz = Verify(authzRes ["ticket"].AsString(null));
                    if (authz == null)
                    {
                        throw new RPCException("internal", "Invalid session ticket returned from auth.authorize");
                    }
                    inf.tkt = authz;
                }
                return(inf.tkt);
            }
        }
Esempio n. 10
0
        public void TestAddKey()
        {
            var client      = new DefaultOneNETClient(url, appkey, "");
            var permissions = new List <Permission>
            {
                new Permission
                {
                    Access_Methods = new[]
                    {
                        HttpRequestMethod.Get.GetMethodString(),
                HttpRequestMethod.Post.GetMethodString()
                    },
                    Resources = new List <KeyResource>
                    {
                        new KeyResource {
                            Dev_Id = "776938"
                        },
                        new KeyResource {
                            Dev_Id = "776941"
                        }
                    }
                }
            };
            var data = new ApiKeyInfo
            {
                Title       = "test key from C#",
                Permissions = permissions
            };
            var req = new NewKeyRequest {
                KeyInfo = data
            };

            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
            Console.WriteLine(rsp.Body);
            Assert.IsNotNull(rsp.Data);
            Assert.IsNotNull(rsp.Data.Key);
        }
Esempio n. 11
0
        public void TestUpdateKey()
        {
            var client      = new DefaultOneNETClient(url, appkey, "");
            var permissions = new List <Permission>
            {
                new Permission
                {
                    Access_Methods = new[]
                    {
                        HttpRequestMethod.Get.GetMethodString(),
                HttpRequestMethod.Post.GetMethodString(),
                HttpRequestMethod.Put.GetMethodString()
                    },
                    Resources = new List <KeyResource>
                    {
                        new KeyResource {
                            Dev_Id = "776938"
                        },
                        new KeyResource {
                            Dev_Id = "776941"
                        }
                    }
                }
            };
            var data = new ApiKeyInfo
            {
                Title       = "test update key from C#",
                Permissions = permissions
            };
            var req = new UpdateKeyRequest {
                KeyString = "jb3idOcNvc3Tv=WtoBLBLPYgVyg=", KeyInfo = data
            };
            var rsp = client.Execute(req);

            Assert.IsFalse(rsp.IsError);
        }
Esempio n. 12
0
        public string CreateKeyToken(string stringToHash)
        {
            ApiKeyInfo apiKey = GetApiKeyInfo(this);

            return($"{apiKey.ApiKey}:{stringToHash}".Hash(HashAlgorithm));
        }
Esempio n. 13
0
        public string GetCurrentApiKey()
        {
            ApiKeyInfo key = GetApiKeyInfo(this);

            return(key.ApiKey);
        }
Esempio n. 14
0
 public Account(int keyID, string vCode)
 {
     KeyID      = keyID;
     VCode      = vCode;
     ApiKeyInfo = new ApiKeyInfo(keyID, vCode);
 }
        public eveapi GetCharacters(ApiKeyInfo apiKeyInfo)
        {
            var url = "https://api.eveonline.com/account/Characters.xml.aspx";

            return(Post(url, apiKeyInfo.ToDictionary()).Data);
        }
Esempio n. 16
0
 /// <summary>
 /// api key更新请求
 /// </summary>
 public UpdateKeyRequest()
 {
     KeyInfo         = new ApiKeyInfo();
     otherParameters = new Dictionary <string, string>();
 }