r0man / oauth-clj

Clojure OAuth library
95 stars 27 forks source link

Etsy flow #16

Closed danielsz closed 10 years ago

danielsz commented 10 years ago

Hi,

I would like to add an Etsy flow along the other services. Since Etsy is OAuth 1, I duplicated the flickr flow, and started adapting it. However, Etsy OAuth is different than the other services in a peculiar way. Most services will ask you the scope for the application when creating the consumer key and secret. Etsy, on the other hand, asks for the scope later, when issuing the request-token call. The problem I encountered is how to pass the scope params. I tried this as a proof of concept, but it doesn't work (scope is ignored):

(defn oauth-request-token
  "Obtain a OAuth request token from Etsy to request user authorization."
  [oauth-consumer-key oauth-consumer-secret oauth-callback]
  (let [request-token ((v1/make-consumer
                         :oauth-consumer-key oauth-consumer-key
                         :oauth-consumer-secret oauth-consumer-secret
                         :oauth-callback oauth-callback
                         :scope ["email_r listings_r"]) {:method :post :url *oauth-request-token-url*})]
    (alter-var-root #'*oauth-authorization-url* (fn [_] (:login-url request-token)))
    request-token))

While if I include the scope in the oauth-request-token-url like so: "https://openapi.etsy.com/v2/oauth/request_token?scope=email_r%20listings_r" I see a signature invalid error when issuing the request-token call.

Help will be appreciated.

https://www.etsy.com/developers/documentation/getting_started/oauth#section_permission_scopes

r0man commented 10 years ago

Hi David,

I think there are two problems at the moement with the oauth-request-token and oauth-access-token fns.

  1. The url parameter to those function should be parsed and query parameters should land in the Ring map. Right now they seem to get ignored during the signing process.
  2. There is no way to pass query params when calling those functions.

I pushed a change that tries to address those problems. Can you try your Etsy calls with the latest master. Something like this:

(oauth-request-token
 url consumer-key consumer-secret
 {:query-params {:scope "email_r listings_r"}})

I hope this helps, Roman.

r0man commented 10 years ago

Pushed one more fix. Please make sure to try it with this one:

https://github.com/r0man/oauth-clj/commit/d1c8b2b585b2812d73b19607093043bdef5b2749

danielsz commented 10 years ago

That did the trick. Thank you very much indeed. I'll issue a pull request with the Etsy flow soon.

danielsz commented 10 years ago

Just one more thing. I need to pass along the callback as well. As it stands, it is set to the default "oob". How should I go about that?

r0man commented 10 years ago

Does this work?

(oauth-request-token
 url consumer-key consumer-secret
 {:query-params {:scope "email_r listings_r"}
  :oauth-callback YOUR-CALLBACK})
danielsz commented 10 years ago

Perfectly. I guess that's that, then. Well done.

danielsz commented 10 years ago

17