PHPackages                             hello-hungry/jam-auth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. hello-hungry/jam-auth

ActiveKohana-module[Authentication &amp; Authorization](/categories/authentication)

hello-hungry/jam-auth
=====================

This is a Kohana Auth driver, for Jam

1.0.5(8y ago)0745BSD-3-ClausePHPPHP &gt;=5.4.0

Since Aug 14Pushed 8y ago5 watchersCompare

[ Source](https://github.com/HelloHungry/jam-auth)[ Packagist](https://packagist.org/packages/hello-hungry/jam-auth)[ Docs](https://github.com/OpenBuildings/jam-auth)[ RSS](/packages/hello-hungry-jam-auth/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (5)Dependencies (5)Versions (21)Used By (0)

Jam driver for Kohana Auth
==========================

[](#jam-driver-for-kohana-auth)

This is updated version of original `jam-auth` package that should use new version of Facebook SDK that will be supported after 10th of July 2017. It will completely replace the old Facebook integration.

[![Build Status](https://camo.githubusercontent.com/483966c5b4833060d9bb7984fbae3cf11a1744264f21f65db762fd0065eb582b/68747470733a2f2f7472617669732d63692e6f72672f4f70656e4275696c64696e67732f6a616d2d617574682e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/OpenBuildings/jam-auth)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/e5014bff74c95c192edb8eb917e055e9bfd6fd5a0f61796e74a90de5cd8c018e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4f70656e4275696c64696e67732f6a616d2d617574682f6261646765732f7175616c6974792d73636f72652e706e673f733d36386135636137373337336262396133643232363036643636396464653665626266333064643334)](https://scrutinizer-ci.com/g/OpenBuildings/jam-auth/)[![Code Coverage](https://camo.githubusercontent.com/e959a1b0f10cef019e3aa5d9af1aa79dc205db673548575172c627bb0f9e5709/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4f70656e4275696c64696e67732f6a616d2d617574682f6261646765732f636f7665726167652e706e673f733d61643637656664653861353534333063346565373436363638336135353731316131353832356338)](https://scrutinizer-ci.com/g/OpenBuildings/jam-auth/)[![Latest Stable Version](https://camo.githubusercontent.com/73296d1200264335ac053b7ff5f9994cf434bec9f65692c38e363504db404ea8/68747470733a2f2f706f7365722e707567782e6f72672f6f70656e6275696c64696e67732f6a616d2d617574682f762f737461626c652e706e67)](https://packagist.org/packages/openbuildings/jam-auth)

This is a Kohana Auth driver, for Jam, however it adds some more functionality that is absent in Auth ORM module, namely the ability to login / logout with different services, such as Twitter, Facebook and Google. The service infrastructure is there, however only the Facebook service is implemented.

Installation
------------

[](#installation)

Enable the module in your **bootstrap.php**:

```
DOCROOT/bootstrap.php
Kohana::modules(array(
	'jam-auth' => MODPATH.'jam-auth',
	// ...
));

APPPATH/config/auth.php
return array(
	'driver' => 'jam'

	// In order to use facebook auth service
	'services' => array(
		'facebook' => array(

			'enabled' => TRUE,

			// Automatically check this service for login credentials if the user is not logged in
			'auto_login' => FALSE,

			// Attempt to create the user if he's logged in with the service, but the user does not yet exist
			'create_user' => TRUE,

			// Facebook login credentials
			'auth' => array(
				'appId' => '224919274252280',
				'secret' => '4c891b816f1273442bdd7e1bac33f7e3'
			),
		),
	),
);

```

You will need to create the database tables - there are 2 sql files provided for mysql / postgre

- auth-schema-mysql.sql
- auth-schema-postgresql.sql

You can execute this to create your user, role and and token tables

Getting started
---------------

[](#getting-started)

The default Model\_User has some fields set up for you:

- **id** - primary key
- **email** - string field with validation for email, unique
- **username** - string field with validation for username (letters, dashes and underscores), length 3..32, required
- **password** - will autohash with the hash method on save (so before the save you can retrieve the actual password when set)
- **logins** - how many times the user has logged in
- **last\_login** - the date of the last login
- **last\_login\_ip** - the IP from which the user performed the last login
- **facbook\_uid** - this is used by the facebook auth service
- **twitter\_uid** - this is used by the twitter auth service

You can use the model "as is" but you most probably will want to customize it, so create a file Model\_User in your APPPATH/classes/model/ folder.

```
APPPATH/classes/model/user.php

APPPATH/classes/controller/session.php
class Controller_Session extends Controller {

	function action_login()
	{
		$request = $this->request;
		$view = View::factory('session/form');

		if ($request->method() === Request::POST)
		{
			// If the username / password is correct, login the user and return it, otherwise return FALSE
			if ($user = Auth::instance()->login($request->post('username'), $request->post('password'), $request->post('remember')))
			{
				$view->set('message', 'You have successfully logged in '.$user->name());
			}
			else
			{
				$view->set('message', 'Username or password incorrect');
			}
		}

		$this->response->body($view);
	}
}

```

Auto login
----------

[](#auto-login)

Auto login uses cookies to login the user automatically.

```
// By setting the "remember me" to TRUE, you create an auth token entry in the database with the corresponding cookie
$user = Auth::instance()->login($username, $password, TRUE);

// Which will be used by these methods to automatically login the user if the cookie matches the db entry
Auth::instance()->logged_in();
Auth::instance()->get_user();
Auth::instance()->auto_login();

```

Services also can be configured to be used for auto-login, for example if Facebook auth service config has 'auto\_login' =&gt; TRUE, then any -&gt;auto\_login() call will try to use the service to for logging in the user. Be careful with this however, as this can add high overhead to the requests of your non-logged in users.

It is best to use a separate method for logging in with each service as described in the following example:

Login with service
------------------

[](#login-with-service)

Jam Auth also supports Facebook logins, and the Facebook API is included in the vendors folder. Example login with facebook code:

```
APPPATH/classes/controller/session.php
class Controller_Session extends Controller {

	function action_login_facebook()
	{
		$this->auth->login_with_service('facebook');
	}

	function action_complete_login_facebook()
	{
		if ($user = $this->auth->complete_login_with_service('facebook'))
		{
			$this->redirect(URL::site());
		}
		else
		{
			throw new Auth_Exception_Service('There was an error logging in through facebook');
		}
	}
}

```

-&gt;login\_with\_service() redirect you to the "login" url of facebook. -&gt;complete\_login\_with\_service() is similar to -&gt;login() and returns the logged in user on successful login and FALSE on failure. You will have to login the user to the service yourself however. So the way this works for Facebook in particular is that you perform a "login" action with javascript, and return to this URL (/session/login\_facebook). And then it finds out what user is this in your own database. You can control whether to create the user automatically if its not present in the database with the 'create\_user' config option.

Model Extension for Facebook
----------------------------

[](#model-extension-for-facebook)

In order to load all the needed information for the user from the service (You want more information about the user than just the email) you can extend the load\_service\_values() method of the model and have specific code to handle extracting that information. For example:

```
public function load_service_values(Auth_Service $service, array $user_data, $create = FALSE)
{
	if ($service->name == 'facebook')
	{
		$email = Arr::get($user_data, 'email');

		$this->set(array_filter(array(
			'facebook_uid' => $user_data['id'],
			'username'     => URL::title(Arr::get($user_data, 'username', $user_data['name']), '-', TRUE),
			'first_name'   => Arr::get($user_data, 'first_name'),
			'last_name'    => Arr::get($user_data, 'last_name'),
			'image'        => 'http://graph.facebook.com/'.$user_data['id'].'/picture?type=large',
			'email'        => $email,
			'facebook'     => 'http://facebook.com/'.Arr::get($user_data, 'username', $user_data['id']),
		)));
	}

	return $this;
}

```

Forgotten password
------------------

[](#forgotten-password)

Forgotten password is not implemented per se, but it is very easy to set up.

```
APPPATH/views/session/forgotten.php

APPPATH/classes/controller/session.php
class Controller_Session extends Controller {

	function action_send_forgotten()
	{
		$request = $this->request;
		$view = View::factory('session/form');

		if ($request->method() === Request::POST)
		{
			$user = Jam::find('user', $request->post('email'));
			if ($user->loaded())
			{
				// Generate a special onetime token, that will expire in a week
				$token = $user->generate_login_token();
				mail($user->email, 'Forgotten Password', 'Click this link to login: '.URL::site(TRUE).'/session/login_token/'.$token->token);
				$view->set('message', 'An email with instructions has been sent to '.$user->email);
			}
			else
			{
				$view->set('message', 'A user with this email was not found');
			}
		}

		$this->response->body($view);
	}

	function action_login_token()
	{
		// Perform the actual login - if the login is successful - return the user, otherwise return FALSE
		if ($user = $this->auth->login_with_token($this->request->param('id')))
		{
			$this->redirect(URL::site());
		}
		else
		{
			throw new Auth_Exception_Service('The token has expired or was incorrect');
		}
	}
}

```

Logging out
-----------

[](#logging-out)

Logging out is a bit more complicated as it requires going to each service's site to logout from there so will have to go several times through the "logout" page to do that. This is handled automatically, but if you have explicit redirects, they might not work as expected. Example logout code:

```
APPPATH/classes/controller/session.php
class Controller_Session extends Controller {

	function action_destroy()
	{
		$this->auth->logout();
		$this->redirect(URL::site());
	}
}

```

License
-------

[](#license)

Jam-auth is Copyright © 2012-2013 OpenBuildings Ltd. developed by Ivan Kerin. It is free software, and may be redistributed under the terms specified in the LICENSE file.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~73 days

Total

20

Last Release

3255d ago

Major Versions

0.4.3 → 1.0.02017-06-15

PHP version history (2 changes)0.1.0PHP &gt;=5.3.0

0.4.3PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/749cf1dfa9fd70be7bbcb900213e22ded804858f6e92baadabc6456536eb18ce?d=identicon)[rolice](/maintainers/rolice)

---

Top Contributors

[![ivank](https://avatars.githubusercontent.com/u/4976?v=4)](https://github.com/ivank "ivank (24 commits)")[![hkdobrev](https://avatars.githubusercontent.com/u/506129?v=4)](https://github.com/hkdobrev "hkdobrev (21 commits)")[![ashmodean7](https://avatars.githubusercontent.com/u/1046954?v=4)](https://github.com/ashmodean7 "ashmodean7 (6 commits)")[![mlgrozev](https://avatars.githubusercontent.com/u/788176?v=4)](https://github.com/mlgrozev "mlgrozev (2 commits)")[![the-vesuvius](https://avatars.githubusercontent.com/u/832396?v=4)](https://github.com/the-vesuvius "the-vesuvius (1 commits)")

---

Tags

facebookauthAuthenticationkohanaloginjam

### Embed Badge

![Health badge](/badges/hello-hungry-jam-auth/health.svg)

```
[![Health](https://phpackages.com/badges/hello-hungry-jam-auth/health.svg)](https://phpackages.com/packages/hello-hungry-jam-auth)
```

###  Alternatives

[auth0/auth0-php

PHP SDK for Auth0 Authentication and Management APIs.

40820.2M68](/packages/auth0-auth0-php)[opauth/opauth

Multi-provider authentication framework for PHP

1.6k783.4k58](/packages/opauth-opauth)[auth0/login

Auth0 Laravel SDK. Straight-forward and tested methods for implementing authentication, and accessing Auth0's Management API endpoints.

2745.0M3](/packages/auth0-login)[socialconnect/auth

Social Connect Auth Component

568845.4k5](/packages/socialconnect-auth)[delight-im/auth

Authentication for PHP. Simple, lightweight and secure.

1.3k135.7k20](/packages/delight-im-auth)[auth0/symfony

Symfony SDK for Auth0 Authentication and Management APIs.

128738.1k](/packages/auth0-symfony)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
