I have my front-end rails app that uses AngularJs too and I also have an api backend also written in Rails (used rails-api
gem). I have implemented login system for this system. Now I want to implement login with facebook/google
. I have searched through internet and so far I found this blog. From this blog, I got the idea of implementing google OAuth 2
in Android with Rails as backend. But In my case I want to implement google OAuth 2
in my front-end app (Rails + Angular) with Rails as backend.
For implementation of google OAuth 2
, Front-end app need to request the token
to google oauth2 authorization server
and I have no idea on how to do it.
Also, Is it good to use rails for requesting the token or I can use Angular for that part. What would be the best practice for this purpose?
First, you need to implement the google login in front-end
. Here is google documentation on implementing google sign-in in javascript
. google will provide you with information on user's profile. After you got the information, you can send it to you service. On server side/Backend you can do whatever with this information. That's on you.
Additionally, this documentation might be helpful for your case.
You could use omniauth-google-oauth2 gem
Main idea is to implement this into Devise
.
Good solution You could find this.
With this solution, it is no problem if You use frontend/backend. So, You should pay attention on next steps:
User Model:
devise :database_authenticatable, ... , :omniauthable
Devise.rb:
config.omniauth :google_oauth2, ENV['GP_key'], ENV['GP_secret'],
{
name: 'google',
scope: 'plus.login, userinfo.email, userinfo.profile,
...
youtubepartner, youtubepartner-channel-audit',
prompt: "select_account"
}
Next steps as in solutions..
In my project it is workable with frontend/backend too. So, if you find difficulties, I will be glad do advice for it solving...
Update: for Android versions of frontend.
You should not do authentication/authorization frontend on Google.
You should do it on backend side.
You could use webtools or other suitable ways for walking around Devise
and Google auth pages
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With