Clojure中的OAuth1

Ric*_*fer 6 rest oauth clojure

我正在尝试使用Clojure与API(Context.IO)集成.Context.IO使用OAuth 1,它需要通知消费者密钥和消费者秘密凭证以进行集成.

我已经设法使用请求库(https://github.com/request/request)与Context.JS一起使用Context.IO .结果很简单,只是在对象中填充了consumer_key和consumer_secret,并在请求中的oauth参数中传递了它.

var oauth   = 
{
  consumer_key: 'dsfdfssdf',
  consumer_secret: 'dasfsafdsf'
};

request.post( { url:url, oauth:oauth } )
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试使用clj-oauth https://github.com/mattrepl/clj-oauth完成相同的工作,但我有点迷失,因为它需要太多不同的参数(对于更复杂的用例,我猜),而我正在努力想弄清楚如何做到这一点.

要添加更多信息,Context IO仅将OAuth用于API身份验证,而不是用户授权.因此,它不需要通知令牌,也不需要提供令牌.它只需要消费者密钥和签名(这里描述的相同:dev.twitter.com/oauth/overview/creating-signatures).

有人能给出一个类似我在Node中使用Clojure或clj-oauth(或任何其他库)完成的示例吗?我还没有找到办法.

谢谢!

Red*_*ins 5

我注册了上下文io来试试这个问题.首先,在莱宁根,我成立了

:dependencies [[org.clojure/clojure "1.6.0"]
                 [clj-oauth "1.5.2"]
                 [clj-http "1.1.2"]] 
Run Code Online (Sandbox Code Playgroud)

作为我的依赖.下面有两个例子.一个调用没有任何参数的url,另一个调用相同的url,但是使用参数.

(ns scratch.core
  (:require [oauth.client :as oauth]
            [clj-http.client :as http]))

(def okey "key")

(def osecret "secret")

(def consumer (oauth/make-consumer okey
                                   osecret
                                   nil
                                   nil
                                   nil
                                   :hmac-sha1))

(defn test-get []
  (let [credentials (oauth/credentials consumer
                                       nil
                                       nil
                                       :GET
                                       "https://api.context.io/lite/users")]
    (http/get "https://api.context.io/lite/users" {:query-params credentials})))

(defn test-get-params []
  (let [params {:email "blah@blah.com"}
        credentials (oauth/credentials consumer
                                       nil
                                       nil
                                       :GET
                                       "https://api.context.io/lite/users"
                                       params)]
    (http/get "https://api.context.io/lite/users" {:query-params (merge credentials params)})))
Run Code Online (Sandbox Code Playgroud)