ElkArte Community

Extending Elk => Addons => Topic started by: Spuds on March 26, 2017, 01:38:04 am

Title: [ADDON] Social Login and Register
Post by: Spuds on March 26, 2017, 01:38:04 am
Inspired by http://www.elkarte.net/community/index.php?topic=4360.0 and trying on the challange [1]

Here is another External Authentication / Login / Register using your Social Media account.  This addon utilizes the initial work done by @Ant59‍ and at the core it is using HybridAuth (http://hybridauth.github.io/hybridauth/index.html)

Consider this ALPHA level software as it needs testing.  I've done some testing with login and register for all of the supported networks except Facebook as I don't have an ID!

Get it here: http://addons.elkarte.net/feature/External-Auth.html

To use this YOU need to register your site as an "app" at each Social Network Provider that you intend to allow on your site.  Doing this is different but similar for each Social Site, basic instructions and links are below (and also in the Admin section of the addon)  The admin settings for the addon are under Admin -> Members -> Registration -> OAuth Providers

Summary

Allows your users to connect with one click to your ElkArte Forum using their social network accounts.

Supports social networks: Facebook, Twitter, LinkedIn, Google, Yahoo, GitHub

Description

The settings for the addon are under Admin -> Members -> Registration -> OAuth Providers

Each social network will require that you create an external application linking your Web site to their api. These external OAuth applications ensure that users are logging into the correct Web site and allows it to send the user back to the correct Web site after successfully authenticating.

The link to setup your OAuth accounts for these sites is provided in the Admin Panel along with general steps of what to do for each API.  Most important will be the Redirect URIs which is provided in the help for each.

Features


New or Existing User

Existing users should "Connect" their current site account with each of the social networks they intend to use.  They can do this from their profile page Modify Profile -> Connected Accounts. Once done they can simply click the appropriate social icon on the login page and be logged in to the site.

New users can select a social login icon which will begin a registration process that will Connect a new site account to the chosen social site.  They will still have to accept your site agreement and any required profile fields you have enabled including email and userid.

Provider Setup

Setting up Facebook


Setting up Twitter


Setting up Google


Setting up LinkedIn


Setting up Yahoo!


I hope this can be a start for coding multiple social login / registration to ElkArte forum whether using Hybridauth as suggested by @emanuele (http://www.elkarte.net/community/index.php?action=profile;u=2) or something similar/better

Title: Re: [ADDON] Social Login and Register
Post by: ahrasis on March 26, 2017, 04:33:19 am
This is a very good news and in about time. Hopefully, will be a feature in EA.
Title: Re: [ADDON] Social Login and Register
Post by: ahrasis on March 26, 2017, 04:46:56 am
Just installed and tried using proper FB key and secret and get this error:
Quote
"PHP message: PHP Fatal error:  Uncaught Error: Class 'Facebook\Facebook' not found in /var/www/clients/client2/web1/web/sources/ext/hybridauth/Hybrid/Providers/Facebook.php:56
Stack trace:
#0 /var/www/clients/client2/web1/web/sources/ext/hybridauth/Hybrid/Provider_Model.php(99): Hybrid_Providers_Facebook->initialize()
#1 /var/www/clients/client2/web1/web/sources/ext/hybridauth/Hybrid/Provider_Adapter.php(101): Hybrid_Provider_Model->__construct('Facebook', Array, Array)
#2 /var/www/clients/client2/web1/web/sources/ext/hybridauth/Hybrid/Auth.php(277): Hybrid_Provider_Adapter->factory('Facebook', Array)
#3 /var/www/clients/client2/web1/web/sources/ext/hybridauth/Hybrid/Auth.php(229): Hybrid_Auth::setup('Facebook', Array)
#4 /var/www/clients/client2/web1/web/sources/controllers/Extauth.controller.php(205): Hybrid_Auth::authenticate('Facebook')
#5 /var/www/clients/client2/web1/web/sources/controllers/Extauth.controller.php(120): Extauth_Controller->getAdapterProfile()
#6 /var/www/clients/client2/web1/web/sour" while reading response header from upstream, client: 192.168.0.108, server: elkarte.sch.my, request: "GET /index.php?action=extauth;provider=facebook;c8abbad8=029259a6d57c6c874ba645caffc09ca4 HTTP/2.0"
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on March 26, 2017, 02:58:30 pm
Thank you for the FB testing, that was the only one I could not test ... I should be able to figure it out whats going on from that trace :D
Title: Re: [ADDON] Social Login and Register
Post by: phantom on March 26, 2017, 05:30:25 pm
Nice :)

I was playing with HybridAuth for a while but couldn't get it to work (errors that login page cannot be accessed directly etc..)
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on March 26, 2017, 06:00:41 pm
Just installed and tried using proper FB key and secret and get this error:
I've updated the addon (update is in the first post).  This should fix that facebook error.  The provider script was not calling the FB autoloader.  Also updated the FB api to what I think is the latest, well at least what composer pulled down.
Nice :)

I was playing with HybridAuth for a while but couldn't get it to work (errors that login page cannot be accessed directly etc..)
I think that was mainly due to sessions issues ... one of the main things needed to get this to run was include SSI in hybridauth index.php so it uses ElkArte sessions and not default PHP ones.  But yeah this was a bit of a pain to get running !
Title: Re: [ADDON] Social Login and Register
Post by: badmonkey on March 26, 2017, 10:06:09 pm
Nice work!  Will this work for 1.1rc1?
Title: Re: [ADDON] Social Login and Register
Post by: ahrasis on March 27, 2017, 02:17:13 am
Will test it again soon and report.
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on March 27, 2017, 03:27:38 am
Nice work!  Will this work for 1.1rc1?
No idea TBH !
Title: Re: [ADDON] Social Login and Register
Post by: badmonkey on March 27, 2017, 03:37:49 am
Gave it a whirl.  The icons don't show.  Looks like they use fontawesome.  I may look at either including FA or replacing the inclusions with svg.  With your permission of course.
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on March 27, 2017, 03:53:28 am
Ah ... there is a setting (available to addons) in 1.1 to enable FA :D see we did not leave ya hanging ... I can't remember what it is right now but will post back later.
Title: Re: [ADDON] Social Login and Register
Post by: badmonkey on March 27, 2017, 04:03:25 am
Ah ... there is a setting (available to addons) in 1.1 to enable FA :D see we did not leave ya hanging ... I can't remember what it is right now but will post back later.

Really?  Cool!  That's even easier.  Learned something too. 
Title: Re: [ADDON] Social Login and Register
Post by: ahrasis on March 27, 2017, 06:06:34 am
Facebook fixes you did work! Partially though.

It registers the user, ask for username and email is successfully imported into the field with choice to be make it public. Continue from that the user cannot login to EA, though user's details are listed in members list already.

One more thing, I kinda get this while uninstall the previous package:
Quote
Type of error: General
file_get_contents(/var/www/clients/client2/web1/web/themes/default/css/Extauth.css): failed to open stream: No such file or directory
https://www.sch.my/index.php?action=admin;area=packages;sa=uninstall2;package=elk_external_auth.zip;pid=410
Apply Filter: Only show the errors from this file File: /var/www/clients/client2/web1/web/sources/SiteCombiner.class.php
Line: 344

Type of error: General
filemtime(): stat failed for /var/www/clients/client2/web1/web/themes/default/css/Extauth.css
https://www.sch.my/index.php?action=admin;area=packages;sa=uninstall2;package=elk_external_auth.zip;pid=410
/var/www/clients/client2/web1/web/sources/SiteCombiner.class.php
Line: 268

The above could be due to me restoring the old 1.0.9 without the fixes already given in 1.0.10 test package. I'll check it out.
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on March 28, 2017, 09:55:26 pm
Well I had to register for a temporary FB account to test this  :(

Selecting FB to register, I was redirected to FB to approve the connection.
I approved it and was directed back to the ElkArte registartion screen with the email (from FB) filled in as expected. 
I entered a username accepted the agreement and clicked register with FB.

At that point I was logged in and my account on the ElkArte had my FB avatar and a few other details, so everything seemed to work as expected for me.  The only thing I can think of is that you did not have the correct Valid OAuth redirect URIs filled out in the FB app?

My FB app has
Client OAuth Login: yes 
Web OAuth Login Yes
Force Web OAuth Reauthentication: No
Embedded Browser OAuth Login: No
Valid OAuth redirect URI: http://YOUR-SITE/sources/ext/hybridauth?hauth_done=Facebook
Login from Devices: No

I would not worry about that CSS file error, just a problem from me updating packages.
Title: Re: [ADDON] Social Login and Register
Post by: radu81 on March 28, 2017, 10:31:53 pm
I did not test the addon, but what happens if there are mandatory custom fields required in Elkarte registration? Are they ignored? IIRC the ONE all mod for SMF ignores custom fields. 
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on March 29, 2017, 01:05:16 am
It should require you to fill any required (standard or custom) profile fields .... however it does not try to "match" any of those with info that it gets from the social network (like it will with email, member name, avatar etc)
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on March 29, 2017, 03:42:47 am
@badmonkey‍ I updated the package in the first post, it has the font awesome "on" setting for 1.1, so give that a try  :D
Title: Re: [ADDON] Social Login and Register
Post by: radu81 on March 29, 2017, 08:39:45 am
It should require you to fill any required (standard or custom) profile fields ....
That's perfect, most forums works this way  8)
Title: Re: [ADDON] Social Login and Register
Post by: badmonkey on March 29, 2017, 08:49:02 pm
Woohoo!  That works!  Thanks @Spuds

Got FB setup and working.  Giggle has an error when trying link accounts.

Code: [Select]
400. That’s an error.

Error: redirect_uri_mismatch

The redirect URI in the request, http://www.awaycamping.com/sources/ext/hybridauth?hauth.done=Google, does not match the ones authorized for the OAuth client. Visit https://console.developers.google.com/apis/credentials/oauthclient/332790426228-2snqk0f0fc6ofhke81ebkr8ktca15f95.apps.googleusercontent.com?project=332790426228 to update the authorized redirect URIs.


What's wrong here?  Thanks!
Title: Re: [ADDON] Social Login and Register
Post by: badmonkey on March 29, 2017, 09:16:16 pm
Changing the redirect uri to

Code: [Select]
http://www.awaycamping.com/sources/ext/endpoint?hauth.done=Google


got past the uri error to the permissions page.  Click Allow, now a 500 error.   :(

Code: [Select]
2017/03/29 19:33:03 [error] 4323#0: *4933836 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Call to undefined function fatal_error() in /var/www/clients/.../web2/web/sources/controllers/Extauth.controller.php on line 243" while reading response header from upstream, client: 137.118....., server: awaycamping.com, request: "GET /index.php?action=extauth;provider=google;sa=auth;member=1;s2d9a0TC4vW=1071ps2d9a........KGh3oVMX HTTP/1.1", upstream: "fastcgi://127.0.0.1:9011", host: "www.awaycamping.com"

Title: Re: [ADDON] Social Login and Register
Post by: badmonkey on March 29, 2017, 11:14:03 pm
Nevermind.  Back to the 400 error.  Not sure what in the world.
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on March 30, 2017, 02:11:42 am
I think one of those errors is due to 1.1 vs 1.0.
Woohoo!  That works!  Thanks @Spuds

Got FB setup and working.  Giggle has an error when trying link accounts.

Code: [Select]
400. That’s an error.

Error: redirect_uri_mismatch

The redirect URI in the request, http://www.awaycamping.com/sources/ext/hybridauth?hauth.done=Google, does not match the ones authorized for the OAuth client. Visit https://console.developers.google.com/apis/credentials/oauthclient/332790426228-2snqk0f0fc6ofhke81ebkr8ktca15f95.apps.googleusercontent.com?project=332790426228 to update the authorized redirect URIs.


What's wrong here?  Thanks!
Double check that the redirect URL you entered in the Google API console is correct. 


Some of the other errors (the fatal error error) is due to 1.0 vs 1.1 ...
Title: Re: [ADDON] Social Login and Register
Post by: badmonkey on March 30, 2017, 03:20:21 am
Thanks spuds.  *Thought* I had entered that as a redirect addy.  Apparently not!  ;D 

The 500 error is gone when attempting to connect.  Permissions are granted, redirected back to the site, but the button still says Connect Using Google. 

There is a 500 error if attempting to register using Google. 
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on March 30, 2017, 07:53:09 pm
I'm going to guess the 500 error is some other 1.1 issue ... I'll take a look 
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on November 26, 2017, 11:44:39 pm
Updated package for ElkArte 1.1
Title: Re: [ADDON] Social Login and Register
Post by: lordmortimer on January 08, 2018, 12:18:53 am
Is anybody using this mod successfully for facebook? I'm constantly running into errors and fb's docs are not helpful.

Currently I'm having these issues:


I'm using Elk 1.0.10 (waiting for Spuds' SimplePortal mod to be complete :) ) and SP Beta 2. I still have to pass the fb app review 'cause it must be perfectly functional, perfectly this, perfectly that.

Thank you ;)
Title: Re: [ADDON] Social Login and Register
Post by: ahrasis on January 08, 2018, 06:19:10 am
Last time I tested , I think it was working, but I can't remember whether I was testing it in EA 1.0 or 1.1.

About SP, I think it is working too.
Title: Re: [ADDON] Social Login and Register
Post by: hartiberlin on January 19, 2018, 01:56:20 pm
Does this also store the email adress of the user that logs in e.g. via Facebook ?

I want to have all valid email adresses of all users on my forum, so I can send them from time to time
some newsletters, without getting too many bounced emails due to faked email adresses..or just no email adresses
if they login just via Facebook ?
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on April 01, 2018, 03:37:27 am
Sorry for the late reply ... yes it gets the Email address form FB or whatever login providers you use ... It will be the email address they signed up with for FB or Google or Yahoo etc ...
Title: Re: [ADDON] Social Login and Register
Post by: Ziggy on March 07, 2019, 03:15:08 pm
Am I right in saying Facebook only allows you to connect to ssl/https sites?
Title: Re: [ADDON] Social Login and Register
Post by: vbgamer45 on March 12, 2019, 04:09:15 pm
I believe so. They changed their api to require it.
Title: Re: [ADDON] Social Login and Register
Post by: moe on August 30, 2019, 08:10:05 am
I tried to use it on elkarte v1.16, but it returned an HTTP 500 error. : -  [  Github, Google, Yahoo's api redirect url is correct, I don't know why. :(
At first I thought it was a permission issue. Later I changed the permissions of all files to 777, but I still couldn't solve the problem. :(
Title: Re: [ADDON] Social Login and Register
Post by: john11smith on August 31, 2019, 11:39:20 pm
Hi, Thanks for the great work you guys doing!
I have just installed a test forum version: 1.1.6 https://www.elkarte.xxis.lt (https://www.elkarte.xxis.lt)
And struggle to configure facebook. Looks like all set on the forum and Facebook but after pressing Facebook buttun I'm getting error:
Quote
URL blocked: This redirect failed because the redirect URI is not white-listed in the app's client OAuth settings. Make sure that the client and web OAuth logins are on and add all your app domains as valid OAuth redirect URIs.
That is no surprise, because https://elkarte.xxis.lt/hybridauth/endpoint?hauth_done=Facebook (https://elkarte.xxis.lt/hybridauth/endpoint?hauth_done=Facebook) leads to nowhere, there isn't even folder named hybridauth in forum's root directory.
Am I doing something wrong or plugin just incompatible?
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on August 31, 2019, 11:56:30 pm
I'm taking a look now to see if anything has changed .... Unfortunately I have no longer have a facebook account to test with.

There should be a hybridauth directory under your sources/ext path, if not something did not install correctly.
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on September 01, 2019, 01:18:05 am
hybridauth was updated to v2.15, the version in the mod was v2.13.   There really was not much of note in the update, but it is supposed to use a newer version of FB graph api ( 2.12 from 2.8 ) so that *may* make a difference.

I've updated the addon and pushed a 1.0.4 release to the addon site, so give that a whirl.

Also check this: https://help.sharetribe.com/en/articles/1317674-how-to-solve-the-url-blocked-this-redirect-failed-because-facebook-login-error

I tried to use it on elkarte v1.16, but it returned an HTTP 500 error. : -  [  Github, Google, Yahoo's api redirect url is correct, I don't know why. :(
At first I thought it was a permission issue. Later I changed the permissions of all files to 777, but I still couldn't solve the problem. :(
Check your server error log, a 500 is an error from the webserver so it should have logged the reason.  We need that to do much.
Title: Re: [ADDON] Social Login and Register
Post by: john11smith on September 01, 2019, 10:12:39 pm
I'm taking a look now to see if anything has changed .... Unfortunately I have no longer have a facebook account to test with.

There should be a hybridauth directory under your sources/ext path, if not something did not install correctly.

I have configured google also. Regarding redirect uri google explained better, so I authorized https://elkarte.xxis.lt/sources/ext/hybridauth?hauth.done=Google (https://elkarte.xxis.lt/sources/ext/hybridauth?hauth.done=Google) instead of https://elkarte.xxis.lt/hybridauth?hauth.done=Google (https://elkarte.xxis.lt/hybridauth?hauth.done=Google)
It alowed me to go alittle further and get error message from the forum "An Error Has Occurred" "Class 'Error_Context' not found"
In the same manner, adjusted Facebook to uri  https://elkarte.xxis.lt/sources/ext/hybridauth?hauth_done=Facebook (https://elkarte.xxis.lt/sources/ext/hybridauth?hauth_done=Facebook) and getting the same "An Error Has Occurred" "Class 'Error_Context' not found"
p.s. the latest version of Hybridauth is 3.0.0 https://hybridauth.github.io/install.html (https://hybridauth.github.io/install.html)
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on September 02, 2019, 03:31:14 pm
Well that one sounds like my bug, drat !!!

Yeah I knew they finally released HBA 3.0 stable, I just did not want to do that migration yet.  2.x really does everything needed.
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on September 02, 2019, 04:08:09 pm
Please replace the Extauth.controller.php in your sources/controller directory with the one attached here.  This should fix the error context error, but we have to see if there is yet another error after that before I release this again  :-[
Title: Re: [ADDON] Social Login and Register
Post by: john11smith on September 04, 2019, 10:45:13 am
Please replace the Extauth.controller.php in your sources/controller directory with the one attached here.  This should fix the error context error, but we have to see if there is yet another error after that before I release this again  :-[
No still not good, the same error. Tested on PC and mobile.
Title: Re: [ADDON] Social Login and Register
Post by: moe on September 04, 2019, 11:33:49 am
Please replace the Extauth.controller.php in your sources/controller directory with the one attached here.  This should fix the error context error, but we have to see if there is yet another error after that before I release this again  :-[
I got the same error as john11smith --------Class 'ErrorContext' not found.
file: /httpdocs/sources/controllers/Extauth.controller.php
Line 428:
Quote
$reg_errors = ErrorContext::context('register', 0);

Title: Re: [ADDON] Social Login and Register
Post by: Spuds on September 04, 2019, 05:33:33 pm
OK one more time.  

I believe the error handling to be fixed

I also found that the help text / icon in the settings page was not displaying so that was also fixed.  The helptext is where it tells you the proper endpoint to set for the various providers.

Lastly one optional item that a provider may supply (the information you get back from the various social networks varies and I tried to keep the requested set of permissions to an absolute minimum) is stored in a different location in 1.1, so that should also be fixed.

Attached is a new version of the addon, uninstall your old version and try this one instead.  Report back the new errors!
Title: Re: [ADDON] Social Login and Register
Post by: john11smith on September 04, 2019, 08:42:24 pm
Yes works great and help icon is helpful. Many thanks!
Just noticed another glitch.  Doesn't allow to create a password says user must enter old one, but there is no old password because the user logged uning Google button. Without password, admin canel is not accessible :) I have created a password from another admin account, but weird :D
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on September 04, 2019, 11:32:18 pm
Cool !

Well that is a bit of a glitch, I had not considered that ... I'll have to take a look at the code and see if there is a suitable hook or other way I can let the system know that the user may not have a "site" password when they only used the social login function.   Kind of interesting issue really.
Title: Re: [ADDON] Social Login and Register
Post by: fremzy on March 14, 2020, 02:02:34 am
Hi,

Can someone please help me with this? To be upfront, I'm a complete noob, so some of what's fuzzy to me may be very clear to everyone else. Please indulge me.

I'm trying to connect Elkarte to Facebook so members who have Facebook don't have to login separately to Elkarte once logged into Facebook. I've downloaded and uploaded the package, followed the instructions to set it up on Facebook (created app, added oAuth URL e.t.c..) but when I go to my forum page, I don't see an option to login using Facebook, or anything like that. What am I doing wrong?  :(