Jump to content

Module Release: Facebook login


Recommended Posts

Modules directory: http://modules.processwire.com/modules/facebook-login/

Github: https://github.com/apeisa/FacebookLogin

I didn't have any real reason to build this. I actually started to just browse the documentation of OAuth implementations and discovered that Facebook really does make this easy: http://developers.facebook.com/docs/authentication/server-side/ (header "Example" on bottom of the page) so I decided to implement it. It was also nice way to test the Ryan's method of module that creates page which executes itself (like Ryan's new ServicePages module).

  • Like 10
Link to comment
Share on other sites

Hi apeisa,

i´m not know if i understood that right. With this Module when i login to PW i´. automatically logged in to my facebook account and later for example i could send a posting or a new "newsentry" in my newssection to my facebook profile???

Link to comment
Share on other sites

Nope. This logs you in (or creates a new user) to processwire using Facebook credentials. Similar functionality can be found from these forums for example. What permissions you give your "Facebook users" is up to you.

Link to comment
Share on other sites

(it was late last night ;) )

Agreed. I thought that I build this module in 30 minutes, but it took over 2 hours of tired debugging... :) I haven't looked this with fresh eyes yet, so there might be something totally strange.

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...

Hello all!

Just here to ask if anybody has used this module on recent stable/dev version of Processwire and has experienced some problems.

I'm in pre-production phase of designing an app and this module is needed, and wanted to be sure it stills works as expected :)


Link to comment
Share on other sites

i use it on few hobby sites. works great, but not the most elegant solution.

What do you think could be a better solution to let people register to a pw site with facebook credential?

I'd like to create (just abstracting in my mind right now) a facebook app where users can upload a photo to processwire backend, using their existing facebook informations.

Any suggestions other than your module, @apesia?


Link to comment
Share on other sites

I've installed this module and played a bit to achieve what I'm trying to do. I'm going to explain my situation and relative problems I got.

- What I'm trying to do :

Create a facebook web app (a processwire web page nested inside a facebook tab, let's say this url "myurl/facebook-login") where the user logins (into processwire) through apesia module and (after been redirected to "myurl") can upload a picture inside his pw user page (from a form upload I've created).

So far this is working, user gets created,been redirected, the form works and the image gets uploaded to his profile. Good!

- What I cannot achieve:

After the is redirected I'd like to post to his timeline a picture and a description.

To do this I've slightly modified @apesia module to let user accepts the permission necessary to handle content upload to his timeline.

Here you can find my modification (link).

This works! User get prompted by facebook to accept further permissions.

To post a picture to his timeline I'm playing with facebook's example (here).

Here is the code I'm trying to implement (a simpyfied version just to test it):

  require_once('../fb_sdk/facebook.php'); // THIS IS PLACED CORRECTLY

  $config = array(
    'appId' => '', // APP ID IS PRESENT IN MY CODE
    'secret' => '',// SECRET KEY IS PRESENT IN MY CODE
    'fileUpload' => true,

  $facebook = new Facebook($config);
  $userid = $facebook->getUser();
  $access_token = $facebook->getAccessToken();

  $photo = 'facebook_test.jpg'; // Path to the photo on the local filesystem
  $message = 'Photo upload via the PHP SDK!';

if($userid) {

      // We have a user ID, so probably a logged in user.
      // If not, we'll get an exception, which we handle below.
      try {
      } catch(FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        print_r('User is logged out');
    } else {

      // No user, print a link for the user to login
      // To upload a photo to a user's wall, we need photo_upload  permission
      // We'll use the current URL as the redirect_uri, so we don't
      // need to specify it here.
      print_r('User not found');


And here is the problem :

I've always recieve a " User not found" response, but user shoud be logged by the module....

What am I doing wrong?

Link to comment
Share on other sites

I don't know enough about the Facebook API to know what's wrong here. But I would guess the Facebook authentication is failing and that you need to retrieve an error code or error message from it in order to know why. Does it have some kind of getError() method that you can call? Also your try/catch block is pointless here, as there's nothing with your try/catch block that can throw an exception. But I'm guessing that's just there as a placeholder that you'll be populating later?

Link to comment
Share on other sites

Thanks for your answer ryan,

yes...that try/catch is just there to print out those messages and let me know if login authentication succeded or not :)

I'm still investigatin on what is happening but as far as I can tell the problem is that the token I got (after authenticating the user through apesia module) is different than the one needed to let my app perform further operations.

I have to study fb php sdk better and understand how to let my users authenticate correctly without the need of this module, since (by now) is out of my skills modify it to perform as I need.

Link to comment
Share on other sites

  • 4 weeks later...

There's no frontend vs backend. Just don't give them page-edit permissions. 

Give them permission you've created yourself.

Create a permission `frontend_edit` and create a role `member`.

On the `member` select the `frontend_edit` permission and save the member role.

After this you can assign this role to a person (user). 


In your templates you can use those like this:

if(!$user->hasPermission('frontend_edit')) echo 'no permission';

if(!$user->hasRole('member')) echo 'user is not a member';

Link to comment
Share on other sites

will this work for frontend user registration where the frontend users have no access to the admin area?

This modules authenticate a user giving it a "facebook-login" role.

At that point you can do whatever you want, like Martin suggested.

Link to comment
Share on other sites

  • 2 months later...

I was playing with the module but it doesn't creates new users. For example, If i'm logged with  my processwire "admin" user and enter to myurl/facebook-login/, it adds the "facebook-login" role to the admin user (but the Facebook ID field remains empty). But if i'm not logged in and enter like a guest, it adds the role to the guest user. I was expecting that a new processwire user was created. Am i right?

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

Hi apeisa,

for a hobby horse project of mine - and to learn writing modules - I took the liberty to adapt your module for GitHub registration/login:


GitHub is using OAuth as well, so I had to more or less modify the URLs (and for some reason, giving a stream context to file_get_contents).

Disclaimer: untested so far! Proof of concept.

  • Like 3
Link to comment
Share on other sites

  • 9 months later...
  • 6 months later...


is it possible that this modul create pages instead of users?

What I need is, that at frontend a user can sign in or register for newsletter width his facebook account and I get in site/template facebook-login childs with the username and fields with email, name, id captured from facebook.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...