【发布时间】:2018-05-31 15:03:03
【问题描述】:
我使用 Doorkeeper gem 将 OAuth 2 提供程序功能引入我的 Rails 应用程序。我将 gem 添加到 gemfile 中,对其进行配置并尝试发出 post 请求以获取访问令牌,如 documentation 中所述。
我向这个网址发送了帖子请求 - http://localhost:3000/oauth/token 使用此参数:
client_id=c094523a20444ee3362e8eb33e08b5266cfb6486babe9f918c0c88104e67f6c0&client_secret=d6cebe57e475e685beb2401108438991e94f0078152d52a2da4d5f1307a4729c&code=c2f56975ba6970634deef1e256faa5de5b146f794f37b3c59f3b5111d6810ef6&grant_type=authorization_code&redirect_uri=urn:ietf:wg:oauth:2.0:oob
但我得到了错误:
{"error":"invalid_grant","error_description":"The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."}
我的门卫初始化器:
Doorkeeper.configure do
# Change the ORM that doorkeeper will use (needs plugins)
orm :active_record
# This block will be called to check whether the resource owner is authenticated or not.
resource_owner_authenticator do
current_user || warden.authenticate!(scope: :user)
end
end
【问题讨论】:
-
你在使用设计吗?
-
是的,我正在使用设计。 Rails 版本也是 5.1.5 可能很重要。
-
它创建了一个新的令牌,但它没有正确响应。
标签: ruby-on-rails oauth-2.0 doorkeeper