Loomio
Tue 4 Jul 2017 1:25AM

Third party logins

GB Gustavo Benjamin Public Seen by 64

Hi!

I would like to know if there is a way to configure/setup the Third party logins (google, facebook) for my loomio site?

Thanks for the great work!

JK

James Kiesel Tue 4 Jul 2017 9:33AM

Hi Gustavo,

Simply set the "{{provider}}_APP_KEY" and "{{provider}}_APP_SECRET" fields in your ENV, and omniauth should take care of the rest.

So, for example, in your .env file you could put

GOOGLE_APP_KEY=app_key
GOOGLE_APP_SECRET=app_secret

to enable login with google. You'll need to search for the individual providers for instructions on how to set up an app with them (it should be straightforward :)). Best of luck!

GB

Gustavo Benjamin Tue 4 Jul 2017 1:33PM

Thank you very much! I will try it!

GB

Gustavo Benjamin Fri 14 Jul 2017 5:03AM

Hi James,

I am now trying to setup the login with google. I followed their instructions, got my client key and secret, set them in my ENV file, and then everything seems ok: I can click on a google buttom, get redirected to google sign in, where I put my google user and pass, google redirects me to

https://loomio.example.com/google/authorize?code=xxxxxxxxxx
(I replaced my real domain with example.com)

but then loomio shows the following error in the browser:

{"error":"Could not connect to google!"}

Any hint on this? From inside the loomio container I could ping google without any problem.

I am attaching the loomio log, where I replaced some sensitive strings. Thanks in advance.

GB

Gustavo Benjamin Mon 17 Jul 2017 9:57PM

Hi everyone,

Problem solved. Had to enable Google People API in Google Developers console, and not Google+ API as almost every tutorial explains. I am really happy now, with google and facebook login working :smiley:.

CJR

Camilo Jose Rojas Tue 18 Jul 2017 3:28AM

Thank Gustavo for the solve.
I had the same problem implemented our own version of loomio in chile.

Regards.

GB

Gustavo Benjamin Tue 18 Jul 2017 9:03PM

Nice to know I wasn't the only one with that problem. I am in Argentina, not so far from you. Trying to implement our own loomio too.

XD

Xavier Dutoit Mon 18 Sep 2017 5:26PM

Hi,

I'm trying to add a twitter oauth. Am I right to understand that I would need to create a new app/controllers/identities/twitter_controller.rb ?

JK

James Kiesel Mon 18 Sep 2017 7:46PM

You're on the right track, yes.

To add an oauth provider, you'll need to add
- A new client which inherits from Clients::Base, Clients::Twitter, which will need to provide (at a minimum) a default host for the api (this will be something like 'https://api.twitter.com/v1/')
- A new controller which inherits from Identities::BaseController, Identities::TwitterController. You'll need to provide at minimum an 'oauth_host' method which points to twitter's oauth endpoint (this will be something like 'twitter.com/oauth/authorize')
- Adding a provider name (in this case 'twitter') to to 'providers.yml', which tells Loomio which providers are active

IIRC twitter has somewhat shoddy support for OAuth2, so that'll be a challenge to work through (I'm pretty sure it's possible though :) )

JK

James Kiesel Mon 18 Sep 2017 7:52PM

Ideally this would go into a plugin, so that it's really easy to apply or remove from any instance. More info on making plugins here.

A plugin for this would look something like this:

module Plugins
module LoomioTwitterOauth
class Plugin < Plugins::Base
setup! :loomio_twitter_oauth do |plugin|
plugin.enabled = true
plugin.use_class 'models/clients/twitter' # define in plugins/loomio_twitter_oauth/models/clients/twitter.rb
plugin.use_class 'app/controllers/identities/twitter_controller' # define in plugins/loomio_twitter_oauth/controllers/identities/twitter_controller.rb
plugin.extend_class AppConfig do
def self.providers
existing = super
existing.merge(providers: existing['providers']
+ ['twitter'])
end
end
end
end
end
end