Skip to content

Commit 6a4ee59

Browse files
committed
auth and bluebubbles location
1 parent ef44fde commit 6a4ee59

File tree

11 files changed

+397
-5
lines changed

11 files changed

+397
-5
lines changed

Cargo.lock

Lines changed: 173 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ tower = "0.5.2"
2424
tracing = "0.1.41"
2525
tracing-subscriber = "0.3.19"
2626
ts-rs = { version = "10.1.0", features = ["chrono-impl"] }
27+
tzf-rs = { version = "1.0.0", default-features = false }

bruno/aubrey.bru

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
meta {
2+
name: rose
3+
type: http
4+
seq: 2
5+
}
6+
7+
get {
8+
url: http://localhost:3000/api/user
9+
body: none
10+
auth: bearer
11+
}
12+
13+
headers {
14+
Host: rose.hall.ly
15+
}
16+
17+
auth:bearer {
18+
token: {{personal-auth-token}}
19+
}

bruno/bruno.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": "1",
3+
"name": "personal-api",
4+
"type": "collection",
5+
"ignore": [
6+
"node_modules",
7+
".git"
8+
]
9+
}

bruno/icloud.bru

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
meta {
2+
name: icloud
3+
type: http
4+
seq: 1
5+
}
6+
7+
get {
8+
url: http://shared-mac-studio:1234/api/v1/icloud/findmy/devices?password={{blubbles-server-pass}}
9+
body: none
10+
auth: inherit
11+
}
12+
13+
params:query {
14+
password: {{blubbles-server-pass}}
15+
}

src/config.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
use std::collections::HashMap;
1+
use std::{borrow::Cow, collections::HashMap};
22

3+
use axum_extra::{headers::{authorization::Bearer, Authorization}, TypedHeader};
34
use serde::{Deserialize, Serialize};
45
use steam_rs::steam_id::SteamId;
56

67
#[derive(Serialize, Deserialize)]
78
pub struct Config {
89
pub discord_bot_token: Option<String>,
9-
#[serde(default)]
1010
pub discord_initial_search_guilds: Vec<u64>,
1111
pub last_fm_key: Option<String>,
1212
pub steam_api_key: Option<String>,
13+
pub bluebubbles_server: Option<String>,
14+
pub bluebubbles_server_password: Option<String>,
1315

16+
pub auth: HashMap<String, AuthConfig>,
1417
pub users: HashMap<String, UserConfig>,
1518
}
1619

@@ -25,4 +28,21 @@ pub struct UserConfig {
2528
pub discord_id: Option<u64>,
2629
pub last_fm_username: Option<String>,
2730
pub steam_id: Option<SteamId>,
31+
pub icloud_device_id: Option<String>,
32+
}
33+
34+
#[derive(Serialize, Deserialize)]
35+
pub struct AuthConfig {
36+
pub scopes: Vec<String>,
37+
}
38+
39+
pub fn scopes_from_bearer(bearer: Option<TypedHeader<Authorization<Bearer>>>, config: &'static Config) -> Cow<'static, [String]> {
40+
bearer
41+
.and_then(|auth| config.auth.get(auth.0.token()))
42+
.map(|auth| Cow::<'static, [String]>::Borrowed(&auth.scopes))
43+
.unwrap_or_default()
44+
}
45+
46+
pub fn has_scope(auth_scopes: &Cow<[String]>, scope: &'static str) -> bool{
47+
auth_scopes.iter().any(|s| scope == s)
2848
}

0 commit comments

Comments
 (0)