Невозможно издеваться над Omniauth Google
Я работаю в приложении rails и хочу автоматизировать поток "Login with google" в моем приложении rails.
Вот мой тестовый пример, который я написал до сих пор после поиска в Google. Но вместо того, чтобы брать меня на мою домашнюю страницу, он перенаправляет меня на какой-то другой URL. Не понимаю, почему это происходит.
test 'z' do
Rails.application.env_config["devise.mapping"] = Devise.mappings[:user]
Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:google_oauth2]
stub_omniauth
get '/users/auth/google_oauth2_login'
print @response.body
# it prints: Redirecting to http://www.example.com/users/auth/google_oauth2_login/callback...nil
end
Вот метод
def stub_omniauth
# first, set OmniAuth to run in test mode
OmniAuth.config.test_mode = true
# then, provide a set of fake oauth data that
# omniauth will use when a user tries to authenticate:
OmniAuth.config.mock_auth[:google] = OmniAuth::AuthHash.new({
provider: "google",
uid: "12345678910",
info: {
email: "jesse@mountainmantechnologies.com",
first_name: "Jesse",
last_name: "Spevack"
},
credentials: {
token: "abcdefg12345",
refresh_token: "12345abcdefg",
expires_at: DateTime.now,
}
})
end
Он перенаправляет на http://www.example.com/users/auth/google_oauth2_login/callback...nil