虽然降级到gem 'omniauth-oauth2', '~> 1.3.1' 已确认是一种解决方案,但在Doorkeeper's Create-a-OmniAuth-strategy-for-your-provider Wiki Page 中提到,在您实施OmniAuth Strategy for Doorkeeper 时,应使用以下方法:
# https://github.com/intridea/omniauth-oauth2/issues/81
def callback_url
full_host + script_name + callback_path
end
在提到的omniauth-oauth2 issue #81中有很长的讨论
当我尝试使用 Rails 5 Devise-based 客户端应用程序来测试我的 Rails 5 Devise-based Doorkeeper Provider 时,我个人遇到了报告的错误,以允许 Provider 的用户在我的客户端应用程序上连接他们的帐户。
在我的OmniAuth::Strategies::Doorkeeper 中没有提到的方法
在前端 Devise OmniauthCallbacksController 上闪烁消息 Invalid Credentials 并且在客户端应用服务器日志中看到以下错误:
Started GET "/users/auth/doorkeeper" for 127.0.0.1 at 2017-08-22 17:45:02 +0530
I, [2017-08-22T17:45:02.386866 #14535] INFO -- omniauth: (doorkeeper) Request phase initiated.
Started GET "/users/auth/doorkeeper/callback?code=1b833bcc09651f98b0424a7afb1e60bd50fdcc765daf7d499bcefb5554457187&state=c215fd707ecd71c6ad0f6b5e58fa0d2da7210d86946d41e3" for 127.0.0.1 at 2017-08-22 17:45:03 +0530
I, [2017-08-22T17:45:03.506424 #14535] INFO -- omniauth: (doorkeeper) Callback phase initiated.
E, [2017-08-22T17:45:03.523737 #14535] ERROR -- omniauth: (doorkeeper) Authentication failure! invalid_credentials: OAuth2::Error, invalid_grant: 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.
{"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."}
Processing by Users::OmniauthCallbacksController#failure as HTML
Parameters: {"code"=>"1b833bcc09651f98b0424a7afb1e60bd50fdcc765daf7d499bcefb5554457187", "state"=>"c215fd707ecd71c6ad0f6b5e58fa0d2da7210d86946d41e3"}
Redirected to http://localhost:5000/
Completed 302 Found in 0ms (ActiveRecord: 0.0ms)
因此,将这种方法添加到策略中可以被视为替代解决方案。
谢谢。