diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/handlers.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/handlers.rs b/src/handlers.rs index a16f73389fad..ebae7f390e60 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<Future<Item=HttpResponse, Error=ConverseError>>; @@ -20,6 +21,9 @@ pub struct AppState { /// Address of the database actor pub db: Addr<Syn, DbExecutor>, + /// Address of the OIDC actor + pub oidc: Addr<Syn, OidcExecutor>, + /// Compiled templates pub tera: tera::Tera, } @@ -104,3 +108,22 @@ pub fn reply_thread(state: State<AppState>, input: Form<NewPost>) -> ConverseRes }) .responder() } + +/// This handler initiates an OIDC login. +pub fn login(state: State<AppState>) -> ConverseResponse { + state.oidc.send(GetLoginUrl) + .from_err() + .and_then(|url| Ok(HttpResponse::TemporaryRedirect() + .header("Location", url) + .finish())) + .responder() +} + +pub fn callback(state: State<AppState>, data: Form<CodeResponse>) -> ConverseResponse { + state.oidc.send(RetrieveToken(data.0)) + .from_err() + .and_then(|author| { + Ok(HttpResponse::from(format!("{:?}", author))) + }) + .responder() +} |