Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Google as an oauth provider and refactorings #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

eipplusone
Copy link

@eipplusone eipplusone commented May 29, 2018

Routes are now less provider dependent.
github.clj deprecated in favor provider-agnostic oauth.clj.
Indentation changes according to https://github.com/bbatsov/clojure-style-guide.

In order to test the changes on would need to register on https://console.developers.google.com/apis/credentials.

Routes are now less provider dependent.
github.clj deprecated in favor provider-agnostic oauth.clj
Indentation changes according to https://github.com/bbatsov/clojure-style-guide
:embedly-key "embedly api key"
;; for avatar and file uploads
;; :aws-domain
"braid.mysite.com"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the key here is commented out but not the value

Copy link
Contributor

@jamesnvc jamesnvc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! I made some stylistic comments; I'll give it a test run later today.

:on-click (fn [e]
(.preventDefault e)
; must use dispatch-sync
; b/c dispatch triggers pop-up blocker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should probably be ";;" comments so they're aligned with the code (I see that the were single-; before, but if we're fixing the indent, should do this as well)

[braid.core.server.util :refer [map->query-str ->transit transit->form]])
(:import
(org.apache.commons.codec.binary Base64)))
(ns braid.core.server.api.github)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably this file should just be deleted?

(org.apache.commons.codec.binary Base64)))

(defn- config-oauth-get [key provider]
(let [oauth-paramater-list (-> config :oauth-provider-list edn/read-string)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be parameter list, not paramater list?

[code state provider]
(let [info (transit->form (Base64/decodeBase64 state))]
(when (and (map? info)
; TODO: use spec to validate state when we can use 1.9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change comment to ";;" & fix indent

:data (->> [::nonce ::sent-at ::register? ::group-id]
(map info)
string/join)})
; Was the request from the last 30 minutes?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change comment to ";;" & fix indent

[code state provider]
(let [info (transit->form (Base64/decodeBase64 state))]
(when (and (map? info)
; TODO: use spec to validate state when we can use 1.9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change comment to ";;" & fix indent

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate

[braid.core.server.routes.helpers :refer [current-user error-response edn-response]]
[braid.core.server.s3 :as s3]
[braid.core.server.sync :as sync]))
(:require [braid.core.common.util :refer [valid-email? valid-nickname?]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're trying to incrementally change the ns form to be like this; could you change this to a newline after the :require?

@@ -1,6 +1,7 @@
(ns braid.core.server.routes.client
(:require
[braid.core.server.api.github :as github]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this require be removed now (does the github ns contain anything anymore)?

;; for link info extraction
:embedly-key "embedly api key"
;; for oauth
{:oauth-provider-list {:github {:auth-uri "https://github.com/login/oauth/authorize?"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be unwrapped (:oauth-provider-list ..., not {:oauth-provider-list ...)

@jamesnvc
Copy link
Contributor

Something we'll have to figure out for this...this puts a nested map in the env for oauth-provider-list, which works when getting env from the profiles.clj, but for deployment we pass those values in as environment variables, and so they can only be strings.

Simple solution: Something we've done for other things with the same issue is pass the map in as a string and have the place where the value is used call edn/read-string if the value is a string.

More complicated but probably ultimately better solution: Switch to using config instead of environ for config things (we've used it for other projects & I generally like it).

(if-let [{:keys [access_token]} (oauth/exchange-token code state provider)]
(let [email (oauth/email-address access_token provider)
user (user/user-with-email email)]
(def access_token access_token)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should probably be deleted?

@jamesnvc
Copy link
Contributor

This could also use a bit of documentation as to what exactly one has to do in the Google developer console -- I assume one needs the "People" API enabled to get the email address?

@jamesnvc
Copy link
Contributor

This isn't working for me; when I try to register with the Google OAuth, things fail in the handler because the email is null -- presumably there's some specific API I need to enable on the Google Dev console to make this work?

@eipplusone
Copy link
Author

Environ already reads the map from profiles as a string so there's edn/read-string in the parsing logic already. The bigger pain is having to enter that map as a string on the console, so maybe a file name with that map being expected is a better solution. What do you think @jamesnvc?

And yes, People API needs to be enabled for the project.

@jamesnvc
Copy link
Contributor

jamesnvc commented Jun 2, 2018

I wonder if it might make more sense to just have env keys for, e.g. :github-client-id, :google-client-secret, etc & put the other keys, with the URIs in code, since the code depends on knowledge of what to do with the returned values anyway.

@jamesnvc
Copy link
Contributor

jamesnvc commented Jun 2, 2018

Ah, and trying to get this working, the error message from Google API call seems to indicate that the Google+ API needs to be enabled for the key. This should probably be documented somewhere...maybe in the module docstring?

EDIT: or maybe there's something else I'm missing? I added the Google+ API to a test app, but when I try to use the Google button to register on Braid, it fails & I can see the response from google is:

{:error {:errors [{:domain "global", :reason "notFound", :message "Not Found"}],
            :code 404, :message "Not Found"}}

Not sure why this is happening...@eipplusone what did you have to do to get it working for you?

@eipplusone
Copy link
Author

Let me write/test it with config changes. I don't think the request makes it to the right api endpoint. It's just a guess though, I haven't seen this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants