Skip to content

Google Oauth2 Process

incjung edited this page Apr 16, 2018 · 1 revision

Google OAuth2 Process

I would use oauth2 library.

To process Oauth2, you have client-id / client-secret

If you don’t have Google account to access oauth2, Visit the Google API Console to obtain OAuth 2.0 credentials such as a client ID and client secret that are known to both Google and your application.

I will access my google calendar service.

(ql:quickload "oauth2")

(defparameter *client-id* "-----YOURS-----")
(defparameter *client-secret* "-----YOURS-----")
(defparameter *redirect-uri* "urn:ietf:wg:oauth:2.0:oob")
;;; For refreash-key
(defparameter *other* '(("access_type" . "offline")))

(defparameter *redirect*
  (request-code
   "https://accounts.google.com/o/oauth2/auth"
   *client-id*
   :scope "https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/calendar.readonly"
   :redirect-uri *redirect-uri*
   :other *other*))

(format t "~%~%Go to ~A and come back with the code: " *redirect*)


(defparameter *code* (read-line))

(defparameter *token*
  (request-token
   "https://accounts.google.com/o/oauth2/token"
   *code* 
   :redirect-uri *redirect-uri*
   :method :post
   :other `(("client_id" . ,*client-id*)
            ("client_secret" . ,*client-secret*))))

(format t "I got a token:~%~A~%" *token*)

(defparameter access-token (token-string *token*))
(defparameter refresh-token (token-refresh-token *token*))


(defparameter *refreshed-token*
  (refresh-token 
   "https://www.googleapis.com/oauth2/v4/token"
   *token*
   :method :post
   :other `(("client_id" . ,*client-id*)
            ("client_secret" . ,*client-secret*))))

(format t " I get a refreshed token : ~A~%" *refreshed-token*)


;;
;; Returns entries on the user's calendar list.
;; * path-url : /users/me/calendarList
;;
(defun get-users-me-calendarlist (&key params content basic-authorization)
  (rest-call "https://www.googleapis.com/calendar/v3" "/users/me/calendarList" :params params :content content
                                                                               :method :get
                                                                               :accept "application/json"
                                                                               :content-type "application/json"))


(get-users-me-calendarlist :params `(("access_token" . ,access-token)))

google oauth2 process

Clone this wiki locally