anchor.diff:  (defmacro assoc-cdr (key alist &optional (test '#'eql)) `(cdr (assoc ,key ,alist :test ,test)))
   
   (defun discover-endpoints (schema discovery-doc-url &key (gat nil gat-p) (gui nil gui-p))
  -  (let ((discovery-document (cl-json:decode-json-from-string (drakma:http-request discovery-doc-url))))
  -
  -    (setf (auth-endpoint schema) (assoc-cdr :authorization--endpoint discovery-document))
  -    (setf (token-endpoint schema) (assoc-cdr :token--endpoint discovery-document))
  -    (setf (userinfo-endpoint schema) (assoc-cdr :userinfo--endpoint discovery-document))
  -
  -    (if gui-p (sheeple:defreply get-user-info ((a schema)) (funcall gui a)))
  -    (if gat-p (sheeple:defreply get-access-token ((a schema) (b sheeple:=string=))
  -                (funcall gat a b)))
  -
  -    schema))
  -
  -; This probably should eventually go?
  -(defmacro with-endpoints (endpoint-schema  &body body)
  -  `(let* ((*endpoint-schema* ,endpoint-schema))
  -     ,@body))
  +  "Discover endpoints on the basis of a discovery document stored at a particular url.
  +   The two keyword arguments define a function to bind to sheeple replies for get-user-token
  +   and get-access-token."
  +  (prog1 schema
  +    (let ((discovery-document (cl-json:decode-json-from-string (drakma:http-request discovery-doc-url))))
  +      (setf (auth-endpoint schema) (assoc-cdr :authorization--endpoint discovery-document)
  +            (token-endpoint schema) (assoc-cdr :token--endpoint discovery-document)
  +            (userinfo-endpoint schema) (assoc-cdr :userinfo--endpoint discovery-document))
  +      (when gui-p
  +        (format t "defining gui-p")
  +        (sheeple:defreply get-user-info ((a schema)) (funcall gui a)))
  +      (when gat-p
  +        (format t "defining gat-p")
  +        (sheeple:defreply get-access-token ((a schema) (b sheeple:=string=))
  +          (funcall gat a b))))))
   
   (defun do-auth-request (endpoint-schema state)
  -  (format t "~%client-id: ~a~%" (auth-endpoint endpoint-schema))
     (drakma:http-request (auth-endpoint endpoint-schema)
                          :redirect nil
                          :parameters `(("client_id" . ,(client-id endpoint-schema))
  
positive.code: (defparameter *goog-info* (sheeple:clone =service-info=))
  (defparameter *endpoint-schema* nil)
  (defparameter *goog-endpoint-schema* (defobject (=endpoint-schema= *goog-info*)))
  
  (defun get-base-url (request)
    (format nil "~a//~a/oidc_callback" (lack.request:request-query-parameters)))
  
  (defproto *fbook-endpoint-schema* (=endpoint-schema= *fbook-info*)
            ((auth-endpoint "https://www.facebook.com/dialog/oauth")
  
negative.code:   (setf (route app "/userinfo.json" :method :get) #'userinfo-route
          (route app "/logout"  :method :get) #'logout-route
          (route app "/login/google" :method :get) #'google-login-entry
          (route app "/login/facebook" :method :get) #'facebook-login-entry
          (route app "/oidc_callback/google" :method :get) (google-callback login-callback)
          (route app "/oidc_callback/facebook" :method :get) (facebook-callback login-callback))
    (lambda (app) (lambda (env) (funcall app env))))
  