Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/live-esi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Live ESI

# Runs the smoke test against the live ESI API (`tests/live.rs`, ignored in
# the normal test run): one public endpoint of every group, read into the
# type the crate returns. It finds a change in what ESI sends that the OpenAPI
# spec does not show (`spec-diff.yml` covers the spec itself). It runs weekly
# and can be run by hand.
#
# ESI is a public service: if it is down or throttling, the run fails for
# that reason. The test is tried twice before the job gives up.
on:
schedule:
- cron: "47 6 * * 3"
workflow_dispatch:

permissions:
contents: read

env:
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
CARGO_TERM_COLOR: always
CARGO_HTTP_MULTIPLEXING: false
CARGO_PROFILE_DEV_DEBUG: line-tables-only

jobs:
live:
name: live
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v7
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
shared-key: live-esi
cache-on-failure: true
- name: Smoke test the public endpoints
run: |
for attempt in 1 2; do
if cargo test --test live -- --ignored --nocapture; then
exit 0
fi
echo "::warning::attempt $attempt failed"
sleep 60
done
exit 1
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,24 @@
All notable changes to this project are documented here. This project is a
fork of [rfesi](https://github.com/Celeo/rfesi) 0.50.2; versioning restarts at 0.1.0.

## [Unreleased]
## [0.3.0] - 2026-11-04

### Fixed

- `UniverseGroup::get_bloodlines` no longer fails as a whole: ESI sends `null` as the `ship_type_id` of six bloodlines although the spec requires it, so `Bloodline::ship_type_id` is now `Option<i64>` (**breaking** for code that reads it).
- Validating the SSO token now requires the `aud` claim to contain the client ID. Before, a token issued for another application was accepted, because every token lists `EVE Online` as an audience.
- Requests with a body (`POST`, `PUT`) now send `Content-Type: application/json`; before, no content type was sent.
- A client with an access token but no expiration no longer panics on an authenticated request: the token is sent and ESI decides whether it is still valid.
- Validating the SSO token no longer panics on a malformed key set or on a token without an `iss` claim; both return `EsiError::InvalidJWT`. A failing status when fetching the keys is now reported as `EsiError::InvalidStatusCode`.
- `FittingsGroup::create_character_fitting` reads the answer as the object ESI sends (`{"fitting_id": n}`); it was read as a bare number and failed on a real answer. The return type is still the `i64` ID.

### Added

- `EsiBuilder::metadata_url`: the address of the SSO metadata document that points to the token validation keys (default: the EVE SSO one), so the validated `authenticate` flow can run against a local server.

### Changed

- **Breaking:** fields that the spec does not mark as required are now `Option`: `ContainerLogEntry::password_type`, and `amount` plus `character_id` / `corporation_id` of the faction warfare leaderboard items (`CharacterLeaderboardItem`, `CorporationLeaderboardItem`). A real answer that omitted them failed to parse as a whole.

## [0.2.2] - 2026-11-01

Expand Down
8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "esi-openapi"
version = "0.2.2"
version = "0.3.0"
authors = ["Rafael <rafaga@users.noreply.github.com>", "Celeo <mattboulanger@fastmail.com>"]
edition = "2021"
description = "Rust API for EVE Online's ESI, based on the OpenAPI specification (fork of rfesi)"
Expand All @@ -19,7 +19,7 @@ jsonwebtoken = { version = "11.1", optional = true, features = ["rust_crypto"] }
futures-util = { version = "0.3", default-features = false, features = ["alloc"] }
log = "0.4"
rand = "0.10"
reqwest = { version = "0.13", default-features = false, features = ["json", "charset", "http2", "form", "query", "gzip", "brotli", "deflate"] }
reqwest = { version = "0.13", default-features = false, features = ["json", "charset", "http2", "form", "query", "gzip", "brotli", "deflate", "rustls"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha2 = "0.11"
Expand All @@ -36,8 +36,6 @@ chrono = "0.4"
uuid = { version = "1.29", features = ["v4", "fast-rng"] }

[features]
default = ["random_state", "validate_jwt", "rustls-tls"]
default = ["random_state", "validate_jwt"]
random_state = []
validate_jwt = ["dep:jsonwebtoken"]
# default-tls = ["reqwest/default-tls"]
rustls-tls = ["reqwest/rustls"]
21 changes: 21 additions & 0 deletions resources/test/keys/jwks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"keys": [
{
"kty": "EC",
"alg": "ES256",
"crv": "P-256",
"kid": "ignored",
"use": "sig",
"x": "AAAA",
"y": "AAAA"
},
{
"kty": "RSA",
"alg": "RS256",
"kid": "JWT-Signature-Key",
"use": "sig",
"n": "1WRqVbsBuwvsoRnI3JClNtmoQq1woLXZY_AkFDD0BOQBggzFsxNXJdF-mAXAAKHFEDrwG6wgg6aPsIae3L-LUEEddv9hAlJAobnNrBITnb1DCN_eNKfE4cDin-Ad7-0O25HhWKBMs1cWZx4CL9t_oEGq9XtgxHk0JF0czBEIH9W5EVPjxPnyi8AoTNncYGWw9xJzhhjU3Qk0nx05UrCnpoNDqEmj5EDZlgDc3GWuhIr8Hzdw4tZKWXEsopVN8MDZS7TpqI0QXc28l5rfbm2C0LiGhEaBMmlWNTjQ88Rfxl9vvjMS9_lNlcIbZoQihT_QHdr2WhpoS0D7HcUBGJC2zqE56OQ3-eZ-pAEU_oHezawC3rZMX9vDbZSZYSgTxW_aNQwOchbcOaNPPbae9QOHPU-J6Uuz2ch9pkBPD-y5vhZ3-zV2w9z5Bfc4Q1sxxcNfYSjwq87TCBKIVoktXHW36caHGJd5M3KrwWhaJzx7RSlJVJdMREbF4QKsiGz3hSV7e-8AoDlXSWooivtHjZIfSh1xOyb_sHL0paesVd2eI72w4Khnq98BuQvv1hORdLipkk2VvAtyMmRYsDlXEZsq2IkXh_ucfWlq_7MjC25SCXymhY-1SNPOxMx_gvq3MkDz29BeaoyPNfwBEGtdRP5oI8iRwC1fj8FFeV4PuDjRKm0",
"e": "AQAB"
}
]
}
17 changes: 15 additions & 2 deletions src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub struct EsiBuilder {
pub(crate) base_api_url: Option<String>,
pub(crate) authorize_url: Option<String>,
pub(crate) token_url: Option<String>,
pub(crate) metadata_url: Option<String>,
pub(crate) spec_url: Option<String>,
pub(crate) scope: Option<String>,
pub(crate) access_token: Option<String>,
Expand Down Expand Up @@ -192,6 +193,13 @@ impl EsiBuilder {
self
}

/// Set the URL of the SSO metadata document, which points to the keys that
/// validate the access token (only used with the "validate_jwt" feature).
pub fn metadata_url(mut self, val: &str) -> Self {
self.metadata_url = Some(val.to_owned());
self
}

/// Set the spec_url.
pub fn spec_url(mut self, val: &str) -> Self {
self.spec_url = Some(val.to_owned());
Expand Down Expand Up @@ -274,7 +282,6 @@ impl EsiBuilder {
let builder = Client::builder()
.timeout(http_timeout)
.default_headers(headers);
#[cfg(feature = "rustls-tls")]
let builder = builder.tls_backend_rustls();
Ok(builder.build()?)
}
Expand Down Expand Up @@ -405,6 +412,10 @@ mod tests {
"https://login.eveonline.com/v2/oauth/authorize"
);
assert_eq!(b.token_url, "https://login.eveonline.com/v2/oauth/token");
assert_eq!(
b.metadata_url,
"https://login.eveonline.com/.well-known/oauth-authorization-server"
);
assert_eq!(b.spec_url, "https://esi.evetech.net/meta/openapi.json");
assert_eq!(b.compatibility_date, "2026-08-18");
assert_eq!(b.access_token, None);
Expand All @@ -418,13 +429,15 @@ mod tests {
.base_api_url("http://eve-api/")
.authorize_url("http://authorize-url/")
.token_url("http://token-url")
.metadata_url("http://metadata-url")
.spec_url("http://spec-url/")
.build()
.unwrap();

assert_eq!(b.base_api_url, "http://eve-api/");
assert_eq!(b.authorize_url, "http://authorize-url/");
assert_eq!(b.token_url, "http://token-url");
assert_eq!(b.metadata_url, "http://metadata-url");
assert_eq!(b.spec_url, "http://spec-url/");
}

Expand All @@ -450,7 +463,7 @@ mod tests {

#[test]
fn test_builder_to_json_empty() {
let json = r#"{"compatibility_date":null,"client_id":null,"client_secret":null,"application_auth":null,"callback_url":null,"base_api_url":null,"authorize_url":null,"token_url":null,"spec_url":null,"scope":null,"access_token":null,"access_expiration":null,"refresh_token":null,"user_agent":null,"http_timeout":null,"spec":null}"#;
let json = r#"{"compatibility_date":null,"client_id":null,"client_secret":null,"application_auth":null,"callback_url":null,"base_api_url":null,"authorize_url":null,"token_url":null,"metadata_url":null,"spec_url":null,"scope":null,"access_token":null,"access_expiration":null,"refresh_token":null,"user_agent":null,"http_timeout":null,"spec":null}"#;
assert_eq!(json, serde_json::to_string(&EsiBuilder::new()).unwrap());
}

Expand Down
23 changes: 17 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use tokio::sync::RwLock;
const BASE_URL: &str = "https://esi.evetech.net/";
const AUTHORIZE_URL: &str = "https://login.eveonline.com/v2/oauth/authorize";
const TOKEN_URL: &str = "https://login.eveonline.com/v2/oauth/token";
const METADATA_URL: &str = "https://login.eveonline.com/.well-known/oauth-authorization-server";
const SPEC_URL: &str = "https://esi.evetech.net/meta/openapi.json";
const ERROR_LIMIT_REMAIN_HEADER: &str = "x-esi-error-limit-remain";
const ERROR_LIMIT_RESET_HEADER: &str = "x-esi-error-limit-reset";
Expand Down Expand Up @@ -195,6 +196,7 @@ pub struct Esi {
pub(crate) base_api_url: String,
pub(crate) authorize_url: String,
pub(crate) token_url: String,
pub(crate) metadata_url: String,
pub(crate) spec_url: String,
pub(crate) scope: String,
pub(crate) application_auth: bool,
Expand Down Expand Up @@ -247,6 +249,7 @@ impl Esi {
base_api_url: builder.base_api_url.unwrap_or(BASE_URL.to_string()),
authorize_url: builder.authorize_url.unwrap_or(AUTHORIZE_URL.to_string()),
token_url: builder.token_url.unwrap_or(TOKEN_URL.to_string()),
metadata_url: builder.metadata_url.unwrap_or(METADATA_URL.to_string()),
spec_url: builder.spec_url.unwrap_or(SPEC_URL.to_string()),
scope: builder.scope.unwrap_or_else(|| "".to_owned()),
application_auth: builder.application_auth.unwrap_or(false),
Expand Down Expand Up @@ -560,6 +563,7 @@ impl Esi {
let claim_data = Some(
crate::jwt_util::validate_jwt(
&self.client,
&self.metadata_url,
&data.access_token,
self.client_id.as_ref().unwrap(),
)
Expand Down Expand Up @@ -984,7 +988,9 @@ impl Esi {
.headers(headers)
.query(query.unwrap_or(&[]));
req_builder = match body {
Some(b) => req_builder.body(b.to_owned()),
Some(b) => req_builder
.header(header::CONTENT_TYPE, "application/json")
.body(b.to_owned()),
None => req_builder,
};
let req = req_builder.build()?;
Expand Down Expand Up @@ -1125,8 +1131,12 @@ impl Esi {
if self.access_token.is_none() {
return Err(EsiError::MissingAuthentication);
}
if self.access_expiration.unwrap() < current_time_millis()? {
return Err(EsiError::AccessTokenExpired);
// A token given without an expiration can't be judged here: send it and
// let ESI answer if it is no longer valid.
if let Some(expiration) = self.access_expiration {
if expiration < current_time_millis()? {
return Err(EsiError::AccessTokenExpired);
}
}
Ok(())
}
Expand All @@ -1135,9 +1145,10 @@ impl Esi {
/// and the compatibility date.
fn request_headers(&self, request_type: &RequestType) -> EsiResult<HeaderMap> {
let mut map = HeaderMap::new();
// The 'user-agent' and 'content-type' headers are set in the default headers
// from the builder, so all that's required here is to set the authorization
// header, if present, and the compatibility date.
// The 'user-agent' and 'accept' headers are set in the default headers
// from the builder (and 'content-type', when there is a body, in
// `send_request`), so all that's required here is to set the
// authorization header, if present, and the compatibility date.
if *request_type == RequestType::Authenticated {
if let Some(at) = &self.access_token {
map.insert(
Expand Down
5 changes: 3 additions & 2 deletions src/groups/corporation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ pub struct ContainerLogEntry {
pub new_config_bitmask: Option<i64>,
/// Configuration bitmask before the change.
pub old_config_bitmask: Option<i64>,
/// Kind of password involved.
pub password_type: ContainerPasswordType,
/// Kind of password involved (only for the password actions).
pub password_type: Option<ContainerPasswordType>,
/// Quantity moved.
pub quantity: Option<i64>,
/// Type ID of the item moved.
Expand Down Expand Up @@ -863,6 +863,7 @@ mod corporation_management_tests {
)
.unwrap();
assert_eq!(l[0].action, ContainerAction::EnterPassword);
assert_eq!(l[0].password_type, Some(ContainerPasswordType::Config));
let t: Vec<CorporationTitle> =
serde_json::from_str(r#"[{"title_id": 1, "name": "CEO", "roles": ["Director"]}]"#)
.unwrap();
Expand Down
8 changes: 4 additions & 4 deletions src/groups/faction_warfare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub struct FWLeaderboards {
#[derive(Debug, Deserialize)]
#[allow(missing_docs)]
pub struct CharacterLeaderboardItem {
pub amount: i64,
pub character_id: i64,
pub amount: Option<i64>,
pub character_id: Option<i64>,
}

#[derive(Debug, Deserialize)]
Expand All @@ -52,8 +52,8 @@ pub struct FWCharacterLeaderboards {
#[derive(Debug, Deserialize)]
#[allow(missing_docs)]
pub struct CorporationLeaderboardItem {
pub amount: i64,
pub corporation_id: i64,
pub amount: Option<i64>,
pub corporation_id: Option<i64>,
}

#[derive(Debug, Deserialize)]
Expand Down
37 changes: 29 additions & 8 deletions src/groups/fittings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ pub struct NewFitting {
pub ship_type_id: i64,
}

/// The answer to saving a fitting.
#[derive(Debug, Deserialize)]
struct CreatedFitting {
fitting_id: i64,
}

impl FittingsGroup<'_> {
api_get!(
/// Return the fittings saved by a character.
Expand All @@ -109,15 +115,23 @@ impl FittingsGroup<'_> {
(character_id: i64) => "{character_id}"
);

api_post!(
/// Save a new fitting. Returns the ID of the created fitting.
create_character_fitting,
"PostCharactersCharacterIdFittings",
RequestType::Authenticated,
i64,
(character_id: i64) => "{character_id}",
/// Save a new fitting. Returns the ID of the created fitting.
pub async fn create_character_fitting(
&self,
character_id: i64,
fitting: &NewFitting,
);
) -> EsiResult<i64> {
let path = self
.esi
.get_endpoint_for_op_id("PostCharactersCharacterIdFittings")?
.replace("{character_id}", &character_id.to_string());
let body = serde_json::to_string(fitting)?;
let created: CreatedFitting = self
.esi
.query("POST", RequestType::Authenticated, &path, None, Some(&body))
.await?;
Ok(created.fitting_id)
}

api_delete!(
/// Delete a saved fitting.
Expand Down Expand Up @@ -145,6 +159,13 @@ mod fittings_tests {
assert_eq!(fits[0].items[1].flag, FittingFlag::Unrecognized);
}

#[test]
fn test_parse_created_fitting() {
let created: CreatedFitting =
serde_json::from_str(r#"{"fitting_id": 3000000000}"#).unwrap();
assert_eq!(created.fitting_id, 3_000_000_000);
}

#[test]
fn test_serialize_new_fitting() {
let f = NewFitting {
Expand Down
Loading
Loading