3

Mendeley有一个很棒的 AP​​I(事实上他们已经使用他们的 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
4

3 回答 3

1

我知道你很久以前就问过这个问题,但我自己需要一个用于 Mendeley 的 OmniAuth 插件。结果,我写了一个可以帮助未来人们的宝石。它的工作原理与其他 OmniAuth 策略非常相似。

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

于 2012-03-14T18:38:56.837 回答
0

通过查看此页面,它们似乎支持 OAuth 1,但在您的代码中您是子类OAuth2

你确定他们支持吗?

于 2011-08-02T00:39:43.310 回答
0

自己做的 - 拉取请求:https ://github.com/intridea/omniauth/pull/587/files#diff-13

于 2012-03-15T05:06:55.657 回答