I am a beginner creating a web application with Rails. I originally created an authentication function that does not use divise, and tried to add an SNS authentication function, but it does not work.
I tried to set the Callback URL on twitter, but I can't register because it is said to be invalid if it is local.
I could register the URL of the production environment, but when I access/auth/twitter, I get a 404 error.
I also tried google, but when I access/auth/google_oauth2 locally, I get the error No route matches [GET] "/ auth/google_oauth2".
It was rails 5 series at the time of creating the application, but I updated to rails 6 on the way. At that time, there may have been something that wasn't going well.Applicable source code
* It is actually entered in the<>part.
GOOGLE_CLIENT_ID = "<ID>" GOOGLE_CLIENT_SECRET = "<SECRET>" TWITTER_KEY = '<KEY>' TWITTER_SECRET = '<SECRET>'
Rails.application.config.middleware.use OmniAuth :: Builder do provider: google_oauth2, ENV ['GOOGLE_CLIENT_ID'], ENV ['GOOGLE_CLIENT_SECRET'] provider: twitter, ENV ["TWITTER_KEY"], ENV ["TWITTER_SECRET"] end
oauth (0.5.4) oauth2 (1.4.4) faraday (>= 0.8,<2.0) jwt (>= 1.0,<3.0) multi_json (~>1.3) multi_xml (~>0.5) rack (>= 1.2,<3) omniauth (1.9.1) hashie (>= 3.4.6) rack (>= 1.6.2,<3) omniauth-google-oauth2 (0.8.0) jwt (>= 2.0) omniauth (>= 1.1.1) omniauth-oauth2 (>= 1.6) omniauth-oauth (1.1.0) oauth omniauth (~>1.0) omniauth-oauth2 (1.6.0) oauth2 (~>1.1) omniauth (~>1.9) omniauth-rails_csrf_protection (0.1.2) actionpack (>= 4.2) omniauth (>= 1.3.1) omniauth-twitter (1.4.0) omniauth-oauth (~>1.1) rack
What I tried
get '/ login', to: 'sessions # new' post '/ login', to: 'sessions # create' get 'auth /: provider/callback', to: 'sessions # create' get 'auth/failure', to: redirect ('/') delete '/ logout', to: 'sessions # destroy'
I have set the environment variables for the production environment.
I also restarted the local server. ‥
I reviewed the settings on twitter and google while looking at some sites, but I could not find any problems.
There may be some mistakes regarding twitter because the UI has changed.
When I tried new rails new and connected to http://127.0.0.1:3000/auth/google_oauth2 with the same code, I was successfully redirected to the google authentication page.
What is causing the route error?
Answer # 1
After removing the above gem, the redirect was successful.
- ruby on rails - [rails] google oauth authentication cannot log in in production environment
- ruby - [rails] i want to implement a function to exclude (unlink) group participants
- ruby on rails 5 - i want to use ajax to implement functions (ruby on rails)
- [ruby on rails] i want to implement a follow function, but the like button is not displayed in the view
- ruby on rails - i want to implement a function for administrator users to register luggage for general users in rails
- ruby on rails - [rails] i want to implement a filtering function and display the corresponding items on the list screen
- ruby on rails - i want to implement a login function using devise
- ruby on rails - i want to implement a function (destroy action) that can delete posted messages, but i am getting an active reco
- ruby on rails - how to implement a sort function by the value of the statistical column that aggregates the values of related
- ruby on rails - i can't implement the rails like function
- ruby on rails - i want to implement a report function, but i get an actioncontroller :: urlgenerationerror
- ruby on rails - i want to implement a function that returns a line bot stamp
- ruby - i want to implement google authentication/sns authentication without using devise
- ruby on rails - questions about routes
- ruby on rails - i want to display the posted images in a random order (get information from the record)
- ruby on rails - [rails] i'm implementing a search function using form_with, but i'm having trouble with the search results not b
- ruby on rails - i would like to add an automatic address input function to the new registration screen
- ruby - [rails] i want to find the date difference using the model created_at
- ruby on rails - i want to resolve rails wrong number of arguments
- ruby - rails causes activerecord :: recordnotfound and routing error at the same time