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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ rather than editing several version sources by hand. Format: [Keep a Changelog](

## [Unreleased]

## [0.2.1] - 2026-11-28
### Added
- `hinge auth capture`: runs the session-capture steps for you (starts the local proxy, prints what
to do on the phone, waits, imports, cleans up) instead of requiring mitmproxy to be run by hand.
`hinge auth import <file>` is unchanged and still works for anyone who prefers the manual steps or
needs to script the capture themselves.

## [0.2.0] - 2026-11-28
### Changed
- **Rewritten in Rust** (edition 2024; clap, tokio, reqwest with rustls, serde). All commands and
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hinge-cli"
version = "0.2.0"
version = "0.2.1"
edition = "2024"
description = "Command-line client for your own Hinge account, built on its reverse-engineered HTTP API."
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Then capture a session from your own device ([docs/auth.md](docs/auth.md)), impo
your account:

```sh
hinge auth import <captured-session-file>
hinge auth capture # walks you through it on your phone, no separate tools to run by hand
hinge auth status
hinge tier
hinge limits
Expand Down
13 changes: 9 additions & 4 deletions docs/auth.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# Authentication

hinge-cli has no official login. It reuses the session your own Hinge app already has, captured once from your own phone.
hinge-cli has no official login: Hinge's own sign-in requires a device-bound check this CLI can't produce
(the server expects a hardware-backed attestation tied to the real app, not just a phone number and a code).
So it reuses the session your own Hinge app already has, captured once from your own phone.
Hinge's terms may forbid this; automation can get an account flagged. Use your own account only.

## Capture (once, per device)
Run `hinge auth capture`. It starts the local capture step for you and prints exactly what to do on
your phone, in order; it waits up to 5 minutes, then saves the session and cleans up by itself. It
needs [mitmproxy](https://mitmproxy.org) installed (the command tells you if it isn't).

**Manual steps (what `auth capture` does for you, if you'd rather run it by hand, or need to automate
a non-interactive capture):**
1. Install [mitmproxy](https://mitmproxy.org) and run `HINGE_OUT=hinge-session.json mitmdump -s tools/hinge_token.py`.
2. On the phone: set the Wi-Fi proxy to this computer (port 8080), open `http://mitm.it`, install the profile and enable full trust under Settings → General → About → Certificate Trust Settings. Turn any VPN off.
3. Force-quit and reopen Hinge. When `hinge-session.json` appears, stop mitmproxy.
Expand All @@ -15,9 +23,6 @@ Hinge's terms may forbid this; automation can get an account flagged. Use your o
- Password manager: set `HINGE_SESSION_REF` to an `op://`, `bw://`, `keychain://` or `cmd://` reference holding the same JSON. Nothing is written to disk.
- `hinge auth logout` deletes the saved session. Tokens expire; repeat the capture when `hinge auth status` fails.

## Not done yet
Phone-number + SMS login inside the CLI (needs the login traffic captured).

## Note: user agent
`hinge auth import` keeps only an allow-list of headers and no longer stores `user-agent`: every request
the CLI sends identifies as a generic Android phone instead (`src/api.rs`). Sessions imported by an
Expand Down
110 changes: 110 additions & 0 deletions src/capture.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//! Guided session capture: wraps the manual mitmproxy steps in `docs/auth.md` into one command, so a
//! member without a technical background can run `hinge auth capture` instead of mitmproxy by hand.
use crate::session_store::{Session, parse_session, real_env, save_session, session_path};
use anyhow::{Context, Result, bail};
use std::io::Write;
use std::net::IpAddr;
use std::path::PathBuf;
use std::process::{Child, Command, Stdio};
use std::time::{Duration, Instant};

const SCRIPT: &str = include_str!("../tools/hinge_token.py");
const PROXY_PORT: u16 = 8080;
const TIMEOUT: Duration = Duration::from_secs(300);

fn local_ip() -> Option<IpAddr> {
// shortcut: UDP "connect" picks the outbound interface without sending a packet; good enough to
// print a LAN address for the phone to type in, falls back to "your computer's IP" if it fails.
let sock = std::net::UdpSocket::bind("0.0.0.0:0").ok()?;
sock.connect("8.8.8.8:80").ok()?;
sock.local_addr().ok().map(|a| a.ip())
}

struct Proxy(Child);
impl Drop for Proxy {
fn drop(&mut self) {
self.0.kill().ok();
self.0.wait().ok();
}
}

pub fn capture(print: &dyn Fn(&str)) -> Result<(Session, PathBuf)> {
if Command::new("mitmdump")
.arg("--version")
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
.is_err()
{
bail!(
"mitmproxy is not installed. Install it from https://mitmproxy.org, then run `hinge auth capture` again."
);
}

let script = std::env::temp_dir().join(format!("hinge_token_{}.py", std::process::id()));
std::fs::write(&script, SCRIPT)?;
let out = std::env::temp_dir().join(format!("hinge_session_{}.json", std::process::id()));
std::fs::remove_file(&out).ok();

let child = Command::new("mitmdump")
.args([
"-s",
script.to_str().unwrap(),
"-p",
&PROXY_PORT.to_string(),
"-q",
])
.env("HINGE_OUT", &out)
.stdout(Stdio::null())
.stderr(Stdio::piped())
.spawn()
.context("could not start mitmdump")?;
let _proxy = Proxy(child); // killed on every return path, including early bail!s below

let ip = local_ip().map_or_else(
|| "<your computer's IP address>".to_string(),
|ip| ip.to_string(),
);
print(&format!(
"Capturing your Hinge session. On your phone, with the SAME Wi-Fi network as this computer and any VPN off:\n\
\n\
1. Set the Wi-Fi proxy to {ip} : {PROXY_PORT}\n\
2. Open http://mitm.it in a browser on the phone, install the certificate, then enable full trust for it\n\
(iPhone: Settings > General > About > Certificate Trust Settings)\n\
3. Force-quit the Hinge app and reopen it\n\
\n\
Waiting up to 5 minutes for your session... (Ctrl+C to cancel)"
));

let start = Instant::now();
while !out.exists() {
if start.elapsed() > TIMEOUT {
bail!(
"No session was captured within 5 minutes. Check the phone's proxy and certificate trust, then try again."
);
}
std::thread::sleep(Duration::from_millis(500));
}
std::thread::sleep(Duration::from_millis(300)); // the file is written, then closed; avoid a half-written read
let text = std::fs::read_to_string(&out)?;
std::fs::remove_file(&out).ok();
std::fs::remove_file(&script).ok();

print(
"Got it. Turn the phone's Wi-Fi proxy back off and remove the mitmproxy certificate when you're done.",
);
Ok((
parse_session(&text)?,
session_path(&real_env, std::env::consts::OS),
))
}

pub fn run() -> Result<PathBuf> {
let stdout_print = |s: &str| {
println!("{s}");
std::io::stdout().flush().ok();
};
let (session, path) = capture(&stdout_print)?;
save_session(&session, &path)?;
Ok(path)
}
13 changes: 13 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod api;
mod appium;
mod capture;
mod secrets;
mod session_store;

Expand Down Expand Up @@ -58,6 +59,8 @@ enum AuthCmd {
#[arg(long)]
keep: bool,
},
/// walk you through capturing a session from your own phone (no separate tools to run by hand)
Capture,
/// check that the saved session works
Status,
/// delete the saved session
Expand Down Expand Up @@ -167,6 +170,16 @@ async fn run(cli: Cli) -> Result<()> {
.await?;
out(j, &json!({ "ok": true }), "session OK".into())
}
Cmd::Auth {
cmd: AuthCmd::Capture,
} => {
let path = capture::run()?;
out(
j,
&json!({ "ok": true }),
format!("session saved to {}", path.display()),
)
}
Cmd::Auth {
cmd: AuthCmd::Logout,
} => {
Expand Down