ElkArte Community

Extending Elk => Addons => Topic started by: Spuds on March 25, 2017, 08:38:04 pm

Title: [ADDON] Social Login and Register
Post by: Spuds on March 25, 2017, 08:38:04 pm
External Authentication / Login / Register using a 3rd party account

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

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

Introduction

Inspired by https://www.elkarte.net/community/index.php?topic=4360.0 and trying on the challenge.  Here is an External Authentication / Login / Register Addon that uses your Social Media account.  This addon builds on the initial work done by @Ant59‍ and at the core it is using HybridAuth (https://hybridauth.github.io/hybridauth/index.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 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

Details

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


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.

Repo / Download

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

Provider Setup
The specifics for providers are always changing.  You will need to do your own legwork/homework on what is required for each.  HybridAuth (https://hybridauth.github.io/hybridauth/) should be your source on how to do those steps.  The following is just a general guide for several providers.  Note the specific steps are often changing so use this as a basic outline to get you going.

Setting up Twitter


Setting up Google


Setting up Yahoo!


Setting up GitHub


Setting up Amazon


Setting up Facebook


Setting up LinkedIn

Title: Re: [ADDON] Social Login and Register
Post by: ahrasis on March 25, 2017, 10:33:19 pm
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 25, 2017, 10:46:56 pm
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, 08:58:30 am
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: Adrek on March 26, 2017, 11:30:25 am
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, 12:00:41 pm
Quote from: ahrasis – 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.
Quote from: phantom – 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, 04:06:09 pm
Nice work!  Will this work for 1.1rc1?
Title: Re: [ADDON] Social Login and Register
Post by: ahrasis on March 26, 2017, 08:17:13 pm
Will test it again soon and report.
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on March 26, 2017, 09:27:38 pm
Quote from: badmonkey – Nice work!  Will this work for 1.1rc1?
No idea TBH !
Title: Re: [ADDON] Social Login and Register
Post by: badmonkey on March 26, 2017, 09:37:49 pm
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 26, 2017, 09:53:28 pm
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 26, 2017, 10:03:25 pm
Quote from: Spuds – 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, 12: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:
QuoteType 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, 03: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, 04: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 28, 2017, 07:05:16 pm
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 28, 2017, 09:42:47 pm
@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, 02:39:45 am
Quote from: Spuds – 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, 02: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, 03: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, 05: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 29, 2017, 08:11:42 pm
I think one of those errors is due to 1.1 vs 1.0.
Quote from: badmonkey – 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 29, 2017, 09:20:21 pm
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, 01: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, 05:44:39 pm
Updated package for ElkArte 1.1
Title: Re: [ADDON] Social Login and Register
Post by: lordmortimer on January 07, 2018, 06:18:53 pm
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, 12: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, 07:56:20 am
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 March 31, 2018, 09:37:27 pm
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, 09:15:08 am
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, 11:09:15 am
I believe so. They changed their api to require it.
Title: Re: [ADDON] Social Login and Register
Post by: moe on August 30, 2019, 02: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, 05: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:
QuoteURL 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, 05: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 August 31, 2019, 07:18:05 pm
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

Quote from: moe – 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, 04:12:39 pm
Quote from: Spuds – 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, 09:31:14 am
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, 10:08:09 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  :-[
Title: Re: [ADDON] Social Login and Register
Post by: john11smith on September 04, 2019, 04:45:13 am
Quote from: Spuds – 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, 05:33:49 am
Quote from: Spuds – 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, 11:33:33 am
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, 02: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, 05: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 13, 2020, 09:02:34 pm
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?  :(
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on May 04, 2021, 02:02:36 pm
Update 1.0.6

o latest v2 hybridauth (I know they are on v3 know but that will be a breaking change)
o fixed for github and several updates for other Providers
o code cleanup, should ow show failure messages when failing to connect to provider
o remove depreciated create function and other php7.4 support

As always its YOU who need to setup the "apps" on the various social media sites you want to support, and the HybridAuth site is going to be your best source of help for that. 

See link in first post or .... https://addons.elkarte.net/feature/External-Auth.html
Title: Re: [ADDON] Social Login and Register
Post by: ksamochkin on May 22, 2021, 06:39:07 am
I think these mods are harmful because most spammers use them successfully
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on November 06, 2022, 04:02:32 pm
Update 1.1.0.  This version now only works with ElkArte 1.1+ and PHP 7.x+  I really should come up with a better name for the addon :man_shrugging:

I have tested / validated this works with Google, Yahoo, Twitter, GitHub, Amazon.  You can register with those sites, or if you already have an site account you can simply "link" them (which allows you to login with a single click).

I have not test FB or LinkedIn.  Last time I looked, FB does not have a simple developer account, you had to do a full register and allow them to do a personal cavity search with their tentacles.  The process should work just like any others, I just can't tell you how to create the FB oAuth app.  Same for linkedin, where  I used to have a account, but they changed their TOS and direction several years ago so I dropped that account, as with FB they were broad in their collection of personal data and loose in using it.


To get the addon you can do one of two things:
Title: Re: [ADDON] Social Login and Register
Post by: ksamochkin on November 25, 2022, 06:43:33 am
syntax error, unexpected 'var' (T_VAR), expecting variable (T_VARIABLE)
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on November 25, 2022, 08:34:31 pm
Did you get a filename or line number where the error occurred?
Title: Re: [ADDON] Social Login and Register
Post by: ksamochkin on November 26, 2022, 01:00:27 am
Quote from: Spuds – Did you get a filename or line number where the error occurred?
no, it does not show, but it is dreary to search by the poke method, I think the creator will figure it out faster
Title: Re: [ADDON] Social Login and Register
Post by: Spuds on November 27, 2022, 10:04:50 am
1.1.1 released