示例#1
0
        public SsoLogic(HttpClient client, EsiConfig config)
        {
            _client = client;
            _config = config;

            clientKey = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{config.ClientId}:{config.SecretKey}"));
        }
示例#2
0
        public SsoLogic(HttpClient client, EsiConfig config)
        {
            _client = client;
            _config = config;
            switch (_config.DataSource)
            {
            case DataSource.Tranquility:
                _ssoUrl = "https://login.eveonline.com" +
                          "";
                break;

            case DataSource.Singularity:
                _ssoUrl = "https://sisilogin.testeveonline.com";
                break;

            case DataSource.Serenity:
                _ssoUrl = "https://login.evepc.163.com";
                break;
            }
            _clientKey = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{config.ClientId}:{config.SecretKey}"));

            //Check that Auth version matches an implemented version, new versions must be added here and in each of the functions below.
            if (!(_config.AuthVersion == AuthVersion.v1 || _config.AuthVersion == AuthVersion.v2))
            {
                throw new NotImplementedException($"Supplied auth version has not been implemented in {nameof(SsoLogic)}.");
            }
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="config"></param>
        public EsiClient(IOptions <EsiConfig> _config)
        {
            config = _config.Value;
            client = new HttpClient(new HttpClientHandler
            {
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            });

            // Enforce user agent value
            if (string.IsNullOrEmpty(config.UserAgent))
            {
                throw new ArgumentException("For your protection, please provide an X-User-Agent value. This can be your character name and/or project name. CCP will be more likely to contact you rather than just cut off access to ESI if you provide something that can identify you within the New Eden galaxy.");
            }
            else
            {
                client.DefaultRequestHeaders.Add("X-User-Agent", config.UserAgent);
            }

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
            client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate"));

            SSO                  = new SsoLogic(client, config);
            Alliance             = new AllianceLogic(client, config);
            Assets               = new AssetsLogic(client, config);
            Bookmarks            = new BookmarksLogic(client, config);
            Calendar             = new CalendarLogic(client, config);
            Character            = new CharacterLogic(client, config);
            Clones               = new ClonesLogic(client, config);
            Contacts             = new ContactsLogic(client, config);
            Contracts            = new ContractsLogic(client, config);
            Corporation          = new CorporationLogic(client, config);
            Dogma                = new DogmaLogic(client, config);
            FactionWarfare       = new FactionWarfareLogic(client, config);
            Fittings             = new FittingsLogic(client, config);
            Fleets               = new FleetsLogic(client, config);
            Incursions           = new IncursionsLogic(client, config);
            Industry             = new IndustryLogic(client, config);
            Insurance            = new InsuranceLogic(client, config);
            Killmails            = new KillmailsLogic(client, config);
            Location             = new LocationLogic(client, config);
            Loyalty              = new LoyaltyLogic(client, config);
            Mail                 = new MailLogic(client, config);
            Market               = new MarketLogic(client, config);
            Opportunities        = new OpportunitiesLogic(client, config);
            PlanetaryInteraction = new PlanetaryInteractionLogic(client, config);
            Routes               = new RoutesLogic(client, config);
            Search               = new SearchLogic(client, config);
            Skills               = new SkillsLogic(client, config);
            Sovereignty          = new SovereigntyLogic(client, config);
            Status               = new StatusLogic(client, config);
            Universe             = new UniverseLogic(client, config);
            UserInterface        = new UserInterfaceLogic(client, config);
            Wallet               = new WalletLogic(client, config);
            Wars                 = new WarsLogic(client, config);
        }
示例#4
0
        public SsoLogic(HttpClient client, EsiConfig config)
        {
            _client = client;
            _config = config;
            switch (_config.DataSource)
            {
            case DataSource.Tranquility:
                _ssoUrl = "login.eveonline.com";
                break;

            case DataSource.Serenity:
                _ssoUrl = "login.evepc.163.com";
                break;
            }
            _clientKey = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{config.ClientId}:{config.SecretKey}"));
        }
示例#5
0
        public static async Task <EsiResponse <T> > Execute <T>(HttpClient client, EsiConfig config, RequestSecurity security, RequestMethod method, string endpoint, Dictionary <string, string> replacements = null, string[] parameters = null, object body = null, string token = null)
        {
            client.DefaultRequestHeaders.Clear();

            var path    = $"{method.ToString()}|{endpoint}";
            var version = EndpointVersion[path];

            if (replacements != null)
            {
                foreach (var property in replacements)
                {
                    endpoint = endpoint.Replace($"{{{property.Key}}}", property.Value);
                }
            }

            var url = $"{config.EsiUrl}{version}{endpoint}?datasource={config.DataSource.ToEsiValue()}";

            //Attach token to request header if this endpoint requires an authorized character
            if (security == RequestSecurity.Authenticated)
            {
                if (token == null)
                {
                    throw new ArgumentException("The request endpoint requires SSO authentication and a Token has not been provided.");
                }

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            }

            if (ETag != null)
            {
                client.DefaultRequestHeaders.Add("If-None-Match", $"\"{ETag}\"");
                ETag = null;
            }

            //Attach query string parameters
            if (parameters != null)
            {
                url += $"&{string.Join("&", parameters)}";
            }

            //Serialize post body data
            HttpContent postBody = null;

            if (body != null)
            {
                postBody = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
            }

            //Get response from client based on request type
            //This is also where body variables will be created and attached as necessary
            HttpResponseMessage response = null;

            switch (method)
            {
            case RequestMethod.Delete:
                response = await client.DeleteAsync(url).ConfigureAwait(false);

                break;

            case RequestMethod.Get:
                response = await client.GetAsync(url).ConfigureAwait(false);

                break;

            case RequestMethod.Post:
                response = await client.PostAsync(url, postBody).ConfigureAwait(false);

                break;

            case RequestMethod.Put:
                response = await client.PutAsync(url, postBody).ConfigureAwait(false);

                break;
            }

            //Output final object
            var obj = new EsiResponse <T>(response, path, version);

            return(obj);
        }