Skip to content

Instantly share code, notes, and snippets.

@allquixotic
Created January 23, 2023 07:24
Show Gist options
  • Save allquixotic/accb7721036062581c7c98ffce9b252b to your computer and use it in GitHub Desktop.
Save allquixotic/accb7721036062581c7c98ffce9b252b to your computer and use it in GitHub Desktop.
another jsonrpc failure
use jsonrpsee::{http_client::{HttpClientBuilder, HttpClient}, ws_client::HeaderMap, core::{Error, __reexports::serde::Deserialize}, proc_macros::rpc};
use dotenvy::var;
#[derive(Deserialize)]
pub struct LoginResponse {
session_id: String,
}
#[rpc(client)]
trait Api {
#[method(name="User.login", param_kind=map)]
async fn login(&self, email: String, password: String) -> Result<LoginResponse, Error>;
}
struct State {
email: String,
password: String,
website: String,
proxy: Option<String>,
client: HttpClient
}
impl State {
fn new() -> Self {
let mut headers = HeaderMap::new();
headers.insert("Accept", "*/*".parse().unwrap());
headers.insert("User-Agent", "something".parse().unwrap());
let mut client_builder = HttpClientBuilder::default().set_headers(headers);
let proxy = var("proxy").ok();
let website = var("website").expect("Required .env variable missing: website");
if proxy.as_ref().is_some() {
client_builder = client_builder.set_proxy(proxy.as_ref().unwrap()).unwrap();
}
let client = client_builder.set_max_logging_length(99999999).build(format!("https://{}:443/api/v1/api.php", website)).unwrap();
State {
email: var("email").expect("Required .env variable missing: email"),
password: var("password").expect("Required .env variable missing: password"),
website: website,
proxy: proxy,
client: client
}
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::FmtSubscriber::builder()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.try_init()
.expect("setting default subscriber failed");
let mut state = State::new();
let resp = state.client.login(state.email, state.password).await?;
println!("{}", resp.session_id);
Ok(())
}
POST /api/v1/api.php HTTP/1.1
content-type: application/json
accept: */*
user-agent: something
host: www.enjin.com
content-length: 121
{"jsonrpc":"2.0","id":0,"method":"User.login","params":{"email":"redacted","password":"redacted"}}
HTTP/1.1 200 OK
Date: Mon, 23 Jan 2023 07:10:20 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Set-Cookie: api_auth=redacted; expires=Wed, 22-Feb-2023 07:10:20 GMT; Max-Age=2592000; path=/; HttpOnly
CF-Cache-Status: DYNAMIC
Pragma: no-cache
X-Backend-Server: web5.enjin.com
Set-Cookie: __cf_bm=redacted; path=/; expires=Mon, 23-Jan-23 07:40:20 GMT; domain=.www.enjin.com; HttpOnly; Secure; SameSite=None
Server: cloudflare
CF-RAY: redacted
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
{
"result": {
"session_id": "redacted",
"notification_counts": {
"mail": "0",
"notifications": "15",
"applications": "2",
"pending_friend_requests": 0,
"api-general": "2",
"api-forums": "255"
},
"pusher_channels": {
"pubnub_channel": "pubnub-mobile-redacted",
"channel_user": "user_redacted_0",
"channel_site": "presence-site",
"channel_sitewall_post": "sitewall_post",
"channel_chat": "presence-pchat"
},
"user_id": "redacted",
"language": "en",
"username": "redacted",
"resources": "https://resources.enjin.com/redacted/",
"sites": [
{
"site_id": "redacted",
"name": "redacted",
"url": "http://www.enjin.com",
"description": "",
"logo": "https://s3.amazonaws.com/files.enjin.com/redacted/site_logo/large.png",
"logo_full": "https://s3.amazonaws.com/files.enjin.com/redacted/site_logo/full.png",
"likes": "370",
"is_liked": false,
"users": "redacted",
"banner": "https://resources.enjin.com/redacted/admin/v3/images/settings/default_banner.png",
"access": "2",
"can_join": true
}
]
},
"id": "0",
"jsonrpc": "2.0"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment