diff --git a/api/src/auth.rs b/api/src/auth.rs index 073c9374ca..4339ae1eef 100644 --- a/api/src/auth.rs +++ b/api/src/auth.rs @@ -28,13 +28,19 @@ lazy_static! { pub struct BasicAuthMiddleware { api_basic_auth: String, basic_realm: &'static HeaderValue, + ignore_uri: Option, } impl BasicAuthMiddleware { - pub fn new(api_basic_auth: String, basic_realm: &'static HeaderValue) -> BasicAuthMiddleware { + pub fn new( + api_basic_auth: String, + basic_realm: &'static HeaderValue, + ignore_uri: Option, + ) -> BasicAuthMiddleware { BasicAuthMiddleware { api_basic_auth, basic_realm, + ignore_uri, } } } @@ -52,6 +58,11 @@ impl Handler for BasicAuthMiddleware { if req.method().as_str() == "OPTIONS" { return next_handler.call(req, handlers); } + if let Some(u) = self.ignore_uri.as_ref() { + if req.uri().path() == u { + return next_handler.call(req, handlers); + } + } if req.headers().contains_key(AUTHORIZATION) && verify_slices_are_equal( req.headers()[AUTHORIZATION].as_bytes(), diff --git a/api/src/handlers.rs b/api/src/handlers.rs index b64c7c5a7b..14ec832b29 100644 --- a/api/src/handlers.rs +++ b/api/src/handlers.rs @@ -69,8 +69,11 @@ pub fn start_rest_apis( let mut router = build_router(chain, tx_pool, peers).expect("unable to build API router"); if let Some(api_secret) = api_secret { let api_basic_auth = format!("Basic {}", util::to_base64(&format!("grin:{}", api_secret))); - let basic_auth_middleware = - Arc::new(BasicAuthMiddleware::new(api_basic_auth, &GRIN_BASIC_REALM)); + let basic_auth_middleware = Arc::new(BasicAuthMiddleware::new( + api_basic_auth, + &GRIN_BASIC_REALM, + None, + )); router.add_middleware(basic_auth_middleware); }