With this module you can login (and sign up) your users via OAuth providers while using the Auth module of Kohana. The currently supported providers:
Thanks goes to Geert De Deckere for his work on OAuth login for KohanaJobs.
Read the following to get started.
See the included auth-schema-mysql.sql
file for the correct table structure.
By default the module supports Jelly. Drivers for Kohana's ORM can be downloaded here.
Enable the oauth
module in bootstrap.php
and do the following with the needed providers:
- For Twitter: enable the Twitter API in
bootstrap.php
- For Facebook: download the Facebook SDK and uncompress it to
application/vendor/facebook
directory
Copy oauth.php
from the oauth module's config
directory to application/config
directory and edit it.
Set the key and secret for the providers like this (for Facebook use your App Id as key):
return array(
'twitter' => array(
'key' => 'xxx',
'secret' => 'xxx'
),
);
Copy sso.php
from the config
directory to application/config
directory and edit it.
You will have to set 2 URLs for each provider:
- callback URL: this will be the page where the user is returned after he / she confirmed the OAuth request
- login URL: if the login process is interrupted the user will be returned to the login page (this setting isn't used for every provider, though it is advisable to have it set)
IMPORTANT: in many cases you want the 2 URLs to be the same as the login completion is not called seperately from initiating the login process. This feature is for only the sake of flexibility.
In your controller all you have to do is something like this (the example is for Twitter):
// Load Auth instance
$auth = Auth::instance();
// Login the user via Twitter
if ($auth->sso('twitter'))
{
// The SSO module returns TRUE if user is logged in, we can issue a redirect in this case
$this->request->redirect('');
}
If the user wasn't found during the login process the current sign up method saves the user as a new user. It also merges the OAuth account with a standard account if they share the same e-mail address.
You can define your own sign up method. Check out the following files depending on your ORM:
- Copy
module_directory/classes/model/builder/user.php
toapplication_directory/classes/model/builder/user.php
. - Create a
sso_signup()
methodin
application_directory/classes/model/builder/user.php` and customize it to your needs.
To get an example on how to create the method check it out in module_directory/classes/model/builder/auth/user.php
.
- Copy
orm_driver_directory/classes/model/user.php
toapplication_directory/classes/model/user.php
. - Customize the
sso_signup()
method to your needs.