Skip to content

Commit

Permalink
Merge branch 'main' into update-user-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sabotack authored Nov 27, 2023
2 parents 7c68899 + 748f786 commit b20f906
Show file tree
Hide file tree
Showing 12 changed files with 598 additions and 87 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ Cargo.lock
.history
.ionide

# End of https://www.toptal.com/developers/gitignore/api/rust,visualstudiocode
# End of https://www.toptal.com/developers/gitignore/api/rust,visualstudiocode
clippy.toml
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ bcrypt = "0.15.0"
[build-dependencies]
tonic-build = "0.10.2"

[lints.clippy]
complexity = "deny"
correctness = "deny"
perf = "deny"
suspicious = "warn"
enum_variant_names = "allow"
2 changes: 1 addition & 1 deletion Ecdar-ProtoBuf
Submodule Ecdar-ProtoBuf updated 2 files
+29 −0 api.proto
+11 −5 services.proto
14 changes: 6 additions & 8 deletions src/api/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ pub fn get_token_from_request<T>(req: &Request<T>) -> Result<String, Status> {
None => return Err(Status::unauthenticated("Token not found")),
};

if token.is_ok() {
Ok(token.unwrap().trim_start_matches("Bearer ").to_string())
if let Ok(tok) = token {
Ok(tok.trim_start_matches("Bearer ").to_string())
} else {
Err(Status::unauthenticated(
"Could not read token from metadata",
Expand All @@ -101,13 +101,11 @@ pub fn get_token_from_request<T>(req: &Request<T>) -> Result<String, Status> {
/// This method is used to validate a token (access or refresh).
/// It returns the token data if the token is valid.
pub fn validate_token(token: String, is_refresh_token: bool) -> Result<TokenData<Claims>, Status> {
let secret: String;

if is_refresh_token {
secret = env::var("REFRESH_TOKEN_HS512_SECRET").expect("Expected HS512_SECRET to be set.");
let secret = if is_refresh_token {
env::var("REFRESH_TOKEN_HS512_SECRET").expect("Expected HS512_SECRET to be set.")
} else {
secret = env::var("ACCESS_TOKEN_HS512_SECRET").expect("Expected HS512_SECRET to be set.");
}
env::var("ACCESS_TOKEN_HS512_SECRET").expect("Expected HS512_SECRET to be set.")
};

let mut validation = Validation::new(Algorithm::HS512);

Expand Down
Loading

0 comments on commit b20f906

Please sign in to comment.