Mendeley 自定义 OAuth 策略

发布于 2024-11-07 00:28:27 字数 1455 浏览 3 评论 0原文

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

Mendeley has a great API (in fact they have put up a contest using their API, this question is not specific to that though), that uses OAuth.

I am trying to write a strategy to allow Mendeley Authentication, and am having quite a bit of trouble doing so..

I go to /auth/mendeley, it redirects me to Mendeley.com, I authenticate, then it redirects me to a page with nothing on it but this

{"error":"Consumer key not found"}

They mention this is a 3 leg OAuth, is that something that requires an extra step than what OAuth typically does?

Here is what I have:

# /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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

分分钟 2024-11-14 00:28:27

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

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

I know you asked this a long time ago, but I needed an OmniAuth plugin for Mendeley myself. As a result, I wrote a gem that should help people out in the future. It works very similarly to other OmniAuth strategies.

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

九局 2024-11-14 00:28:27

通过查看 此页面,看起来它们支持 OAuth 1,但在您的代码中您继承了 <代码>OAuth2。

你确定他们支持吗?

By looking at this page, it looks like they support OAuth 1, but in your code you subclass OAuth2.

Are you sure they support it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文