门德利有一个很好的API (事实上,他们使用API进行了一次竞赛,但这个问题并不是特定的),它使用了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发布于 2012-03-15 05:06:55
发布于 2012-03-14 18:38:56
我知道你很久以前就问过这个问题了,但我自己需要一个OmniAuth插件。因此,我写了一个宝石,应该在未来帮助人们。它的工作原理与其他OmniAuth策略非常相似。
发布于 2011-08-02 00:39:43
通过查看此页,它们似乎支持OAuth 1,但在您的代码中,您的子类是OAuth2。
你确定他们会支持吗?
https://stackoverflow.com/questions/5972048
复制相似问题