Clojure中的OAuth1 [英] OAuth1 in Clojure

查看:118
本文介绍了Clojure中的OAuth1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Clojure与API(Context.IO)集成。 Context.IO使用OAuth 1,它需要通知消费者密钥和消费者秘密凭证与之集成。

I'm trying to integrate with an API (Context.IO) using Clojure. Context.IO uses OAuth 1, which requires to inform consumer key and consumer secret credentials to integrate with.

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

I've manage to work with Context.IO with Node.JS in the past, using request library (https://github.com/request/request). It turn out to be quite simple, just filled consumer_key and consumer_secret in an object and passed it in oauth parameter in the request.

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

request.post( { url:url, oauth:oauth } )

现在我想使用clj-oauth来完成相同的操作 https://github.com/mattrepl/clj-oauth,但我有点失落,因为它需要太多不同的参数(对于更复杂的用例我猜),我很难想出如何做的简单。

Now I'm trying to accomplish the same using clj-oauth https://github.com/mattrepl/clj-oauth, but I'm kinda lost, because it requires too different parameters (for more complex use cases I guess), and I'm having a hard time trying to figure out how to do the simple.

要添加更多信息,上下文IO仅将OAuth用于API认证,而不是用户授权。所以它不需要令牌被通知,也不提供一个。它只需要消费者密钥和签名(同样描述:dev.twitter.com/oauth/overview/creating-signatures)。

To add more information, Context IO uses OAuth only for API Authentication, not user Authorization. So it doesn't require tokens to be informed, neither provides one. It only requires the consumer key and signature (the same described here: dev.twitter.com/oauth/overview/creating-signatures).

有人可以给出类似的例子我在Node中使用Clojure或clj-oauth(或任何其他库)完成了什么?我没有找到办法这样做。

Can someone give an example similar to what I accomplished in Node using Clojure or clj-oauth (or any other library)? I haven't found a way to do so.

谢谢!

推荐答案

我注册了上下文io,首先,在leiningen中我设置

I signed up for context io to give this a go. First, in leiningen I set up

:dependencies [[org.clojure/clojure "1.6.0"]
                 [clj-oauth "1.5.2"]
                 [clj-http "1.1.2"]] 


$ b b

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

as my dependencies. There are two examples below. One calls a url without any parameters, the other calls the same url, but with parameters.

(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)})))

这篇关于Clojure中的OAuth1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆