Omniauth-Zendesk-Oauth2 callback method

问题内容:

I am using Omniauth-Zendesk-Oauth2 gem for authorization. The gem is sending correct authorization request and it is showing consent screen as expected.

Following this documentation I have set my oauth client application and set the callback URL to http://localhost:3000/users/auth/zendesk/callback

I have writen a callback function in my OmniauthCallbacksController but it is not going to zendesk function in OmniauthCallbacksController and going to failure every time

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def zendesk
    puts 'Not Printing this line even'*15
    puts request.env["omniauth.auth"].inspect

    @user = User.from_omniauth(request.env["omniauth.auth"])
    puts @user.inspect

    if @user.persisted?
      sign_in_and_redirect @user
      set_flash_message(:notice, :success, :kind => "Zendesk Connected") if is_navigational_format?
    else
      session["devise.zendesk_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

  def failure
    flash[:integration_error] = I18n.t('integrations.error')
    redirect_to root_path
  end
end

Few more details:

Here is authorization link for my oauth client application
https://devsincsupport.zendesk.com/oauth/authorizations/new?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fusers%2Fauth%2Fzendesk%2Fcallback&client_id=testdev3&scope=read%20write

Clicking ‘Allow’ returns code and state params but give the following errors on server.

Started GET "/users/auth/zendesk/callback?code=70cd4c1e82bb6b2ed2e26df0429d5160ec0af4f4e9b0be0e80ca3752888e140b&state=2822fbaca2e6239d2beea7286f13e88d3906eec2a809d85e" for 127.0.0.1 at 2017-12-11 17:38:12 +0500
I, [2017-12-11T17:38:12.534858 #17393]  INFO -- omniauth: (zendesk) Callback phase initiated.
E, [2017-12-11T17:38:17.018161 #17393] ERROR -- omniauth: (zendesk) Authentication failure! invalid_credentials: OAuth2::Error, invalid_grant: The provided access grant is invalid, expired, or revoked (e.g. invalid assertion, expired authorization token, bad end-user password credentials, or mismatching authorization code and redirection URI).
{"error":"invalid_grant","error_description":"The provided access grant is invalid, expired, or revoked (e.g. invalid assertion, expired authorization token, bad end-user password credentials, or mismatching authorization code and redirection URI)."}
Processing by OmniauthCallbacksController#failure as HTML
  Parameters: 
  {"code"=>"70cd4c1e82bb6b2ed2e26df0429d5160ec0af4f4e9b0be0e80ca3752888e140b", "state"=>"2822fbaca2e6239d2beea7286f13e88d3906eec2a809d85e"}
Redirected to http://localhost:3000/
Completed 302 Found in 2ms (ActiveRecord: 0.0ms)

问题评论:

原文地址:

https://stackoverflow.com/questions/47752851/omniauth-zendesk-oauth2-callback-method

Add a Comment