-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create token helper to fix duplicate code
- Loading branch information
Showing
4 changed files
with
22 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod handler; | ||
pub mod macros; | ||
pub mod token_helper; |
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,15 @@ | ||
use actix_web::http::header::HeaderValue; | ||
|
||
pub fn token_extractor(auth: &str) -> String { | ||
let bearer_str = auth.split(' ').collect::<Vec<&str>>(); | ||
let token_prefix = bearer_str[1].split('.').collect::<Vec<&str>>(); | ||
|
||
token_prefix[1..].join(".") | ||
} | ||
|
||
pub fn is_auth_header_valid(auth_header: &HeaderValue) -> bool { | ||
if let Ok(auth_str) = auth_header.to_str() { | ||
return auth_str.starts_with("bearer") || auth_str.starts_with("Bearer"); | ||
} | ||
false | ||
} |