public void SetCharacterData(AuthorizedCharacterData data) { Assets = new AssetsLogic(client, config, data); Bookmarks = new BookmarksLogic(client, config, data); Calendar = new CalendarLogic(client, config, data); Character = new CharacterLogic(client, config, data); Clones = new ClonesLogic(client, config, data); Contacts = new ContactsLogic(client, config, data); Contracts = new ContractsLogic(client, config, data); Corporation = new CorporationLogic(client, config, data); FactionWarfare = new FactionWarfareLogic(client, config, data); Fittings = new FittingsLogic(client, config, data); Fleets = new FleetsLogic(client, config, data); Industry = new IndustryLogic(client, config, data); Killmails = new KillmailsLogic(client, config, data); Location = new LocationLogic(client, config, data); Loyalty = new LoyaltyLogic(client, config, data); Mail = new MailLogic(client, config, data); Market = new MarketLogic(client, config, data); Opportunities = new OpportunitiesLogic(client, config, data); PlanetaryInteraction = new PlanetaryInteractionLogic(client, config, data); Search = new SearchLogic(client, config, data); Skills = new SkillsLogic(client, config, data); UserInterface = new UserInterfaceLogic(client, config, data); Wallet = new WalletLogic(client, config, data); Universe = new UniverseLogic(client, config, data); }
/// <summary> /// Invites the pilot to a fleet. If a specific squad is not specified they will be invited to the default squad. /// </summary> /// <param name="fleetBoss">Fleet Boss explicit cast as AuthorizedCharacterData</param> /// <param name="fleetId">Target fleet Id</param> /// <param name="squadId">Target squad Id</param> /// <param name="pilotId">Invitee Id</param> public static async Task <object> FleetInvite(AuthorizedCharacterData fleetBoss, long fleetId, long squadId, long wingId, int pilotId) { try { EsiClient x = GetEsiClient(); x.SetCharacterData(fleetBoss); EsiResponse <string> response = await x.Fleets.InviteCharacter(fleetId, pilotId, ESI.NET.Enumerations.FleetRole.SquadMember, wingId, squadId); if (response.StatusCode != HttpStatusCode.OK) { s_Log.LogError("{0} error search API '{1}': {2}", response.StatusCode, response.Endpoint, response.Message); Exception ex; if (response.Message.Contains("'error_label': 'FleetCandidateOffline', 'error_dict'")) { ex = new Exception("Fleet Candidate Offline"); } else { ex = new Exception(response.Message); } throw new Exception("Fleet Invite Failed", ex); } return(null); } catch (Exception ex) { //s_Log.LogError("{0} error searching API '{1}': {2}", FleetMembers_response.StatusCode, FleetMembers_response.Endpoint, FleetMembers_response.Message); //throw new Exception(FleetLayout_response.ErrorType().ToString()); throw new NotImplementedException(); } }
public CharacterLogic(HttpClient client, EsiConfig config, AuthorizedCharacterData data = null) { _client = client; _config = config; _data = data; if (data != null) character_id = data.CharacterID; }
public CorporationLogic(HttpClient client, EsiConfig config, AuthorizedCharacterData data = null) { _client = client; _config = config; _data = data; if (data != null) { corporation_id = data.CorporationID; } }
/// <summary> /// Verifies the Character information for the provided Token information. /// While this method represents the oauth/verify request, in addition to the verified data that ESI returns, this object also stores the Token and Refresh token /// and this method also uses ESI retrieves other information pertinent to making calls in the ESI.NET API. (alliance_id, corporation_id, faction_id) /// You will need a record in your database that stores at least this information. Serialize and store this object for quick retrieval and token refreshing. /// </summary> /// <param name="token"></param> /// <returns></returns> public async Task <AuthorizedCharacterData> Verify(SsoToken token) { _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken); AuthorizedCharacterData authorizedCharacter = null; if (_config.AuthVersion == AuthVersion.v1) { var response = await _client.GetAsync($"{_ssoUrl}/oauth/verify").Result.Content.ReadAsStringAsync(); authorizedCharacter = JsonConvert.DeserializeObject <AuthorizedCharacterData>(response); authorizedCharacter.Token = token.AccessToken; authorizedCharacter.RefreshToken = token.RefreshToken; } else if (_config.AuthVersion == AuthVersion.v2) { var response = await(await _client.GetAsync($"{_config.EsiUrl}verify")).Content.ReadAsStringAsync(); authorizedCharacter = JsonConvert.DeserializeObject <AuthorizedCharacterData>(response); authorizedCharacter.Token = token.AccessToken; authorizedCharacter.RefreshToken = token.RefreshToken; } else { throw new NotImplementedException($"Supplied auth version has not been implemented in {nameof(Verify)}."); } //var response = await (await _client.GetAsync($"{_config.EsiUrl}verify")).Content.ReadAsStringAsync(); //AuthorizedCharacterData authorizedCharacter = JsonConvert.DeserializeObject<AuthorizedCharacterData>(response); //authorizedCharacter.Token = token.AccessToken; //authorizedCharacter.RefreshToken = token.RefreshToken; var url = $"{_config.EsiUrl}v1/characters/affiliation/?datasource={_config.DataSource.ToEsiValue()}"; var body = new StringContent(JsonConvert.SerializeObject(new int[] { authorizedCharacter.CharacterID }), Encoding.UTF8, "application/json"); // Get more specifc details about authorized character to be used in API calls that require this data about the character var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken); var characterResponse = await client.PostAsync(url, body).ConfigureAwait(false); //var characterResponse = new CharacterLogic(_client, _config, authorizedCharacter).Affiliation(new int[] { authorizedCharacter.CharacterID }).ConfigureAwait(false).GetAwaiter().GetResult(); if (characterResponse.StatusCode == System.Net.HttpStatusCode.OK) { EsiResponse <List <Affiliation> > affiliations = new EsiResponse <List <Affiliation> >(characterResponse, "Post|/character/affiliations/", "v1"); var characterData = affiliations.Data.First(); authorizedCharacter.AllianceID = characterData.AllianceId; authorizedCharacter.CorporationID = characterData.CorporationId; authorizedCharacter.FactionID = characterData.FactionId; } return(authorizedCharacter); }
public static async Task UpdateTokenAsync(string refreshToken, ApplicationUser applicationUser, IEsiClient esiClient) { SsoToken ssoToken = await esiClient.SSO.GetToken(GrantType.RefreshToken, refreshToken); AuthorizedCharacterData authorizedCharacterData = new AuthorizedCharacterData() { RefreshToken = refreshToken, Token = ssoToken.AccessToken, TokenType = ssoToken.TokenType, CorporationID = 98342486, ExpiresOn = DateTime.Now.AddSeconds(ssoToken.ExpiresIn), CharacterID = applicationUser.CharID, CharacterName = applicationUser.UserName }; esiClient.SetCharacterData(authorizedCharacterData); }
public ContactsLogic(HttpClient client, EsiConfig config, AuthorizedCharacterData data = null) { _client = client; _config = config; _data = data; if (_data != null) { character_id = _data.CharacterID; corporation_id = _data.CorporationID; alliance_id = _data.CorporationID; } }
/// <summary> /// Opens the Show Info window for a Character, Corporation or Alliance in game. /// </summary> /// <param name="pilot">Pilot explicit cast as AuthorizedCharacterData</param> /// <param name="target_id"></param> /// <see cref="Models.Pilot"/> /// <seealso cref="AuthorizedCharacterData"/> /// <seealso cref="ESI.NET.Models.Character"/> /// <seealso cref="ESI.NET.Models.Corporation"/> /// <seealso cref="ESI.NET.Models.Alliance"/> public static void ShowInfo(AuthorizedCharacterData pilot, int target_id) { try { EsiClient x = GetEsiClient(); x.SetCharacterData(pilot); x.UserInterface.Information(target_id); } catch (Exception ex) { Console.Beep(); } }
/// <summary> /// Sets a new autopilot destination in game. /// </summary> /// <param name="pilot">Pilot explicit cast as AuthorizedCharacterData</param> /// <param name="system_id">ID of the target solar system.</param> /// <see cref="ESI.NET.Models.Universe.SolarSystem"/> public static void SetDestination(AuthorizedCharacterData pilot, int system_id) { try { EsiClient x = GetEsiClient(); x.SetCharacterData(pilot); x.UserInterface.Waypoint(system_id, true, true); } catch (Exception ex) { Console.Beep(); } }
public static async Task <List <ESI.NET.Models.Fleets.Wing> > GetFleetLayout(AuthorizedCharacterData fleetBoss, long fleetId) { EsiClient x = GetEsiClient(); x.SetCharacterData(fleetBoss); EsiResponse <List <ESI.NET.Models.Fleets.Wing> > FleetLayout_response = await x.Fleets.Wings(fleetId); if (FleetLayout_response.StatusCode != HttpStatusCode.OK) { s_Log.LogError("{0} error search API '{1}': {2}", FleetLayout_response.StatusCode, FleetLayout_response.Endpoint, FleetLayout_response.Message); throw new Exception(FleetLayout_response.ErrorType().ToString()); } return(FleetLayout_response.Data); }
/// <summary> /// Checks ESI to see if the pilot is online. /// </summary> /// <param name="pilot">Pilot explicit cast as AuthorizedCharacterData</param> /// <returns>Bool</returns> public static async Task <bool> IsOnlineAsync(AuthorizedCharacterData pilot) { EsiClient x = GetEsiClient(); x.SetCharacterData(pilot); EsiResponse <ESI.NET.Models.Location.Activity> Location_response = await x.Location.Online(); if (Location_response.StatusCode != HttpStatusCode.OK) { s_Log.LogError("{0} error searching API '{1}': {2}", Location_response.StatusCode, Location_response.Endpoint, Location_response.Message); return(true); } return(Location_response.Data.Online); }
public static async Task <ESI.NET.Models.Location.Location> GetSystem(AuthorizedCharacterData pilot) { EsiClient x = GetEsiClient(); x.SetCharacterData(pilot); EsiResponse <ESI.NET.Models.Location.Location> Location_response = await x.Location.Location(); if (Location_response.StatusCode != HttpStatusCode.OK) { s_Log.LogError("{0} error searching API '{1}': {2}", Location_response.StatusCode, Location_response.Endpoint, Location_response.Message); return(null); } return(Location_response.Data); }
public async void finishAuth(string uri) { // eveauth-eveclip://callback/?code=DX58B9i1IkvZj23aoAZPXQmNR1NZi7hixM0Vm2lWXV71zl1-Dlpkd1jUgS4gl0tq0 int pos = uri.IndexOf("?code="); string code = uri.Substring(pos + 6); try { SsoToken token = await m_client.SSO.GetToken(GrantType.AuthorizationCode, code); m_authCharData = await m_client.SSO.Verify(token.Value); m_client.SetCharacterData(m_authCharData); } catch (Exception) { MessageBox.Show("Login failed. Please enter ClientID and SecretKey in Options. See https://developers.eveonline.com/ for details.", "Error logging in"); } }
public EsiData(MainForm mainform) { SecOptions o = SecOptions.getInstance(); o.readKey(); IOptions <EsiConfig> config = Options.Create(new EsiConfig() { EsiUrl = "https://esi.tech.ccp.is/", DataSource = DataSource.Tranquility, ClientId = o.m_clientId, SecretKey = o.m_secretKey, CallbackUrl = "eveauth-eveclip://callback/", UserAgent = "Name: Che Silas" }); m_client = new EsiClient(config); m_authCharData = null; m_mainForm = mainform; InitAuth(); }
/// <summary> /// Verifies the Character information for the provided Token information. /// While this method represents the oauth/verify request, in addition to the verified data that ESI returns, this object also stores the Token and Refresh token /// and this method also uses ESI retrieves other information pertinent to making calls in the ESI.NET API. (alliance_id, corporation_id, faction_id) /// You will need a record in your database that stores at least this information. Serialize and store this object for quick retrieval and token refreshing. /// </summary> /// <param name="token"></param> /// <returns></returns> public async Task <AuthorizedCharacterData> Verify(SsoToken token) { AuthorizedCharacterData authorizedCharacter = new AuthorizedCharacterData(); try { var tokenHandler = new JwtSecurityTokenHandler(); // Get the eve online JWT to validate against var jwtksUrl = $"https://{_ssoUrl}/oauth/jwks"; var response = await _client.GetAsync(jwtksUrl).Result.Content.ReadAsStringAsync(); var jwks = new JsonWebKeySet(response); var jwk = jwks.Keys.First(); SecurityToken validatedToken; // Validate the token TokenValidationParameters tokenValidationParams = new TokenValidationParameters { ValidateAudience = false, ValidateIssuer = true, ValidIssuer = _ssoUrl, ValidateIssuerSigningKey = true, IssuerSigningKey = jwk, ClockSkew = TimeSpan.FromSeconds(2), // CCP's servers seem slightly ahead (~1s) }; tokenHandler.ValidateToken(token.AccessToken, tokenValidationParams, out validatedToken); JwtSecurityToken jwtValidatedToken = validatedToken as JwtSecurityToken; var subjectClaim = jwtValidatedToken.Claims.SingleOrDefault(c => c.Type == "sub").Value; var nameClaim = jwtValidatedToken.Claims.SingleOrDefault(c => c.Type == "name").Value; var ownerClaim = jwtValidatedToken.Claims.SingleOrDefault(c => c.Type == "owner").Value; var returnedScopes = jwtValidatedToken.Claims.Where(c => c.Type == "scp"); var scopesClaim = string.Join(" ", returnedScopes.Select(s => s.Value)); authorizedCharacter.RefreshToken = token.RefreshToken; authorizedCharacter.Token = token.AccessToken; authorizedCharacter.CharacterName = nameClaim; authorizedCharacter.CharacterOwnerHash = ownerClaim; authorizedCharacter.CharacterID = int.Parse(subjectClaim.Split(':').Last()); authorizedCharacter.ExpiresOn = jwtValidatedToken.ValidTo; authorizedCharacter.Scopes = scopesClaim; // Get more specifc details about authorized character to be used in API calls that require this data about the character var url = $"{_config.EsiUrl}latest/characters/affiliation/?datasource={_config.DataSource.ToEsiValue()}"; var body = new StringContent(JsonConvert.SerializeObject(new int[] { authorizedCharacter.CharacterID }), Encoding.UTF8, "application/json"); var client = new HttpClient(); var characterResponse = await client.PostAsync(url, body).ConfigureAwait(false); if (characterResponse.StatusCode == HttpStatusCode.OK) { EsiResponse <List <Affiliation> > affiliations = new EsiResponse <List <Affiliation> >(characterResponse, "Post|/character/affiliations/"); var characterData = affiliations.Data.First(); authorizedCharacter.AllianceID = characterData.AllianceId; authorizedCharacter.CorporationID = characterData.CorporationId; authorizedCharacter.FactionID = characterData.FactionId; } } catch { // validation failed } return(authorizedCharacter); }
public UserInterfaceLogic(HttpClient client, EsiConfig config, AuthorizedCharacterData data = null) { _client = client; _config = config; _data = data; }
public async Task <AuthorizedCharacterData> Verify() { AuthorizedCharacterData result = await _client.SSO.Verify(token); return(result); }
public async Task <IActionResult> Callback(string code, string state) { // Verify a code and state query parameter was returned. if (code == null || state == null) { _Logger.LogWarning("Eve Callback Error: One or more of the query parameters are missing. State: {0}. Code: {1}", state, code); return(StatusCode(452)); } // Verify the state to protect against CSRF attacks. if (HttpContext.Session.GetString("state") != state) { _Logger.LogWarning("Eve Callback Error: Invalid state returned."); HttpContext.Session.Remove("state"); return(StatusCode(452)); } // Clear the state session HttpContext.Session.Remove("state"); ESI.NET.EsiClient s_client = EsiWrapper.GetEsiClient(); SsoToken token = await s_client.SSO.GetToken(GrantType.AuthorizationCode, code); AuthorizedCharacterData n_pilot = await s_client.SSO.Verify(token); long corporation_id = (long)n_pilot.CorporationID; Corporation.EnsureInDatabase(corporation_id, _Db); var pilot = await _Db.Pilots.FindAsync(n_pilot.CharacterID); if (pilot == null) { // User doesn't exist, create a new account pilot = new Pilot() { CharacterID = n_pilot.CharacterID, AccountId = User.AccountId(), CharacterName = n_pilot.CharacterName, CorporationID = corporation_id, RefreshToken = n_pilot.RefreshToken, Token = n_pilot.Token, UpdatedAt = DateTime.UtcNow, RegisteredAt = DateTime.UtcNow, }; await _Db.AddAsync(pilot); await _Db.SaveChangesAsync(); _Logger.LogDebug("{0} has linked the pilot {1} to their account.", User.FindFirst("name").Value, pilot.CharacterName); //TODO: alert user that it worked return(Redirect("/pilot-select")); } else if (!pilot.IsLinked() || pilot.BelongsToAccount(int.Parse(User.FindFirst("id").Value))) { // Update the pilot information - This may include a new account if it was unlinked. pilot.AccountId = User.AccountId(); pilot.CharacterName = n_pilot.CharacterName; pilot.CorporationID = corporation_id; pilot.RefreshToken = n_pilot.RefreshToken; pilot.Token = n_pilot.Token; pilot.UpdatedAt = DateTime.UtcNow; await _Db.SaveChangesAsync(); _Logger.LogDebug("{0} has updated the pilot {1} that is linked to their account.", User.FindFirst("name").Value, pilot.CharacterName); //TODO: alert user that it worked return(Redirect("/pilot-select")); } //TODO: alert user that it failed _Logger.LogDebug("{0} has tried to link {1} to their account, however it is linked to someone else’s account.", User.AccountName(), pilot.CharacterName); return(Redirect("/pilot-select")); }
public static async Task <List <ESI.NET.Models.Fleets.Member> > GetFleetMembers(AuthorizedCharacterData pilot, long fleet_id) { EsiClient esi = GetEsiClient(); esi.SetCharacterData(pilot); EsiResponse <System.Collections.Generic.List <ESI.NET.Models.Fleets.Member> > FleetMembers_response = await esi.Fleets.Members(fleet_id); if (FleetMembers_response.StatusCode != HttpStatusCode.OK) { s_Log.LogError("{0} error searching API '{1}': {2}", FleetMembers_response.StatusCode, FleetMembers_response.Endpoint, FleetMembers_response.Message); throw new Exception(FleetMembers_response.ErrorType().ToString()); } return(FleetMembers_response.Data); }