Oauth2Login by flydev 👊🏻

OAuth2 login for ProcessWire

Auth2Login for ProcessWire

A Module which give you ability to login an existing user using your favorite thrid-party OAuth2 provider (i.e. Facebook, GitHub, Google, LinkedIn, etc.).. You can login from the backend to the backend directly or render a form on the frontend and redirect the user to a choosen page. Built on top of ThePhpLeague OAuth2-Client lib.

Registration is not handled by this module but planned.

Howto Install


Install the module following this procedure:

Next step, in order to use a provider, you need to use Composer to install each provider.

ie: to install Google, open a terminal, go to your root directory of pw and type the following command-line: composer require league/oauth2-google

Currently implemented providers/packages :

Google :  league/oauth2-google
Facebook: league/oauth2-facebook
Github: league/oauth2-github
LinkedIn: league/oauth2-linkedin

More third-party providers are available there and can be implemented on demand basis.

Howto Use It


First (and for testing purpose), you should create a new user in ProcessWire that reflect your real OAuth2 account information. The important informations are, Last Name, First Name and Email. The module will compare existing users by firstname, lastname and email; If the user match the informations, then he is logged in.

ie, if my Google fullname is John Wick, then in ProcessWire, I create a new user Wick-John with email johnwick@mydomain.com

Next step, go to your favorite provider and create an app in order to get the ClientId and ClientSecret keys. Ask on the forum if you have difficulties getting there.

Once you got the keys for a provider, just paste it into the module settings and save it. One or more button should appear bellow the standard login form.

The final step is to make your JSON configuration file.

Check this sample :

{
  "providers": {
    "google": {
      "className": "Google",
      "packageName": "league/oauth2-google",
      "helpUrl": "https://console.developers.google.com/apis/credentials"
    },
    "facebook": {
      "className": "Facebook",
      "packageName": "league/oauth2-facebook",
      "helpUrl": "https://developers.facebook.com/apps/",
      "options": {
        "graphApiVersion": "v2.10",
        "scope": "email"
      }
    },
    "github": {
      "className": "Github",
      "packageName": "league/oauth2-github",
      "helpUrl": "https://github.com/settings/developers",
      "options": {
        "scope": "user:email"
      }
    },
    "linkedin": {
      "className": "LinkedIn",
      "packageName": "league/oauth2-linkedin",
      "helpUrl": "https://www.linkedin.com/secure/developer"
    }
  }
}

Backend Usage

In ready.php, call the module :

if($page->template == 'admin') {
    $oauth2mod = $modules->get('Oauth2Login');
    if($oauth2mod)
        $oauth2mod->hookBackend();
}

Frontend Usage

Small note: At this moment the render method is pretty simple. It output a InputfieldForm with InputfieldSubmit(s) into wrapped in a ul:li tag. Feedbacks and ideas welcome!

For the following example, I created a page login and a template login which contain the following code :

    <?php namespace ProcessWire;

	if(!$user->isLoggedin()) {

		    $options = array(
		        'buttonClass' => 'my_button_class',
		        'buttonValue' => 'Login with {provider}', // {{provider}} keyword
		        'prependMarkup' => '<div class="wrapper">',
		        'appendMarkup' => '</div>'
		    );

		    $redirectUri = str_lreplace('//', '/', $config->urls->httpRoot . $page->url);

		    $content = $modules->get('Oauth2Login')->config(
	          array(
	              'redirect_uri' => $redirectUri,
	              'success_uri'  => $page->url
	          )
	      )->render($options);
	}

Install and use modules at your own risk. Always have a site and database backup before installing new modules.

Latest news

  • ProcessWire Weekly #518
    The 518th issue of ProcessWire Weekly brings in all the latest news from the ProcessWire community. Modules, sites, and more. Read on!
    Weekly.pw / 13 April 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK