npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@fabianlars/tauri-plugin-oauth

v2.0.0

Published

A Tauri plugin for spawning a localhost server. Needed for some oauth flows (Login with X).

Downloads

16,857

Readme

Tauri Plugin OAuth

A minimalistic Rust library and Tauri plugin for handling browser-based OAuth flows in desktop applications. This plugin spawns a temporary localhost server to capture OAuth redirects, solving the challenge of using OAuth with desktop apps.

Why This Plugin?

Many OAuth providers (like Google and GitHub) don't allow custom URI schemes ("deep links") as redirect URLs. This plugin provides a solution by:

  1. Spawning a temporary local server
  2. Capturing the OAuth redirect
  3. Passing the authorization data back to your app

Note: For an alternative approach using deep linking, see tauri-plugin-deep-link. The deep-link plugin can automatically start your app if there's no open instance.

Installation

# Cargo.toml
[dependencies]
tauri-plugin-oauth = "2"

For Tauri projects using npm or yarn:

npm install @fabianlars/tauri-plugin-oauth@2
# or
yarn add @fabianlars/tauri-plugin-oauth@2

Usage

Rust

use tauri::{command, Emitter, Window};
use tauri_plugin_oauth::start;

#[command]
async fn start_server(window: Window) -> Result<u16, String> {
    start(move |url| {
        // Because of the unprotected localhost port, you must verify the URL here.
        // Preferebly send back only the token, or nothing at all if you can handle everything else in Rust.
        let _ = window.emit("redirect_uri", url);
    })
        .map_err(|err| err.to_string())
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()

        .plugin(tauri_plugin_oauth::init())
        .invoke_handler(tauri::generate_handler![start_server])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

TypeScript

import { start, cancel, onUrl, onInvalidUrl } from '@fabianlars/tauri-plugin-oauth';

async function startOAuthFlow() {
  try {
    const port = await start();
    console.log(`OAuth server started on port ${port}`);

    // Set up listeners for OAuth results
    await onUrl((url) => {
      console.log('Received OAuth URL:', url);
      // Handle the OAuth redirect
    });

    // Initiate your OAuth flow here
    // ...

  } catch (error) {
    console.error('Error starting OAuth server:', error);
  }
}

// Don't forget to stop the server when you're done
async function stopOAuthServer() {
  try {
    await cancel(port);
    console.log('OAuth server stopped');
  } catch (error) {
    console.error('Error stopping OAuth server:', error);
  }
}

Configuration

You can configure the plugin behavior using the OauthConfig struct:

use tauri_plugin_oauth::OauthConfig;

let config = OauthConfig {
    ports: Some(vec![8000, 8001, 8002]),
    response: Some("OAuth process completed. You can close this window.".into()),
};

start_with_config(config, |url| {
    // Handle OAuth URL
})
.await
.expect("Failed to start OAuth server");

Security Considerations

  • Always validate the received OAuth URL on your server-side before considering it authentic.
  • Use HTTPS for your OAuth flow to prevent man-in-the-middle attacks.
  • Implement proper token storage and refresh mechanisms in your application.

Contributing

Contributions are always welcome! Please feel free to submit a Pull Request.

License

This project is dual-licensed under either of the following licenses, at your option: