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
这不是一个直接的答案,但一些[dev的邮件列表]上(http://groups.google.com/group/ mendeley-open-api-developers /)发现将HTTP方法从POST更改为GET可解决问题。 – 2011-05-12 01:37:00
你是否指定重定向网址? – netbrain 2011-05-30 13:17:50
哪里?在我的代码中,还是在Mendeley应用程序中? – Rabbott 2011-05-30 16:40:46