happyninjas/fuel-ninjauth — pull request #17 by zarunor (2012-02-01 05:46:45+00:00)
Title: Adapter for Auth and Sentry

Phil suggested an authentication adapter class for interfacing with different authentication. Here's my stab at one. I hope it will be useful, at least as an example.

My goal was to preserve the current functionality, and have it work with FuelPHP Auth and Cartalyst Sentry with their default configurations. The AuthAdapter class can be extended for other authentication classes in the future.

My Sentry adapter has to jump through some weird hoops, like splitting a full name into a first name and last name, because OAuth2 and NinjAuth work with the full name, while Sentry's default install uses a first name and last name in the metadata table.

I've asked the Sentry guys to comment on the Sentry config values that my adapter can optionally rely on.

Note: NinjAuth will now log the user in after registration. In the future, this could perhaps be configurable.

Btw, to anyone testing, you may need to apply this pull request allowing secret to be null in the DB (Facebook with offline_access is broken without it): https://github.com/happyninjas/fuel-ninjauth/pull/12

# Release Notes:
The authentication adapter abstracts the interface to authentication methods. Currently, adapters exist for the FuelPHP Auth package and Cartalyst's Sentry package.

## Ninjauth configuration:
- The auth adapter is set in Ninjauth config via ninjauth.auth_adapter, possible values are 'Auth' and 'Sentry'
- If ninjauth.auth_adapter is not set, then the Auth adapter will be used by default, just like current functionality

## Sentry configuration:
- The AuthAdapter_Sentry adapter class relies on several Sentry config entries.
- These entries are not required, but they add flexibility to the adapter
- _sentry.default_activation_ determines whether users are created with an activation requirement or not.
- if _sentry.default_activation_ is not set, then the Sentry adapter creates users with activation requirement set to false
- _sentry.users_primary_key_ sets the primary key of the users table, in case it's not 'id'
- if _sentry.users_primary_key_ is not set, then the primary key is assumed to be 'id'

## Exceptions:
Auth exceptions and Sentry exceptions are caught and their message is re-thrown as Ninjauth\Exception. The client of the adapter remains agnostic to the class of exceptions thrown, and catches them as Ninjauth\Exception