Mendeley自定义OAuth策略 [英] Mendeley Custom OAuth Strategy

查看:104
本文介绍了Mendeley自定义OAuth策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mendeley 具有出色的API(实际上,他们举办了比赛使用他们的API,这个问题并不特定于此),而是使用OAuth.

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.

我正在尝试编写一种策略来允许Mendeley身份验证,但是这样做很麻烦.

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

我转到/auth/mendeley,它将我重定向到Mendeley.com,我进行身份验证,然后将我重定向到一个没有任何内容的页面

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"}

他们提到这是3条腿的OAuth,这是比OAuth通常需要更多步骤的事情吗?

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

这就是我所拥有的:

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

推荐答案

自己解决-拉取请求:

Did it myself - Pull request: https://github.com/intridea/omniauth/pull/587/files#diff-13

这篇关于Mendeley自定义OAuth策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆