gpt4 book ai didi

ruby-on-rails - Mendeley 自定义 OAuth 策略

转载 作者:行者123 更新时间:2023-12-02 04:09:35 29 4
gpt4 key购买 nike

Mendeley有一个很棒的 AP​​I(事实上他们已经使用他们的 API 发起了一场比赛,不过这个问题并不是特定的),它使用 OAuth。

我正在尝试编写一个允许 Mendeley 身份验证的策略,并且在这样做时遇到了很多麻烦..

我去/auth/mendeley,它把我重定向到Mendeley.com,我进行身份验证,然后它把我重定向到一个除了这个之外什么都没有的页面

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



他们提到这是一个 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 的 OmniAuth 插件。结果,我写了一个可以帮助 future 人们的 gem 。它的工作原理与其他 OmniAuth 策略非常相似。

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

关于ruby-on-rails - Mendeley 自定义 OAuth 策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5972048/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com