Skip to content

Commit

Permalink
feat: microsoft authentication scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
ResetPower committed Feb 16, 2024
1 parent 7ddd596 commit 7ee15ac
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions src-tauri/Cargo.lock

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

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tauri = { version = "1.5", features = [ "api-all",
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
zip = "0.6.6"
once_cell = "1.19.0"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
36 changes: 36 additions & 0 deletions src-tauri/src/core/auth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use tauri::Manager;

#[tauri::command]
pub fn get_microsoft_auth_code(app_handle: tauri::AppHandle) {
tauri::WindowBuilder::new(
&app_handle,
"oauth",
tauri::WindowUrl::External(
"https://login.live.com/oauth20_authorize.srf\
?client_id=00000000402b5328\
&response_type=code\
&prompt=login\
&scope=service%3A%3Auser.auth.xboxlive.com%3A%3AMBI_SSL\
&redirect_uri=https%3A%2F%2Flogin.live.com%2Foauth20_desktop.srf"
.parse()
.unwrap(),
),
)
.title("Log in to Microsoft...")
.on_navigation(|url| {
let prefix = "https://login.live.com/oauth20_desktop.srf?";
let url = url.to_string();
if url.starts_with(prefix) {
let auth_code = url.replace(prefix, "");
if let Some(app_handle) = crate::INSTANCE.get() {
app_handle.emit_all("auth-code", auth_code).unwrap();
if let Some(window) = app_handle.get_window("oauth") {
window.close().unwrap();
}
}
}
true
})
.build()
.unwrap();
}
1 change: 1 addition & 0 deletions src-tauri/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod auth;
pub mod runner;
pub mod zip;
12 changes: 11 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use once_cell::sync::OnceCell;
use tauri::AppHandle;

pub static INSTANCE: OnceCell<AppHandle> = OnceCell::new();

mod core;

fn main() {
tauri::Builder::default()
.setup(|app| {
INSTANCE.set(app.handle()).unwrap();
Ok(())
})
.invoke_handler(tauri::generate_handler![
core::zip::extract_zip,
core::runner::run_minecraft
core::runner::run_minecraft,
core::auth::get_microsoft_auth_code,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down

0 comments on commit 7ee15ac

Please sign in to comment.