MCPcopy Index your code
hub / github.com/Firstyear/opensuse-proxy-cache / handle

Method handle

opensuse-proxy-cache/src/auth.rs:23–45  ·  view source on GitHub ↗
(
        &self,
        mut request: tide::Request<State>,
        next: tide::Next<'_, State>,
    )

Source from the content-addressed store, hash-verified

21#[async_trait::async_trait]
22impl<State: Clone + Send + Sync + 'static> tide::Middleware<State> for AuthMiddleware {
23 async fn handle(
24 &self,
25 mut request: tide::Request<State>,
26 next: tide::Next<'_, State>,
27 ) -> tide::Result {
28 let maybe_exp: Option<chrono::DateTime<chrono::offset::Utc>> = request.session().get("exp");
29 if let Some(exp) = maybe_exp {
30 let now = chrono::offset::Utc::now();
31 if exp > now {
32 info!("authenticated session found");
33 let response = next.run(request).await;
34 Ok(response)
35 } else {
36 info!("expired session, redirecting");
37 request.session_mut().remove("exp");
38
39 Ok(tide::Redirect::new("/oauth/login").into())
40 }
41 } else {
42 info!("authenticated NOT found, redirecting");
43 Ok(tide::Redirect::new("/oauth/login").into())
44 }
45 }
46}
47
48pub fn configure_oauth(

Callers 1

do_mainFunction · 0.80

Calls 2

removeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected