3

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
thomson_matt
  • 7,473
  • 3
  • 39
  • 47
Rabbott
  • 4,282
  • 1
  • 30
  • 53
  • This isn't a direct answer, but some on [the dev mailing list](http://groups.google.com/group/mendeley-open-api-developers/) have found that changing the HTTP method to GET from POST solves the problem. – William Gunn May 12 '11 at 01:37
  • Do you specify a redirect url? – netbrain May 30 '11 at 13:17
  • Where? within my code, or within the Mendeley app? – Rabbott May 30 '11 at 16:40
  • 3-legged OAuth is the default strategy. The other one is 2-legged, implemented for example by Google http://code.google.com/apis/accounts/docs/OAuth.html#tokensGADomains – asymmetric Aug 02 '11 at 00:29

3 Answers3

1

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

fractaloop
  • 302
  • 1
  • 7
  • 1
    I have a pending pull request for omniauth at the moment https://github.com/intridea/omniauth/pull/587 although I don't think that he's working on 0.3.2 anymore. – Rabbott Mar 15 '12 at 05:06
  • 1
    This version is designed for 1.0, and should work what people are using these days. Oh well~ – fractaloop Apr 30 '12 at 23:20
0

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?

asymmetric
  • 3,800
  • 3
  • 34
  • 52
0

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

Rabbott
  • 4,282
  • 1
  • 30
  • 53