2011-05-12 103 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