I'm creating a authentication page on ionic 4 and I need to integrate the google auth to make the process easier.
But I don't want to store the users on firebase, because I have a backend on ruby on rails 5 application.
How to integrate google auth with rails api?
If you have the backend builded in rails you will need to validated the google auth first in the ionic app as explained in here. https://ionicthemes.com/tutorials/about/ionic-google-login#authentication-options you have 3 options, your is The handcrafted way (using your own API/Backend).
After get the authorization token from google you have to send it through your api and validates the token. To validate the token use the gem google-id-token and the your controller should looks like this
token = params[:token]
validator = GoogleIDToken::Validator.new(expiry: 1800)
begin
payload = validator.check(token, client_id)
user_id = payload['sub']
email = payload['email']
picture = payload['picture']
name = payload['name']
head :ok
rescue GoogleIDToken::ValidationError => e
head 404
end
For more information about this gem https://github.com/google/google-id-token
Also for the client_id it should be generated when you create an app in google console.
Related
I would like to add Gmail to my Rails 4 app. So far I have set up everything so user can log in with Google account. I followed this guide.
Now when user tries to log in my Rails 4 app he receives such onscreen :
After "Allow" user is redirected back to my Rails 4 app.
Initializers/omioauth.rb
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, Rails.application.secrets.client_id, Rails.application.secrets.client_secret, {scope: ['email',
'https://www.googleapis.com/auth/gmail.modify'],
access_type: 'offline', client_options: {ssl: {ca_file: Rails.root.join("cacert.pem").to_s}}}
end
All authorization data from Google is located in secrets.yml.
Installed gems:
gem "omniauth-google-oauth2", "~> 0.2.1"
gem "google-api-client"
Question: What are the next steps to implement Gmail API in Rails project? How to retrieve my Gmail inbox content..
So far I haven't found complete and self-explaining guide to do so.
I found Gmail gem, but the guide is very incomplete for Rails begginers.
For example, I installed this gem and then tried to require 'gmail' in rails c . Then I received error uninitialized constance 'gmail'.
Note: I don't need full solution to my problem,but just a push to start going and I could understand idea.
Thanks in advance.
Try to check the Ruby implementation of Gmail API in the Google Documentation itself.
Just complete the steps described in the rest of this page, and you'll have a simple Ruby command-line application that makes requests to the Gmail API.
For more information, you can also check these threads:
How to access the Gmail API with Ruby
google/google-api-ruby-client
Gmail API Client Library for Ruby
Gmail API and Rails – Authorize with OAuth via Omniauth
I am making a simple app in Ruby I need to get User's Email. I am using Google API client for Ruby. I am not able to get User's Email address, I have been researching on this topic for 2 days, and not able to get Email of user after the user sign in. I dont want to do it with Google+ sign in button I want it programmatically. I get authorized by google but then dont know how to retrieve the User Info of signed in user. I tried also tried it with client = Google::APIClient.new but i was not able. Below is my Code. I will appreciate your help.
scopes = ['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.readonly', 'https://www.googleapis.com/auth/plus.login','https://www.googleapis.com/auth/userinfo.email']
client_secrets = Google::APIClient::ClientSecrets.load(SECRETS_PATH)
auth_client = client_secrets.to_authorization
auth_client.update!(
:additional_parameters => {"access_type" => "offline"}
)
auth_client.update!(
:scope => scopes,
:redirect_uri => 'http://localhost:3000/google_oauth2')
Hey On this You can Refer the Gem Google Plus
I have implemented the same and It's Working Fine from these sides.
Steps to Integrate Following Gem-
Firstly Install the google_plus gem by including it on GemFile.
Generate the API Key from Google Console of Google Plus +
https://console.developers.google.com
Including it Before use like it
GooglePlus.api_key = 'your key'
Search any Person by Id of Google
person = GooglePlus::Person.get(123)
You will get the complete users info for particular users
I know that there is Koala gem for Rails to work with Facebook. I need to make clear 2 things:
How to check if some access_token is valid in Rails using Koala (or something else)?
How to generate some real access token (using some settings of my app or my login/password) for testing through RSpec?
Thanks in advance.
For #1 Use the Tool https://developers.facebook.com/tools/debug if you don't want to code a test. Otherwise hit this API and verify the response.
https://graph.facebook.com/oauth/access_token_info?client_id={APP_ID}&access_token={ACCESS_TOKEN}
For #2, Koala has a good API for accessing Facebook Test Users, which I recommend for use in Rspec.
We also support the test users API, allowing you to conjure up fake
users and command them to do your bidding using the Graph or REST API:
#test_users = Koala::Facebook::TestUsers.new(:app_id => id, :secret => secret)
user = #test_users.create(is_app_installed, desired_permissions)
user_graph_api = Koala::Facebook::API.new(user["access_token"])
# or, if you want to make a whole community:
#test_users.create_network(network_size, is_app_installed, common_permissions)
You can also create Test User in the App Settings from Facebook, and view thier details from this API :
https://graph.facebook.com/{APP_ID}/accounts/test-users?%20access_token={APP_TOKEN}
Trying to write a facebook app and am attempting authentication. This is a rails 3.1 application
The First redirect where I give facebook my api and it returns a code seems to run well. But when I try to take that code and 'exchange it' from a access_token I run into problems.
The access token appears where the iframe aws.
Here is my code.
def index
#Load facebook.yml info
config = YAML::load(File.open("#{Rails.root}/config/facebook.yml"));
# setup client
redirect_to "https://graph.facebook.com/oauth/authorize?client_id=#{config['development']['app_id']}&redirect_uri=#{CALLBACK_URI}"
end
def callback
logger.debug("c")
config = YAML::load(File.open("#{Rails.root}/config/facebook.yml"));
if (!params.key?('access_token'))
logger.debug("A")
redirect_to "https://graph.facebook.com/oauth/access_token?client_id=# {config['development']['app_id']}&redirect_uri=#{CALLBACK_URI}&client_secret=#{config['development']['client_secret']}&code=#{params['code']}"
return
end
logger.debug("B")
access_token = params['access_token']
#me = FbGraph::User.me(ACCESS_TOKEN)
#name=#me.name
end
end
You are not supposed to redirect the user’s browser to the second endpoint (think for a moment, you are putting your app secret into that URL, so it would be easy for everyone to spot it there) – you are supposed to make a server-side call to that endpoint.
The docs clearly say so, https://developers.facebook.com/docs/authentication/server-side/:
“Once the user has authorized your app, you should make a server side request to exchange the code returned above for a user access token.”
How to use the twitter geo api.
Did you read the Documentation in the link you posted? It says
Requires Authentication : TRUE
Ever since the geoapi shut down, it has been pretty much integrated with the twitter api. The json returned by twitter GET statuses also returns a geo key in the dictionary and geo_enabled key as well.
Here's what you can do to authorize and receive updates via oauth and twitter api (python code)-
from twitter import Twitter
from twitter.oauth import OAuth
def get_feeds(screenName):
twitter = Twitter(auth=OAuth('', '', CONSUMER_KEY, CONSUMER_SECRET))
statuses = twitter.statuses.user_timeline(screen_name=screenName, include_entities=1, include_rts=True)
print "Got Status"
return statuses