[英]Tauri Redirect URI Schema
I'm building a Tauri app and would like to set up OAuth integration with Google.我正在构建一个 Tauri 应用程序,并希望设置 OAuth 与 Google 的集成。 To do so, I will need a URI for the oauth callback, but Tauri is unclear how to configure the schema possibly using this method or with the
WindowUrl
?为此,我需要一个用于 oauth 回调的 URI,但 Tauri 不清楚如何使用此方法或
WindowUrl
配置模式?
How can I add a URI to my Tauri app so I could like to it like the following example: myapp://callback
如何将 URI 添加到我的 Tauri 应用程序,以便我喜欢它,如下例所示:
myapp://callback
I think it could look something like the following:我认为它可能类似于以下内容:
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet])
.register_uri_scheme_protocol("myapp", move |app, request| {
# protocol logic here
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Tauri currently doesn't directly support deep linking. Tauri 目前不直接支持深度链接。 A good alternative that I found was this rust project.
我找到的一个很好的替代方案是这个rust 项目。 After installation you can do something like the following:
安装后,您可以执行以下操作:
#[tauri::command]
async fn start_oauth_server(window: Window) -> Result<u16, String> {
println!("Starting server");
start(None, 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.
// convert the string to a url
let url = url::Url::parse(&url).unwrap();
// get the code query parameter
let code = url
.query_pairs()
.find(|(k, _)| k == "code")
.unwrap_or_default()
.1;
// get the state query parameter
let state = url
.query_pairs()
.find(|(k, _)| k == "state")
.unwrap_or_default()
.1;
// create map of query parameters
let mut query_params = HashMap::new();
query_params.insert("code".to_string(), code.to_string());
query_params.insert("state".to_string(), state.to_string());
query_params.insert(String::from("redirect_uri"), url.to_string());
if window.emit("redirect_uri", query_params).is_ok() {
println!("Sent redirect_uri event");
} else {
println!("Failed to send redirect_uri event");
}
})
.map_err(|err| err.to_string())
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.