+++ categories = ["development"] date = "2014-01-09T08:54:57-05:00" description = "Overview of what is involved in getting your Laravel 4 apps authentication system to integrate with Get Satisfaction Fastpass for single sign on." keywords = ["laravel", "php", "fastpass"] tags = ["laravel", "php", "fastpass"] slug = "integrating-get-satisfaction-fastpass-with-laravel" title = "Integrating Get Satisfaction Fastpass with Laravel" +++ Here is an overview of what is involved in getting your Laravel 4 apps authentication system to integrate with Get Satisfaction Fastpass for single sign on. ## What I am using * [Laravel 4.0][2] * [Cartalyst Sentry 2][3] (for authentication) * [Former][4] * [Fastpass PHP SDK][1] ## Install the Fastpass PHP SDK *****Create a folder to install the library in** ``` $ mkdir app/lib $ mkdir app/lib/getsatisfaction ``` **Download & untar/unzip the Fastpass PHP SDK** ``` cd app/lib/getsatisfaction wget "https://getsatisfaction.com/fastpass/php.tar.gz" tar -zxvf php.tar.gz . ``` **Update** *composer.json* **adding the location of the library** In the *autoload* section add the path *app/lib/getsatisfaction* ``` "autoload": { "classmap": [ "app/commands", "app/controllers", "app/models", "app/database/migrations", "app/database/seeds", "app/tests/TestCase.php", "app/lib/getsatisfaction" ] }, ``` **In the console run** ``` $ composer update $ php artisan dump-autoload ``` **Create a configuration file (e.g. app/config/getsatisfaction.php ) to hold your API tokens for the Fastpass service** ```php '', 'secret' => '', 'domain' => '', ); ``` The above information can be found in the admin section once you log in as administrator on . ## Create a login screen for Single Sign on We now need to create a login form to be used by the Fastpass service to use our authentication service provided by sentry to log users into Get Satisfaction. **First we create a new controller** *app/controllers/SatisfactionController.php* ```php Input::get('login_attribute'), 'password' => Input::get('password') ); try { // Log user in $user = Sentry::authenticate($userdata, $remember); } catch (LoginRequiredException $e) { return Redirect::back()->withInput()->with('error', $e->getMessage()); } catch (PasswordRequiredException $e) { return Redirect::back()->withInput()->with('error', $e->getMessage()); } catch (WrongPasswordException $e) { return Redirect::back()->withInput()->with('error', $e->getMessage()); } catch (UserNotActivatedException $e) { return Redirect::back()->withInput()->with('error', $e->getMessage()); } catch (UserNotFoundException $e) { return Redirect::back()->withInput()->with('error', $e->getMessage()); } catch (UserSuspendedException $e) { return Redirect::back()->withInput()->with('error', $e->getMessage()); } catch (UserBannedException $e) { return Redirect::back()->withInput()->with('error', $e->getMessage()); } catch (Exception $e) { return Redirect::back()->withInput()->with('error', $e->getMessage()); } Event::fire('users.login', array($user)); // Log user into Get Satisfaction service return View::make('satisfaction.index', compact('user')); } /** * Show the login form * * @author Salar Rahmanian * @link http://www.softinio.com * * @return Response */ public function getLogin() { // Check to see if user logged in, if not show login form if (!\Sentry::check()) { $login_attribute = Config::get('cartalyst/sentry::users.login_attribute'); return View::make('satisfaction.login', compact('login_attribute')); } // user already logged in so log them into Get Satisfaction service $user = \Sentry::getUser(); return View::make('satisfaction.index', compact('user')); } } ``` Now we need to create the two views used by this controller, one with a login form and one view which logs the user into the get satisfaction service. **For the login form we create the view ** *app/views/satisfaction/login.blade.php* This can be a copy of the login form you currently use within your Laravel app but with the form action changed to use the new *SatisfactionController*. ``` @extends('layouts.master') @section('h1')

Sign In

@stop @section('crumb')
  • User
  • Login
  • @stop @section('title') Sign In - @stop @section('container')
    {{ Former::horizontal_open(url('/satisfaction/login')) }} {{ Former::text('login_attribute', 'User Name',Input::old('login_attribute'))->required() }} {{ Former::password('password', 'Password')->required() }} {{ Former::checkbox('remember_me',' ')->text('Remember me on this computer') }}
    {{ Former::primary_submit('Log in') }} Register Here
    @stop ``` **We create the view that logs user into Get Satisfaction** *app/views/satisfaction/index.blade.php* This is in effect a blank html document which calls the php class from the Fastpass library to log the current user into the Get Satisfaction service. ``` {{ \FastPass::$domain = \Config::get('getsatisfaction.domain'); }} {{ \FastPass::script(\Config::get('getsatisfaction.key'), \Config::get('getsatisfaction.secret'), $user->email, $user->username, $user->id, true ); }} @yield('title') softinio.com {{ basset_stylesheets('bootstrap','application') }} ``` The users email , username and user id provided by Sentry are used to create and log user into the Get Satisfaction service. The username is what will be displayed as the logged in user on Get Satisfaction website so if you prefer something else you can substitute username for what you prefer. **Update your** *app/routes.php* **file** ```php Route::get('satisfaction/login', 'SatisfactionController@getLogin'); Route::post('satisfaction/login','SatisfactionController@postLogin'); ``` ## Update Get Satisfaction with your login URL Based on the new route you created for the *SatisfactionController* your URL to your single sign on should be ``` http:///satisfaction/login ``` Log into Get Satifaction as admin, click the wheel settings menu, select Configure then select Fastpass. Here set your *External Login URL* to this and click save. Whilst you are logged in as admin you can also click login options and select Fastpass as your preferred login method. [1]: https://getsatisfaction.com/fastpass/php.tar.gz [2]: http://laravel.com [3]: https://cartalyst.com/manual/sentry [4]: http://anahkiasen.github.io/former