about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-04-08T20·37+0200
committerVincent Ambo <tazjin@gmail.com>2018-04-08T20·37+0200
commita63bc782b02ac4c784b67ef13da5405183ceeacc (patch)
tree8b5491deec5a8367d0c1e2b5b52153597c45d3c6 /src
parent115f50ae37338450c3533f403a8404a84cfb8670 (diff)
feat(handler): Implement OIDC login & callback handlers
Diffstat (limited to 'src')
-rw-r--r--src/handlers.rs23
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()
+}