git.fiddlerwoaroof.com
Browse code

Little toy demo that shows userinfo after login

fiddlerwoaroof authored on 06/11/2015 06:50:41
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,60 @@
1
+(ql:quickload :ningle)
2
+(ql:quickload :clack)
3
+(ql:quickload :cl-oid-connect)
4
+(ql:quickload :cl-who)
5
+(ql:quickload :ubiquitous)
6
+(ql:quickload :clack-errors)
7
+
8
+(defpackage :cl-oid-connect.demo
9
+  (:use :cl :cl-oid-connect.utils :cl-oid-connect :cl-who))
10
+(in-package :cl-oid-connect.demo)
11
+
12
+(defparameter *app* (make-instance 'ningle:<app>))
13
+
14
+(def-route ("/login" (params) :app *app*)
15
+  `(200 ()
16
+    ,(with-html-output-to-string (s)
17
+       (:html (:head (:title "Login"))
18
+        (:body
19
+          (:div :class "login-button facebook"
20
+           (:a :href "/login/facebook" "Facebook"))
21
+          (:div :class "login-button google"
22
+           (:a :href "/login/google" "Google")))))))
23
+
24
+(def-route ("/" (params) :app *app*)
25
+  (declare (ignore params))
26
+  (ningle:with-context-variables (session)
27
+    (require-login
28
+      (redirect-if-necessary session
29
+        (with-endpoints (gethash :endpoint-schema session)
30
+          `(200 (:content-type "application/json")
31
+            ,(cl-json:encode-json-to-string (gethash :userinfo session))))))))
32
+
33
+(cl-oid-connect::setup-oid-connect *app* (userinfo &rest args))
34
+
35
+(let ((handler nil))
36
+  (ubiquitous:restore :whitespace)
37
+  (defun stop () (clack:stop (pop handler)))
38
+
39
+  (defun start (&optional tmp)
40
+    (cl-oid-connect:initialize-oid-connect
41
+      (ubiquitous:value 'facebook 'secrets)
42
+      (ubiquitous:value 'google 'secrets))
43
+    (let ((server (if (> (length tmp) 1)
44
+                    (intern (string-upcase (elt tmp 1)) 'keyword)
45
+                    :hunchentoot)))
46
+      (push (clack:clackup
47
+              (lack.builder:builder
48
+                :backtrace
49
+                :session
50
+                *app*
51
+                )
52
+              :port 9090
53
+              :server server)
54
+            handler)))
55
+
56
+  (defun restart-clack ()
57
+    (do () ((null handler)) (stop))
58
+    (start)))
59
+
60
+