1. Go to this page and download the library: Download imanrjb/passport-auth library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class User extends Model
{
use HasApiTokens, Authenticatable, Authorizable;
public function findForPassport($email)
{
return $this->where('email', $email)->first();
}
public function validateForPassportPasswordGrant($password)
{
return Hash::check($password, $this->password);
}
}
// Second parameter is the client Id
\PassportAuth\LumenPassport::tokensExpireIn(Carbon::now()->addMinutes(50), 2);
\Laravel\Passport\Passport::refreshTokensExpireIn(Carbon::now()->addDays(2));
artisan passport:purge
// Generate new token with user credential
$client = Client::whereProvider('users')->first();
$request = Request::create('/oauth/token', 'POST', [
'grant_type' => 'password',
'client_id' => $client->id,
'client_secret' => $client->secret,
'username' => $request->email,
'password' => $request->password,
'scope' => '*',
'user_agent' => Browser::platformName() . ", " . Browser::browserFamily(),
'ip' => request()->ip()
]);
return app()->handle($request);
// Create route with middleware and return user information
$router->group(['middleware' => 'auth:api'], function () use ($router) {
$router->get('/user', function () {
return \Illuminate\Support\Facades\Auth::user();
});
});