2011-05-12 9 views
3

Mendeleyには素晴らしいAPIがあります(実際にはAPIを使用してコンテストを開催していますが、この質問はOAuthを使用しています)。私はMendeley認証を許可するための戦略を記述しようとしていますし、トラブルのかなりのビットがそう持っていますMendeleyカスタムOAuth戦略

..

は私が/認証/ mendeley、それはMendeley.comに私をリダイレクトし、私が認証するために行きます、それはそれで何もページに私をリダイレクトしますが、この

{「エラー」:「が見つかりませんコンシューマーキー」}

彼らはこれが3脚のOAuthで言及は、そのものですOAuthの通常の処理よりも余計な作業が必要です。彼らはOAuthの1をサポートするように

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

これは直接の答えではなく、[devメーリングリスト]にいくつかの(http://groups.google.com/group/ mendeley-open-api-developers /)は、HTTPメソッドをPOSTからGETに変更することで問題が解決されることを発見しました。 –

+0

リダイレクトURLを指定していますか? – netbrain

+0

どこ?私のコード内で、またはMendeleyアプリ内で? – Rabbott

答えて

0

this pageで見ることによって、それが見えますが、あなたのコードでは、あなたはOAuth2をサブクラス:ここ

は私が持っているものです。

本当にサポートしていますか?

1

私はあなたにこの前に尋ねたことは知っていますが、MendeleyのためのOmniAuthプラグインが必要でした。その結果、私は将来人々を助けるはずの宝石を書きました。他のOmniAuth戦略と非常によく似ています。

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

+1

現時点では、匿名用の保留中のプルリクエストがあります。 github.com/intridea/omniauth/pull/587私は彼がもう0.3.2で作業しているとは思わない。 – Rabbott

+1

このバージョンは1.0向けに設計されており、人々が最近何を使用しているのかを理解する必要があります。ああよく〜 – fractaloop