2011-05-12 105 views
3

Mendeley有一个很棒的API(事实上他们已经提出了一个使用他们的API的比赛,但这个问题并不是特定的),它使用OAuth。Mendeley自定义OAuth策略

我想写一个战略,让Mendeley认证,和时遇到了不少麻烦这样做..

我去/ auth /中mendeley,它重定向我Mendeley.com,我验证,然后将其重定向我什么也没有它的网页,但这个

{“错误”:“消费者键未找到”}

他们提到这是一个3脚的OAuth,是东西那需要比OAuth通常所做的额外步骤?

以下是我有:

# /config/initializers/omniauth.rb 

module OmniAuth 
    module Strategies 
    # tell omniauth to load the strategy 
    autoload :Mendeley, 'lib/mendeley' 
    end 
end 

# gather oauth credentials from the yml file 
OAUTH = YAML.load_file(File.join(Rails.root, "config", "oauth.yml")) 

# load all the possible oauth strategies 
ActionController::Dispatcher.middleware.use OmniAuth::Builder do 
    provider OmniAuth::Strategies::Mendeley, OAUTH['mendeley']['consumer_key'], OAUTH['mendeley']['consumer_secret'] 
end 

 

# lib/mendeley.rb 

require 'omniauth/oauth' 
require 'multi_json' 

module OmniAuth 
    module Strategies 

    # Omniauth strategy for using oauth2 and mendeley.com 

    class Mendeley < OAuth2 
     def initialize(app, consumer_key = nil, consumer_secret = nil, &block) 
     client_options = { 
      :site => 'http://api.mendeley.com' 
     } 

     super(app, :mendeley, consumer_key, consumer_secret, client_options, &block) 
     end 
    end 
    end 
end 
+0

这不是一个直接的答案,但一些[dev的邮件列表]上(http://groups.google.com/group/ mendeley-open-api-developers /)发现将HTTP方法从POST更改为GET可解决问题。 – 2011-05-12 01:37:00

+0

你是否指定重定向网址? – netbrain 2011-05-30 13:17:50

+0

哪里?在我的代码中,还是在Mendeley应用程序中? – Rabbott 2011-05-30 16:40:46

回答

0

通过查看this page,它看起来像他们所支持的OAuth 1,但在你的代码中继承OAuth2

你确定他们支持吗?

1

我知道你很久以前问过这个问题,但我自己需要一个OmniAuth插件给Mendeley。因此,我写了一本应该帮助人们在未来发展的宝石。它与其他OmniAuth策略非常类似。

https://github.com/fractaloop/omniauth-mendeley

+1

实现的。目前,我有一个针对omniauth的挂起请求https:// github.com/intridea/omniauth/pull/587虽然我不认为他已经在0.3.2上工作了。 – Rabbott 2012-03-15 05:06:05

+1

这个版本是为1.0设计的,应该可以工作人们目前使用的东西。哦〜 – fractaloop 2012-04-30 23:20:23