that0n3guy/anvard

HybridAuth social sign in package for Laravel 4

dev-master 2014-06-27 18:56 UTC

This package is not auto-updated.

Last update: 2024-12-17 07:46:53 UTC


README

Requirements

  • Laravel 4.1.x
  • Database setup for migrations
  • A "User" model (you can set a different name in configuration)
  • You have read the notes on configuration before you dive in :)

Installation

  1. Add the dependency to your composer.json file: "atticmedia/anvard": "dev-master"
  2. Run php composer.phar install or composer update
  3. Add 'Atticmedia\Anvard\AnvardServiceProvider', to your config/app.php file
  4. Publish the package config php artisan config:publish atticmedia/anvard
  5. Add your service credentials to app/config/packages/atticmedia/anvard/hybridauth.php
  6. Check the app/config/packages/atticmedia/anvard/db.php file to see if you need to customise anything (see Configuration below for help)
  7. Run the migration php artisan migrate --package=atticmedia/anvard
  8. Create the Profile model (using a different name if you changed the config)
  9. Set the User to have many Profiles:

     public function profiles() {
         return $this->hasMany('Profile');
     }
    
  1. Set the Profile to belong to a User and to have certain fields fillable:

     class Profile extends Eloquent  {
    
         protected $fillable = array('provider', 'user_id');
    
         public function user() {
             return $this->belongsTo('User');
         }
     }
    
    
    

If you get composer errors talking about hybridauth. You probably need to do one of the below:

Option 1: You may need to add the below to composer:

"minimum-stability": "dev",
"prefer-stable": true

Option 2: Instead of the above step, you could add "hybridauth/hybridauth": "2.*@dev" to composer.json if you don't want to change your full projects minimum-stability (this is what I do).

Configuration

Anvard comes with several configuration files, and you must edit at least one of them.

Before you can run Anvard, you need to publish out the packages config files to your own app - which you can easily do using artisan:

php artisan config:publish atticmedia/anvard

You will then find the configuration files in your app/config/packages directory.

hybridauth.php

Firstly to put in all your service credentials (app id and app secret that you got from Facebook, LinkedIn, etc).

This is almost the exact set of configuration used by the HybridAuth library itself, so see their documentation for more information.

The one exception is the "base_url", which Anvard itself specifies based on the Routes it is configured to use.

db.php

This file specifies everything related to your database and models. Anvard expects you to have a users table, and it will create a profiles table for you with the migration.

Note that you should edit this file BEFORE YOU RUN THE MIGRATION, since the migration itself reads this config.

Hopefully most of the values in this file are self explanatory, the exceptions being the "profiletousermap", "userrules" and "uservalues" keys.

profilestousersmap

This is used when a new user is created from a social login. It is a reasonably common case that you will have some properties on User that are mapped to Profiles, but you may want to keep them directly in the User model to make your life easier when > dealing with users who were not registered using this method.

Specifying this will map fields from the Profile to the newly > created User.

Keys are attribute names from the Profile (which mirrors the original HybridAuth Adapter) and values are attribute names on the User model.

userrules

If you are using Ardent to automatically validate models (and stop them from being saved if validation fails) you may want to specify a set of override rules here when creating new Users.

For example, we don't have passwords for users created by Anvard, so you could disable the confirmation requirement there.

uservalues

This is similar to the profiletousermap, but much more flexible. You can specify specific values for certain attributes on new Users (i.e. a "role_id" for all "customers"), or even provide a callback to run - the callback will be passed in the new (unsaved) user and the original HybridAuth Adapter profile of values.

views.php

Anvard provides it's own extremely simple views. Change this setting to specify your own views instead.

Routes

See the routes.php config file to alter the default routes