Mendeley 自定义 OAuth 策略
Mendeley 有一个很棒的 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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道您很久以前就问过这个问题,但我自己需要一个适用于 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
通过查看 此页面,看起来它们支持 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?
自己做的 - 拉取请求: https://github.com/intridea/ omniauth/pull/587/files#diff-13
Did it myself - Pull request: https://github.com/intridea/omniauth/pull/587/files#diff-13