tauri_plugin_auth_session/
lib.rs1use tauri::{
17 plugin::{Builder, TauriPlugin},
18 Runtime,
19};
20
21#[cfg(any(target_os = "macos", target_os = "ios"))]
22mod apple;
23
24#[cfg(target_os = "android")]
25mod android;
26
27#[cfg(target_os = "android")]
28const PLUGIN_IDENTIFIER: &str = "app.tauri.auth_session";
29
30#[cfg(target_os = "android")]
31use tauri::{AppHandle, Manager};
32
33#[cfg(target_os = "android")]
35struct MobilePluginHandle<R: Runtime>(tauri::plugin::PluginHandle<R>);
36
37pub fn init<R: Runtime>() -> TauriPlugin<R> {
39 Builder::new("auth-session")
40 .setup(|app, api| {
41 #[cfg(target_os = "android")]
42 {
43 let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "AuthSessionPlugin")?;
44 app.manage(MobilePluginHandle(handle));
45 }
46 #[cfg(not(target_os = "android"))]
47 {
48 let _ = (app, api);
49 }
50 Ok(())
51 })
52 .invoke_handler(tauri::generate_handler![start])
53 .build()
54}
55
56#[cfg(any(target_os = "macos", target_os = "ios"))]
61#[tauri::command]
62async fn start(
63 auth_url: String,
64 callback_url_scheme: String,
65 ephemeral: Option<bool>,
66) -> Result<String, String> {
67 apple::start_session(auth_url, callback_url_scheme, ephemeral.unwrap_or(false)).await
68}
69
70#[cfg(target_os = "android")]
75#[tauri::command]
76async fn start<R: Runtime>(
77 app: AppHandle<R>,
78 auth_url: String,
79 callback_url_scheme: String,
80 _ephemeral: Option<bool>,
81) -> Result<String, String> {
82 let handle = app.state::<MobilePluginHandle<R>>();
83 android::start_session(&handle.0, auth_url, callback_url_scheme).await
84}
85
86#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
91#[tauri::command]
92async fn start(
93 _auth_url: String,
94 _callback_url_scheme: String,
95 _ephemeral: Option<bool>,
96) -> Result<String, String> {
97 Err("In-app auth sessions are only available on Apple and Android platforms".to_string())
98}