To install this package you will need
- Laravel 5.4
- PHP 5.5
The best way to install this package is with the help of composer. Run
composer require ahsankhatri/wordpress-auth-provider
or install it by adding it to composer.json
then run composer update
"require": {
"ahsankhatri/wordpress-auth-provider": "^1.0",
}
Once you have installed this package from the composer, make sure to follow the below steps to configure.
'providers' => [
/*
* Laravel Framework Service Providers...
*/
...,
MrShan0\WordpressAuth\WordpressAuthServiceProvider::class,
]
Also, to register authentication guard.
'guards' => [
...,
'wordpress' => [
'driver' => 'session',
'provider' => 'wordpress',
],
'providers' => [
...,
'wordpress' => [
'driver' => 'eloquent.wordpress',
'model' => MrShan0\WordpressAuth\Models\WordpressUser::class,
],
'passwords' => [
...,
'wordpress' => [
'provider' => 'wordpress',
'table' => 'password_resets',
'expire' => 60,
],
password_resets
table (from Laravel default auth mechanism) is required to hold reset password token. If you do not have password_resets
table then use this migration instead
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePasswordResetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('password_resets');
}
}
You need to define wordpress
guard explicitly to load the driver.
Auth::guard('wordpress')->loginUsingId(5);
// or login using email and password
Auth::guard('wordpress')->attempt([
'user_email' => '[email protected]',
'user_pass' => 'quickbrownfox'
]);
// get user object
Auth::guard('wordpress')->user();
// logout
Auth::guard('wordpress')->logout();
You may also change default guard in config/auth.php
then your code will look like
Auth::loginUsingId(5);
Thanks to the community of Laravel.
Copyright (c) 2016 Ahsaan Muhammad Yousuf, MIT License