Socialite

A cool module to handle oauth2 authentication.

Currently support:

  • Facebook
  • Google
  • Linkedin
  • Github

Installation:

You can install with commandbox

install socialite

Otherwise download from forgebox

http://www.coldbox.org/forgebox/view/Socialite

Configuration:

You need to put your clientId, clientSecret and redirect url in config file. You can insert your data in ColdBox.cfc:

		// Custom Settings
	    moduleSettings = {
			socialite = {
				facebook = {
					client_id = "XXXXXXXXXXXXX",
					client_secret = "XXXXXXXXXXXXX",
					redirect_url = "http://YOUR-URL/provider/response/facebook"					
				},
				google = {
					client_id = "XXXXXXXXXXXXX",
					client_secret = "XXXXXXXXXXXXX",
					redirect_url = "http://YOUR-URL/provider/response/google"					
				},
				github = {
					client_id = "XXXXXXXXXXXXX",
					client_secret = "XXXXXXXXXXXXX",
					redirect_url = "http://YOUR-URL/provider/response/github"					
				},
				linkedin = {
					client_id = "XXXXXXXXXXXXX",
					client_secret = "XXXXXXXXXXXXX",
					redirect_url = "http://YOUR-URL/provider/response/linkedin"					
				}
			}
		};

Usage:

First create routes:

		route(pattern="/provider/response/:provider", target="socialite.response");
		route(pattern="/provider/:provider", target="socialite.auth");

In your view put the code for login button:

<a href="#event.buildLink( 'provider/facebook' )#">Facebook</a>

In your handler:

socialite.init().with('facebook').redirect()

This will prompt you to authentication page. Then simply:

socialite.with('facebook').user(rc.code)

A simple example:


component {

	property name="socialite" inject="[email protected]";
    property name="credentials" inject="coldbox:modulesettings: socialite";
	property name="user" inject="[email protected]";

	function index(event,rc,prc){
		event.setView("socialite/index");
	}

	function auth(event,rc,prc){
		var social = socialite.init( credentials ).with( rc.provider );
		social.redirect();
	}

	function response(event,rc,prc){
		prc.user = socialite.init( credentials ).with(rc.provider).user(rc.code);
		event.setView("socialite/index");
	}

}

And you will get user data.

 

 
$ box install socialite
No collaborators yet.
  • Jan 10 2017 06:29 PM
  • Jul 06 2018 09:55 AM
  • 506
  • 253
  • 29