mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-05-18 05:15:16 -04:00
Use actual oauth clients + ship ids and secrets (#1415)
* use actual oauth clients + ship ids and secrets * re-enable features * use prod as default api url
This commit is contained in:
@@ -71,6 +71,9 @@ macro_rules! tauri_handlers {
|
||||
}};
|
||||
}
|
||||
|
||||
const CLIENT_ID: &str = "2abb241e-40b8-4517-a3e3-5594375c8fbb";
|
||||
const CLIENT_SECRET: &str = "eb4554cb-c08d-4e82-b4cc-0aa29c07e934";
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> tauri::Result<()> {
|
||||
#[cfg(debug_assertions)]
|
||||
@@ -88,7 +91,18 @@ async fn main() -> tauri::Result<()> {
|
||||
|
||||
// The `_guard` must be assigned to variable for flushing remaining logs on main exit through Drop
|
||||
let (_guard, result) = match Node::init_logger(&data_dir) {
|
||||
Ok(guard) => (Some(guard), Node::new(data_dir).await),
|
||||
Ok(guard) => (
|
||||
Some(guard),
|
||||
Node::new(
|
||||
data_dir,
|
||||
sd_core::Env {
|
||||
api_url: "https://app.spacedrive.com".to_string(),
|
||||
client_id: CLIENT_ID.to_string(),
|
||||
client_secret: CLIENT_SECRET.to_string(),
|
||||
},
|
||||
)
|
||||
.await,
|
||||
),
|
||||
Err(err) => (None, Err(NodeError::Logger(err))),
|
||||
};
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@ pub static SUBSCRIPTIONS: Lazy<Arc<futures_locks::Mutex<HashMap<RequestId, onesh
|
||||
|
||||
pub static EVENT_SENDER: OnceCell<mpsc::Sender<Response>> = OnceCell::new();
|
||||
|
||||
pub const CLIENT_ID: &str = "d068776a-05b6-4aaa-9001-4d01734e1944";
|
||||
pub const CLIENT_SECRET: &str = "961cdf5c-9eb1-43dc-b921-5b1dd8bbf6a5";
|
||||
|
||||
pub struct MobileSender<'a> {
|
||||
resp: &'a mut Option<Response>,
|
||||
}
|
||||
@@ -70,7 +73,16 @@ pub fn handle_core_msg(
|
||||
let _guard = Node::init_logger(&data_dir);
|
||||
|
||||
// TODO: probably don't unwrap
|
||||
let new_node = Node::new(data_dir).await.unwrap();
|
||||
let new_node = Node::new(
|
||||
data_dir,
|
||||
sd_core::Env {
|
||||
api_url: "https://app.spacedrive.com".to_string(),
|
||||
client_id: CLIENT_ID.to_string(),
|
||||
client_secret: CLIENT_SECRET.to_string(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
node.replace(new_node.clone());
|
||||
new_node
|
||||
}
|
||||
|
||||
@@ -39,7 +39,19 @@ async fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
let (node, router) = match Node::new(data_dir).await {
|
||||
let (node, router) = match Node::new(
|
||||
data_dir,
|
||||
sd_core::Env {
|
||||
api_url: std::env::var("SD_API_URL")
|
||||
.unwrap_or_else(|_| "https://app.spacedrive.com".to_string()),
|
||||
client_id: std::env::var("SD_CLIENT_ID")
|
||||
.unwrap_or_else(|_| "04701823-a498-406e-aef9-22081c1dae34".to_string()),
|
||||
client_secret: std::env::var("SD_CLIENT_ID")
|
||||
.unwrap_or_else(|_| "8c0e4f85-d1d3-4a0c-9445-65003ffc581d".to_string()),
|
||||
},
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(d) => d,
|
||||
Err(e) => {
|
||||
panic!("{}", e.to_string())
|
||||
|
||||
@@ -57,11 +57,12 @@ pub(crate) fn mount() -> AlphaRouter<Ctx> {
|
||||
verification_uri_complete: String,
|
||||
}
|
||||
|
||||
let Ok(auth_response) = (match node.http
|
||||
let Ok(auth_response) = (match node.http
|
||||
.post(&format!("{}/login/device/code", &node.env.api_url))
|
||||
.form(&[("client_id", &node.env.client_id)])
|
||||
.send()
|
||||
.await {
|
||||
Ok(resp) => resp.json::<DeviceAuthorizationResponse>().await,
|
||||
Ok(r) => r.json::<DeviceAuthorizationResponse>().await,
|
||||
Err(e) => Err(e)
|
||||
}) else {
|
||||
yield Response::Error;
|
||||
@@ -79,7 +80,11 @@ pub(crate) fn mount() -> AlphaRouter<Ctx> {
|
||||
|
||||
let Ok(token_resp) = node.http
|
||||
.post(&format!("{}/login/oauth/access_token", &node.env.api_url))
|
||||
.form(&[("grant_type", DEVICE_CODE_URN), ("device_code", &auth_response.device_code)])
|
||||
.form(&[
|
||||
("grant_type", DEVICE_CODE_URN),
|
||||
("device_code", &auth_response.device_code),
|
||||
("client_id", &node.env.client_id)
|
||||
])
|
||||
.send()
|
||||
.await else {
|
||||
break Response::Error;
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
pub struct Env {
|
||||
pub api_url: String,
|
||||
}
|
||||
|
||||
impl Default for Env {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Env {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
api_url: std::env::var("SD_API_URL")
|
||||
.unwrap_or_else(|_| "https://app.spacedrive.com".to_string()),
|
||||
}
|
||||
}
|
||||
pub client_id: String,
|
||||
pub client_secret: String,
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ pub(crate) mod preferences;
|
||||
pub mod util;
|
||||
pub(crate) mod volume;
|
||||
|
||||
pub use env::Env;
|
||||
|
||||
pub(crate) use sd_core_sync as sync;
|
||||
|
||||
/// Represents a single running instance of the Spacedrive core.
|
||||
@@ -78,7 +80,10 @@ impl fmt::Debug for Node {
|
||||
}
|
||||
|
||||
impl Node {
|
||||
pub async fn new(data_dir: impl AsRef<Path>) -> Result<(Arc<Node>, Arc<Router>), NodeError> {
|
||||
pub async fn new(
|
||||
data_dir: impl AsRef<Path>,
|
||||
env: env::Env,
|
||||
) -> Result<(Arc<Node>, Arc<Router>), NodeError> {
|
||||
let data_dir = data_dir.as_ref();
|
||||
|
||||
info!("Starting core with data directory '{}'", data_dir.display());
|
||||
@@ -114,8 +119,8 @@ impl Node {
|
||||
),
|
||||
libraries,
|
||||
files_over_p2p_flag: Arc::new(AtomicBool::new(false)),
|
||||
env: Default::default(),
|
||||
http: reqwest::Client::new(),
|
||||
env,
|
||||
});
|
||||
|
||||
// Restore backend feature flags
|
||||
|
||||
Reference in New Issue
Block a user