1- use std:: collections:: HashMap ;
1+ use std:: { borrow :: Cow , collections:: HashMap } ;
22
3+ use axum_extra:: { headers:: { authorization:: Bearer , Authorization } , TypedHeader } ;
34use serde:: { Deserialize , Serialize } ;
45use steam_rs:: steam_id:: SteamId ;
56
67#[ derive( Serialize , Deserialize ) ]
78pub 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