diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-14 23:17:26 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-14 23:17:26 -0700 |
commit | 2c56f2b65bcf3b3f85db9d2a34501154c9c9404d (patch) | |
tree | d9580fb8578f6e1ea0f47dd1e6402ebd41d3a0e9 /rust/fatcat-api/src/server/auth.rs | |
parent | e468707ee53f4a8ff75b00a1eec44921672464b6 (diff) | |
download | fatcat-2c56f2b65bcf3b3f85db9d2a34501154c9c9404d.tar.gz fatcat-2c56f2b65bcf3b3f85db9d2a34501154c9c9404d.zip |
regenerated and pseudo-integrated
Diffstat (limited to 'rust/fatcat-api/src/server/auth.rs')
-rw-r--r-- | rust/fatcat-api/src/server/auth.rs | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/rust/fatcat-api/src/server/auth.rs b/rust/fatcat-api/src/server/auth.rs new file mode 100644 index 00000000..48dfd7d6 --- /dev/null +++ b/rust/fatcat-api/src/server/auth.rs @@ -0,0 +1,93 @@ +use Api; +use hyper; +use hyper::{Error, Request, Response, StatusCode}; +use server::url::form_urlencoded; +use std::io; +use swagger::auth::{AuthData, Authorization, Scopes}; + +pub struct NewService<T> +where + T: hyper::server::NewService< + Request = (Request, Option<AuthData>), + Response = Response, + Error = Error, + >, +{ + inner: T, +} + +impl<T> NewService<T> +where + T: hyper::server::NewService< + Request = (Request, Option<AuthData>), + Response = Response, + Error = Error, + > + + 'static, +{ + pub fn new(inner: T) -> NewService<T> { + NewService { inner } + } +} + +impl<T> hyper::server::NewService for NewService<T> +where + T: hyper::server::NewService< + Request = (Request, Option<AuthData>), + Response = Response, + Error = Error, + > + + 'static, +{ + type Request = Request; + type Response = Response; + type Error = Error; + type Instance = Service<T::Instance>; + + fn new_service(&self) -> Result<Self::Instance, io::Error> { + self.inner.new_service().map(|s| Service::new(s)) + } +} + +/// Middleware to extract authentication data from request +pub struct Service<T> +where + T: hyper::server::Service< + Request = (Request, Option<AuthData>), + Response = Response, + Error = Error, + >, +{ + inner: T, +} + +impl<T> Service<T> +where + T: hyper::server::Service< + Request = (Request, Option<AuthData>), + Response = Response, + Error = Error, + >, +{ + pub fn new(inner: T) -> Service<T> { + Service { inner } + } +} + +impl<T> hyper::server::Service for Service<T> +where + T: hyper::server::Service< + Request = (Request, Option<AuthData>), + Response = Response, + Error = Error, + >, +{ + type Request = Request; + type Response = Response; + type Error = Error; + type Future = T::Future; + + fn call(&self, req: Self::Request) -> Self::Future { + return self.inner.call((req, None)); + } +} |