diff --git a/src/handlers.rs b/src/handlers.rs index a16f73389..ebae7f390 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -12,6 +12,7 @@ use db::*; use actix::prelude::{Addr, Syn}; use futures::Future; use errors::{Result, ConverseError}; +use oidc::*; type ConverseResponse = Box>; @@ -20,6 +21,9 @@ pub struct AppState { /// Address of the database actor pub db: Addr, + /// Address of the OIDC actor + pub oidc: Addr, + /// Compiled templates pub tera: tera::Tera, } @@ -104,3 +108,22 @@ pub fn reply_thread(state: State, input: Form) -> ConverseRes }) .responder() } + +/// This handler initiates an OIDC login. +pub fn login(state: State) -> ConverseResponse { + state.oidc.send(GetLoginUrl) + .from_err() + .and_then(|url| Ok(HttpResponse::TemporaryRedirect() + .header("Location", url) + .finish())) + .responder() +} + +pub fn callback(state: State, data: Form) -> ConverseResponse { + state.oidc.send(RetrieveToken(data.0)) + .from_err() + .and_then(|author| { + Ok(HttpResponse::from(format!("{:?}", author))) + }) + .responder() +}