-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
8 changed files
with
112 additions
and
56 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
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,28 @@ | ||
use actix_web::{dev::ServiceRequest, web::Data, Error}; | ||
use actix_web_httpauth::extractors::{ | ||
bearer::{BearerAuth, Config}, | ||
AuthenticationError, | ||
}; | ||
use tracing::error; | ||
|
||
pub async fn auth_validator( | ||
req: ServiceRequest, | ||
credentials: BearerAuth, | ||
) -> Result<ServiceRequest, (Error, ServiceRequest)> { | ||
let api_key: &str = req.app_data::<Data<String>>().expect("missing api_key"); | ||
let token = credentials.token(); | ||
|
||
//TODO: Do a constant time comparison | ||
if api_key != token { | ||
error!("authetication failed"); | ||
let config = req | ||
.app_data::<Config>() | ||
.cloned() | ||
.unwrap_or_default() | ||
.scope("v1"); | ||
|
||
return Err((AuthenticationError::from(config).into(), req)); | ||
} | ||
|
||
Ok(req) | ||
} |
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,3 +1,4 @@ | ||
pub mod authentication; | ||
pub mod configuration; | ||
pub mod db; | ||
pub mod encryption; | ||
|
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
Oops, something went wrong.