Метод обратного вызова Omniauth-Zendesk-Oauth2
Я использую для авторизации гем Omniauth-Zendesk-Oauth2. Жемчужина отправляет правильный запрос авторизации и показывает экран согласия, как и ожидалось.
Следуя этой документации, я установил свое клиентское приложение oauth и установил URL-адрес обратного вызова на http://localhost:3000/users/auth/zendesk/callback
Я написал функцию обратного вызова в моем OmniauthCallbacksController, но она не собирается выполнять функцию zendesk в OmniauthCallbacksController и каждый раз приводит к сбою
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
Еще несколько деталей:
Вот ссылка для авторизации моего клиентского приложения oauth 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
Нажатие "Разрешить" возвращает код и параметры состояния, но выдает следующие ошибки на сервере.
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)