Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sign in users with Google Auth Library for Ruby

I want to sign in users with the google-auth-library-ruby gem.

In their guides "Google Sign-In for server-side apps " they have a good code example how to exchange the authorization code for an ID token, but it's only for Python (and Java):

credentials = client.credentials_from_clientsecrets_and_code(
CLIENT_SECRET_FILE,
['https://www.googleapis.com/auth/drive.appdata', 'profile', 'email'],
auth_code)

Does anybody know about the equivalent for Ruby?

PS. I'm familiar with the omniauth gem, but would like to use the google-auth-library-ruby gem if possible.

like image 860
Fellow Stranger Avatar asked Oct 29 '22 22:10

Fellow Stranger


1 Answers

After some research, I found this collection of samples, where the googleauth gem is used. Here you have it:

client_id = Google::Auth::ClientId.new("your Google client ID", "your Google secret")
scope = ["email","profile"] 
token_store = nil # there are actually already implemented File or Redis token stores
callback_url = "http://localhost:8000"

authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store, callback_url)

credentials = authorizer.get_credentials_from_code(code: "the auth code in the Sign In response")
like image 80
Alejandro Rizzo Avatar answered Nov 08 '22 01:11

Alejandro Rizzo