【问题标题】:OAuth2::Error with doorkeeperOAuth2::门卫错误
【发布时间】:2015-10-29 12:43:00
【问题描述】:

每当我尝试通过门卫提供商进行身份验证时,我总是收到以下错误

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."}

我尝试了其他门卫客户端,但仍然有同样的错误

看门人客户端:

  1. https://github.com/doorkeeper-gem/doorkeeper-devise-client.git
  2. http://dev.mikamai.com/post/112508735689/oauth2-on-rails-the-client-application

门卫供应商:

https://github.com/doorkeeper-gem/doorkeeper-provider-app.git

【问题讨论】:

    标签: ruby-on-rails oauth devise doorkeeper


    【解决方案1】:

    我通过将omniauth-oauth2 gem 版本降级到此处提到的1.3.1 解决了这个问题 - https://github.com/intridea/omniauth-oauth2/issues/81

    【讨论】:

      【解决方案2】:

      虽然降级到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)
      

      因此,将这种方法添加到策略中可以被视为替代解决方案。

      谢谢。

      【讨论】:

        猜你喜欢
        • 2012-11-23
        • 1970-01-01
        • 1970-01-01
        • 2015-10-29
        • 1970-01-01
        • 2017-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多