-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
212 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pub(crate) mod routes; | ||
pub mod router; | ||
pub(crate) mod routes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* Photos.network · A privacy first photo storage and sharing service for fediverse. | ||
* Copyright (C) 2020 Photos network developers | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
pub mod optuser; | ||
pub mod user; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* Photos.network · A privacy first photo storage and sharing service for fediverse. | ||
* Copyright (C) 2020 Photos network developers | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
//! This extractor checks if an `Authorization` is header and contains a valid JWT token. | ||
//! Otherwise it will respond `Some(None)` to indicate an unauthorized user or a visiter without an account at all. | ||
//! | ||
use crate::model::auth::user::User; | ||
use async_trait::async_trait; | ||
use axum::extract::FromRequestParts; | ||
use http::request::Parts; | ||
|
||
pub struct OptionalUser(pub Option<User>); | ||
|
||
#[async_trait] | ||
impl<S> FromRequestParts<S> for OptionalUser | ||
where | ||
S: Send + Sync, | ||
{ | ||
type Rejection = String; | ||
|
||
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> { | ||
parts | ||
.headers | ||
.get("Authorization") | ||
.and_then(|header| { | ||
let _auth_token = header.to_str().ok(); | ||
|
||
// TODO: verify auth token | ||
Some(Self(Some(User::new("info@photos.network".to_string())))) | ||
}) | ||
.ok_or("".to_string()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* Photos.network · A privacy first photo storage and sharing service for fediverse. | ||
* Copyright (C) 2020 Photos network developers | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
//! This extractor requires an `Authorization` header present with a valid JWT token. | ||
//! Otherwise it will respond with `StatusCode::UNAUTHORIZED` | ||
//! | ||
use async_trait::async_trait; | ||
use axum::extract::FromRequestParts; | ||
use axum::http::StatusCode; | ||
use http::request::Parts; | ||
|
||
use crate::model::auth::user::User; | ||
|
||
#[async_trait] | ||
impl<S> FromRequestParts<S> for User | ||
where | ||
S: Send + Sync, | ||
{ | ||
type Rejection = (StatusCode, &'static str); | ||
|
||
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> { | ||
let _auth_token = parts | ||
.headers | ||
.get("Authorization") | ||
.and_then(|header| header.to_str().ok()) | ||
.ok_or((StatusCode::UNAUTHORIZED, "Unauthorized"))?; | ||
|
||
// TODO: get user for Authtoken | ||
Ok(User::new("info@photos.network".to_string())) | ||
// TODO: verify Token | ||
// verify_auth_token(auth_header) | ||
// .await | ||
// .map_err(|_| (StatusCode::UNAUTHORIZED, "Unauthorized")) | ||
//Err((StatusCode::UNAUTHORIZED, "Unauthorized")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* Photos.network · A privacy first photo storage and sharing service for fediverse. | ||
* Copyright (C) 2020 Photos network developers | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
pub mod extractors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
pub mod user; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pub(crate) mod routes; | ||
pub mod router; | ||
pub(crate) mod routes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
pub(crate) mod get_media; | ||
pub(crate) mod post_media; | ||
pub(crate) mod get_media_id; | ||
pub(crate) mod post_media_id; | ||
pub(crate) mod patch_media_id; | ||
pub(crate) mod delete_media_id; | ||
pub(crate) mod get_albums; | ||
pub(crate) mod post_albums; | ||
pub(crate) mod get_albums_id; | ||
pub(crate) mod get_media; | ||
pub(crate) mod get_media_id; | ||
pub(crate) mod patch_albums_id; | ||
pub(crate) mod patch_albums_id_share; | ||
pub(crate) mod patch_albums_id_unshare; | ||
pub(crate) mod patch_media_id; | ||
pub(crate) mod post_albums; | ||
pub(crate) mod post_media; | ||
pub(crate) mod post_media_id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
/* Photos.network · A privacy first photo storage and sharing service for fediverse. | ||
* Copyright (C) 2020 Photos network developers | ||
* | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
pub struct Location { | ||
pub latitude: f64, | ||
pub longitude: f64 | ||
pub longitude: f64, | ||
} |
Oops, something went wrong.