Search code examples
oauth-2.0emacsclojureread-eval-print-loop

Doom Emacs Clojure Google Authorization Code


I run doom emacs in windows 10, for clojure. Based on

Sparkfund google-apps-clj.credentials/get-auth-map

function, the

         _ (println "Please visit the following url and input the code "
                    "that appears on the screen: " auth-url)

Please visit the following url and input the code that appears on the screen: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=1080463043693...www.googleapis.com/auth/spreadsheets "

give me the link in my emacs repl, then i copy & paste the link in my browser, it return a copy-able authorization code 4/1AY0e-g5z1hqNhJtLosomecodezSnx5gEGOk.

Question is, how do i paste the authorization code into my REPL? the repl still stuck in println and i had to Ctrl+C+ Ctrl+C which kills the process.

it's supposed to give token after i got the authorization code. because there's still this code to finish the function. please help?

    auth-code (doto ^String (read-line) assert)
    token-request (doto (.newTokenRequest auth-flow auth-code)
                    assert
                    (.setRedirectUri "urn:ietf:wg:oauth:2.0:oob"))]
(doto (.execute token-request)
  assert)))
(defn get-auth-map
  "Given a google-ctx configuration map, and a list of scopes(as strings),
   creates a URL for the user to receive their auth-code, which is then used
   to receive an authorization map, which the user should store securely"
  [google-ctx scope]
  (let [google-secret (get-google-secret google-ctx)
        auth-flow-builder (doto (GoogleAuthorizationCodeFlow$Builder. http-transport json-factory
                                                                      google-secret scope)
                            (.setAccessType "offline"))
        auth-flow (doto (.build auth-flow-builder)
                    assert)
        auth-request-url (doto (.newAuthorizationUrl auth-flow)
                           assert
                           (.setRedirectUri "urn:ietf:wg:oauth:2.0:oob"))
        auth-url (.build auth-request-url)
        _ (println "Please visit the following url and input the code "
                   "that appears on the screen: " auth-url)
        auth-code (doto ^String (read-line) assert)
        token-request (doto (.newTokenRequest auth-flow auth-code)
                        assert
                        (.setRedirectUri "urn:ietf:wg:oauth:2.0:oob"))]
    (doto (.execute token-request)
      assert)))

Solution

  • it's very silly, I need to input the auth-code after

    Stdin : paste-your-auth-code-here

    located at the bottom of emacs! then press enter

    enter image description here