#FabianLars - tauri-plugin-oauth

1 messages · Page 1 of 1 (latest)

sudden zephyr
#

Hi, I need help with implementing the Tauri Plugin OAuth. Currently, I am trying to enable Google login. The OAuth functionality works on the web version of my app, but now I want to implement it in my Tauri app. I am new to Tauri and currently unfamiliar with Rust, so I am feeling confused and lost. So far, I have completed the following steps:

  1. in Cargo.toml
tauri-plugin-oauth = { git = "https://github.com/FabianLars/tauri-plugin-oauth", branch = "main" }
  1. in main.rs
#![cfg_attr(
    all(not(debug_assertions), target_os = "windows"),
    windows_subsystem = "windows"
)]

use tauri::{command, 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())
}

fn main() {
    let sys_tray = build_system_tray();
    tauri::Builder::default()
        .plugin(tauri_plugin_store::Builder::default().build())
        .plugin(tauri_plugin_oauth::init())
        .system_tray(sys_tray)
        .setup(|app| {
            let window = app.get_window("main").unwrap();
            app.global_shortcut_manager()
                .register(SHORTCUT_SHOW_HIDE, move || {
                    show_hide_window(&window);
                })
                .unwrap();
        Ok(())
        })
        .invoke_handler(tauri::generate_handler![open_settings,start_server])
        .run(tauri::generate_context!())
        .unwrap();
}

  1. In my Tauri app, I have created a functional button that can successfully redirect the user to the web for Google login. I am unsure how to implement the functionality that allows the user to return to my app and complete the login process.

thank you!

drowsy island
#

Soooo, first of the all, the plugin was primarily created for flows that use the user's default browser for logging in (because i hate it when i can't do that as a user myself 🙃)

#

anyway, where you're now emitting the redirect_uri event you now have to instruct tauri to redirect to https://tauri.localhost/ (windows) or tauri://localhost/ (linux/macos). While holding on to the token until the page is done loading. -> For that last part you may have to do an extra event roundtrip so that the frontend can tell you that it's ready or something

#

or i guess adding the token into the url could work too idk (may be insecure though?)

sudden zephyr