Desktop apps (Rust)
Desktop apps sign in through the system browser (RFC 8252, "OAuth for native apps"): the user types the password in the browser they know, with their password manager and passkeys, never in a window of your app. The answer comes back to a small server your app opens on 127.0.0.1.
You need: a client with the loopback callback turned on (in the console: New client → loopback callback, with a path such as /callback). The port is not registered: it changes at every sign-in.
Add the crate
The novren-id crate is distributed from git while the packages are private:
[dependencies]
novren-id = { git = "https://github.com/novrenIris/novrenID", tag = "packages-v2026.11.6" }
open = "5" # to open the system browserSign in
use novren_id::app::{begin_login, exchange_code, open_product_key, refresh, revoke, TokenResponse};
use std::time::Duration;
const ACCOUNT_URL: &str = "https://account.novren.net";
const ID_SERVER_URL: &str = "https://id.novren.net";
const CLIENT_ID: &str = "cl-0123456789abcdef0123"; // a client with the loopback callback
async fn sign_in() -> novren_id::Result<TokenResponse> {
// 1. A local server on 127.0.0.1 (random port) + PKCE + ephemeral key.
let (url, loopback) = begin_login(ACCOUNT_URL, CLIENT_ID)?;
// 2. The system browser: the user signs in there, never inside your window.
open::that(&url).expect("cannot open the browser");
// 3. Wait for the return (5 minutes at most).
let callback = loopback.wait(Duration::from_secs(300))?;
// 4. Open the app key (only on this machine), then exchange the code.
let login = open_product_key(&callback, &loopback.pending)?;
// login.account_id, login.product_key (zeroized on drop), login.identity
keep_key(login); // your code: keep it in memory only
exchange_code(ID_SERVER_URL, &loopback.pending, &callback.code).await
}
// The refresh token rotates: always store the new one.
async fn renew(refresh_token: &str) -> novren_id::Result<TokenResponse> {
refresh(ID_SERVER_URL, CLIENT_ID, refresh_token).await
}
async fn sign_out(refresh_token: &str) -> novren_id::Result<()> {
revoke(ID_SERVER_URL, CLIENT_ID, refresh_token).await
}Step by step
begin_login(account_url, client_id)binds a listener on127.0.0.1:0(a free port chosen by the system), prepares PKCE,stateand the ephemeral key, and returns the URL to open plus aLoopback.- Open the URL in the system browser.
loopback.wait(timeout)waits for the browser to come back. The fragment (#key=…) never reaches a server, not even a local one, so the first answer is a tiny page that reads the fragment and posts it to/callback/keyon the same local server. The local server accepts a single post, after the right request, then closes. The browser tab then tells the user they can go back to the app.open_product_key(&callback, &loopback.pending)opens the app key.exchange_code(id_server_url, &loopback.pending, &callback.code)gets the tokens.
To let the user cancel (a "Cancel" button while waiting), use wait_cancellable(timeout, &cancelled) with an AtomicBool.
Why 127.0.0.1 and never localhost
localhost can be redirected by a DNS resolver or the hosts file. 127.0.0.1 is always this machine.
Store the tokens
Keep the refresh token in the operating system's keychain (Windows Credential Manager, macOS Keychain, Secret Service on Linux), not in a plain file. product_key is Zeroizing: keep it in memory and let it be wiped.
Edge cases
- The user closes the browser tab:
waitreturns an error at the timeout. Show a "try again" button. - Firewall prompts: binding to
127.0.0.1doesn't open a port to the network, so firewalls normally stay silent. - Tauri: call the crate from a Tauri command, not from the webview. The webview never receives the key unless you pass it.