-
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: allow creators to check the state of each user playing their qu…
…est (#176) This PR: - adds a new endpoint to allow the creators to get all instances of their quests - adds a new endpoint to allow the creators to check the state of each instance - improves auth middleware and error conversion
- Loading branch information
Showing
36 changed files
with
689 additions
and
399 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
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
use actix_web::http::header::HeaderMap; | ||
use dcl_crypto_middleware_rs::signed_fetch::{verify, AuthMiddlewareError, VerificationOptions}; | ||
use std::collections::HashMap; | ||
|
||
pub mod optional_auth; | ||
pub mod required_auth; | ||
|
||
async fn verification( | ||
headers: &HeaderMap, | ||
method: &str, | ||
path: &str, | ||
) -> Result<String, AuthMiddlewareError> { | ||
let headers = headers | ||
.iter() | ||
.map(|(key, val)| (key.to_string(), val.to_str().unwrap_or("").to_string())) | ||
.collect::<HashMap<String, String>>(); | ||
|
||
verify(method, path, headers, VerificationOptions::default()) | ||
.await | ||
.map(|address| address.to_string().to_ascii_lowercase()) | ||
} |
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::Payload, Error, FromRequest, HttpRequest}; | ||
use serde::Deserialize; | ||
use std::{future::Future, pin::Pin}; | ||
|
||
#[derive(Deserialize, Debug, Default, Clone)] | ||
pub struct OptionalAuthUser { | ||
pub address: Option<String>, | ||
} | ||
|
||
impl FromRequest for OptionalAuthUser { | ||
type Error = Error; | ||
type Future = Pin<Box<dyn Future<Output = Result<Self, Self::Error>>>>; | ||
|
||
fn from_request(request: &HttpRequest, _: &mut Payload) -> Self::Future { | ||
let request = request.clone(); | ||
Box::pin(async move { | ||
match super::verification(request.headers(), request.method().as_str(), request.path()) | ||
.await | ||
{ | ||
Ok(address) => Ok(OptionalAuthUser { | ||
address: Some(address), | ||
}), | ||
// since it's optional auth, we do not return unathorization error | ||
Err(_) => Ok(OptionalAuthUser { address: None }), | ||
} | ||
}) | ||
} | ||
} |
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,23 @@ | ||
use actix_web::{dev::Payload, error::ErrorUnauthorized, Error, FromRequest, HttpRequest}; | ||
use serde::Deserialize; | ||
use std::{future::Future, pin::Pin}; | ||
|
||
#[derive(Deserialize, Debug, Default, Clone)] | ||
pub struct RequiredAuthUser { | ||
pub address: String, | ||
} | ||
|
||
impl FromRequest for RequiredAuthUser { | ||
type Error = Error; | ||
type Future = Pin<Box<dyn Future<Output = Result<Self, Self::Error>>>>; | ||
|
||
fn from_request(request: &HttpRequest, _: &mut Payload) -> Self::Future { | ||
let request = request.clone(); | ||
Box::pin(async move { | ||
super::verification(request.headers(), request.method().as_str(), request.path()) | ||
.await | ||
.map(|address| RequiredAuthUser { address }) | ||
.map_err(|_| ErrorUnauthorized("Unathorized")) | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.