Регистрация | Войти
Lisp — программируемый язык программирования
vk.com.lisp
Автор: Menschenkindlein - 2013-02-28T13:57:15.000000+04:00
(in-package #:saluto)

(eval-when (:load-toplevel)
  (new-oauth-provider "VK.COM"

;;; ==================================================================

                      :init-values '((provider-name           . "vk.com")
                                     (oauth-host              . "https://oauth.vk.com")
                                     (oauth-path              . "/authorize")
                                     (api-host                . "https://api.vk.com/method")
                                     (query-params            . (("response_type"  . "code")
                                                                 #|("scope"  . "photos,notify")|#
)
)

                                     (access-token-path       . "/access_token")
)


;;; ==================================================================

                      :goto-fun
                      (alexandria:named-lambda goto-fun (module)
                        (if (not (session))
                            (progn
                              (start-session)
                              (redirect (build-goto-path module (session)))
)

                            (redirect "/")
)
)


;;; ==================================================================

                      :receiver-fun
                      (alexandria:named-lambda receiver-fun (module session code error?)
                        (when (invalid-receiver-params? code
                                                        session
                                                        error?
)

                          (logout)
                          (redirect "/")
)


                        (let ((access-token (extract-access-token
                                             (request (prepare-access-token-request module code))
)
)

                              (userinfo-request nil)
                              (userinfo nil)
)


                          (setf userinfo-request
                                (prepare-userinfo-request module access-token)
)

                          (setf userinfo (request userinfo-request))
                          (let ((parsed-userinfo (parse-userinfo module userinfo)))
                            (store-userinfo module parsed-userinfo)
)
)

                        (redirect "/")
)


;;; ==================================================================

                      :prepare-userinfo-fun
                      (alexandria:named-lambda prepare-user-info-fun (module auth-key)
                          (list (concatenate 'string (api-host module) "users.get")
                                :parameters (list (cons "fields" "photo_max")
                                                  (cons "access_token" auth-key)
)

                                :content-length t
                                :method :get
)
)


;;; ==================================================================

                      :parse-userinfo-fun
                      (alexandria:named-lambda parse-userinfo-fun (module answer)
                        (let* ((parsed-answer (first (jsown:parse answer)))
                               (first-name (jsown:val parsed-answer "first_name"))
                               (last-name  (jsown:val parsed-answer "last_name"))
                               (avatar     (jsown:val parsed-answer "photo_max")) ;; may be just "photo"
                               ;; (email      (jsown:val parsed-answer "email"))
                               (uid        (jsown:val parsed-answer "uid"))
)

                          (list :first-name first-name
                                :last-name  last-name
                                :avatar     avatar
                                ;; :email      email
                                :uid        uid
                                :session    (session)
                                :provider   "vk.com"
)
)
)
)
)
@2009-2013 lisper.ru