diff --git a/src/authentication.rs b/src/authentication.rs index 0f0b5ff..b65ff15 100644 --- a/src/authentication.rs +++ b/src/authentication.rs @@ -25,6 +25,7 @@ pub struct UserTokenMetadata { pub struct AuthenticationTokenGranter { pub config: Table, + pub instance: Instance, } impl AuthenticationTokenGranter { @@ -113,14 +114,10 @@ impl AuthenticationTokenGranter { let claims = UserTokenMetadata { user: User { - username: String::from("ambee"), - instance: Instance { - url: String::from("giterated.dev"), - }, - }, - generated_for: Instance { - url: String::from("giterated.dev"), + username: request.username.clone(), + instance: self.instance.clone(), }, + generated_for: raw_request.instance.clone(), exp: (SystemTime::UNIX_EPOCH.elapsed().unwrap() + std::time::Duration::from_secs(24 * 60 * 60)) .as_secs(), diff --git a/src/backend/git.rs b/src/backend/git.rs index ba435da..8c4212d 100644 --- a/src/backend/git.rs +++ b/src/backend/git.rs @@ -43,9 +43,9 @@ impl GitRepository { // Separate function because "Private" will be expanded later /// Checks if the user is allowed to view this repository pub fn can_user_view_repository(&self, user: Option<&User>) -> bool { - !(matches!(self.visibility, RepositoryVisibility::Private) - && self.owner_user.instance.url != user.map_or("", |user| user.instance.url.as_str()) - && self.owner_user.username != user.map_or("", |user| user.username.as_str())) + !matches!(self.visibility, RepositoryVisibility::Private) + || (matches!(self.visibility, RepositoryVisibility::Private) + && Some(&self.owner_user) == user) } // This is in it's own function because I assume I'll have to add logic to this later diff --git a/src/main.rs b/src/main.rs index b8aa26e..0c85f84 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,6 +62,7 @@ async fn main() -> Result<(), Error> { let token_granter = Arc::new(Mutex::new(AuthenticationTokenGranter { config: config.clone(), + instance: Instance::from_str("giterated.dev").unwrap(), })); let user_backend: Arc> = Arc::new(Mutex::new(UserAuth::new(