JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Fix authentication

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨cef865c

Showing ⁨⁨3⁩ changed files⁩ with ⁨⁨8⁩ insertions⁩ and ⁨⁨10⁩ deletions⁩

src/authentication.rs

View file
@@ -25,6 +25,7 @@ pub struct UserTokenMetadata {
25 25
26 26 pub struct AuthenticationTokenGranter {
27 27 pub config: Table,
28 pub instance: Instance,
28 29 }
29 30
30 31 impl AuthenticationTokenGranter {
@@ -113,14 +114,10 @@ impl AuthenticationTokenGranter {
113 114
114 115 let claims = UserTokenMetadata {
115 116 user: User {
116 username: String::from("ambee"),
117 instance: Instance {
118 url: String::from("giterated.dev"),
119 },
120 },
121 generated_for: Instance {
122 url: String::from("giterated.dev"),
117 username: request.username.clone(),
118 instance: self.instance.clone(),
123 119 },
120 generated_for: raw_request.instance.clone(),
124 121 exp: (SystemTime::UNIX_EPOCH.elapsed().unwrap()
125 122 + std::time::Duration::from_secs(24 * 60 * 60))
126 123 .as_secs(),

src/backend/git.rs

View file
@@ -43,9 +43,9 @@ impl GitRepository {
43 43 // Separate function because "Private" will be expanded later
44 44 /// Checks if the user is allowed to view this repository
45 45 pub fn can_user_view_repository(&self, user: Option<&User>) -> bool {
46 !(matches!(self.visibility, RepositoryVisibility::Private)
47 && self.owner_user.instance.url != user.map_or("", |user| user.instance.url.as_str())
48 && self.owner_user.username != user.map_or("", |user| user.username.as_str()))
46 !matches!(self.visibility, RepositoryVisibility::Private)
47 || (matches!(self.visibility, RepositoryVisibility::Private)
48 && Some(&self.owner_user) == user)
49 49 }
50 50
51 51 // This is in it's own function because I assume I'll have to add logic to this later

src/main.rs

View file
@@ -62,6 +62,7 @@ async fn main() -> Result<(), Error> {
62 62
63 63 let token_granter = Arc::new(Mutex::new(AuthenticationTokenGranter {
64 64 config: config.clone(),
65 instance: Instance::from_str("giterated.dev").unwrap(),
65 66 }));
66 67
67 68 let user_backend: Arc<Mutex<dyn UserBackend + Send>> = Arc::new(Mutex::new(UserAuth::new(