PHPackages                             jijihohococo/ichi-api-authentication - 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. jijihohococo/ichi-api-authentication

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

jijihohococo/ichi-api-authentication
====================================

API Authentication for laravel

13PHP

Since Aug 2Pushed 4y ago1 watchersCompare

[ Source](https://github.com/jijihohococo/ichi-api-authentication)[ Packagist](https://packagist.org/packages/jijihohococo/ichi-api-authentication)[ RSS](/packages/jijihohococo-ichi-api-authentication/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Ichi API Authentication For Laravel
===================================

[](#ichi-api-authentication-for-laravel)

Since I had difficulties in using Laravel Passport due to the conflicts of PHP Version and League Oauth2 Library. I had the idea of developing my own API Authentication driver. This API Authentication library is developed without Oauth2. It is also my first time library development. The usage and library structure is really same as Laravel Passport's structure. It is aimed to use multiple API Authentication Guards in Laravel API Developments without facing difficulties that I had mentioned above. The development frame had took one week.

This library can be used for Laravel Version 5.6 to 8 with PHP Version 7.0 to above

License
-------

[](#license)

This package is Open Source According to [MIT license](LICENSE.md)

Installing Library
------------------

[](#installing-library)

```
composer require jijihohococo/ichi-api-authentication:dev-master
```

Before Using
------------

[](#before-using)

You need to have "id" , "email" and "password" columns in your user table to use this library.

Using the library
-----------------

[](#using-the-library)

To use the library, firstly we need to assign the guards like below code in "config/auth.php" of your Laravel Project.

```
'guards' => [
	'user_api' => [
		'driver' => 'ichi',
		'provider' => 'users',
		'hash' => false,
	],
]
```

And then we need to add User API Guard into Ichi API Database by the below code in terminal

```
php artisan ichi:client --password
```

After choosing the right guard for your user in terminal as you mentioned in your guard array of "config/auth.php", your User Model need to inherit this library functions by the inheritance as shown as below.

```
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use JiJiHoHoCoCo\IchiApiAuthentication\HasApi;
class User extends Authenticatable{
	use HasApi;
}
```

The configuration is finished, you can override the database models of Ichi library with command line as shown as below.

```
php artisan vendor:publish --tag=ichi-migrations
```

You can also override the configurations of Ichi Library with command line as shown as below

```
php artisan vendor:publish --tag=ichi-config
```

You can test the registration of your token like below

```
$user= User::create([
	'name' => 'jiji' ,
	'email' => 'ji@gmail.com' ,
	'password' => Hash::make( 'password' )
]);
$token=$user->ichiToken();
return response()->json([
	'name' => $user->name ,
	'token' => $token->token ,
	'expired_at' => $token->expired_at ,
    'refresh_token' => $token->refreshToken ,
    'refreshTokenExpiredTime' => $token->refreshTokenExpiredTime
]);
```

You can test the login of your token like below

*You need to make Accept =&gt; application/json and Authorization =&gt; Bearer {token} in your headers to make login actions.*```
Route::group(['middleware' => ['auth:user_api']], function() {
	Route::get('user_profile',function(){
		$user=\Auth::guard('user_api')->user();
		dd($user->name);
	});
});
```

You can revoke the login token as shown as below.

```
Route::group(['middleware' => ['auth:user_api']], function() {
    Route::get('user_logout',function(){
        $user=\Auth::guard('user_api')->user();
        $user->revoke();
        return response()->json([
            'message' => 'Log out successfully'
        ]);
    });
```

The default expiration time of token is 1 Year. You can customize this expiration time like below in "app/Providers/AuthServiceProvider.php"

*Gate has no connection with our library.*

```
namespace App\Providers;

use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
use JiJiHoHoCoCo\IchiApiAuthentication\Ichi;
class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        // 'App\Models\Model' => 'App\Policies\ModelPolicy',
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();
        Ichi::setExpiredAt(now()->addDays(2));
    }
```

You can select all the tokens of selected User By

```
User::findOrFail(1)->getAllTokens();
```

You can delete the revoked tokens in command line as shown as below

```
php artisan ichi:remove --revoke
```

You can delete the expired tokens in command line as shown as below

```
php artisan ichi:remove --expired
```

Refresh Token
-------------

[](#refresh-token)

You can refresh token outside of authentication route like that with the headers Accept =&gt; application/json and refresh\_token =&gt; Bearer {refreshToken}. You must refresh token when your token is expired when he/she is login.

```
Route::get('refresh_user_token',function(){
    $user=new User;
    $refreshToken=$user->refreshToken();
    return response()->json([
        'name' => $refreshToken->user->name ,
        'token' => $refreshToken->token ,
        'expired_at' => $refreshToken->expired_at ,
        'refresh_token' => $refreshToken->refreshToken ,
        'refreshTokenExpiredTime' => $refreshToken->refreshTokenExpiredTime
     ]);
});
```

The default expiration time of refresh token is 1 Year. You can customize this expiration time like below in "app/Providers/AuthServiceProvider.php"

*Gate has no connection with our library.*

```
namespace App\Providers;

use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
use JiJiHoHoCoCo\IchiApiAuthentication\Ichi;
class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        // 'App\Models\Model' => 'App\Policies\ModelPolicy',
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();
        Ichi::setRefreshExpiredAt(now()->addDays(2));
    }
```

Revoke Other Tokens
-------------------

[](#revoke-other-tokens)

You can make log out other devices Accept =&gt; application/json and Authroization =&gt; Bearer {token} (that token will not be revoked).

```
Route::group(['middleware' => ['auth:user_api']], function() {
Route::get('revoke_other_token',function(){
    $user=\Auth::guard('user_api')->user();
    $user->logOutOtherTokens();
    return response()->json([
        'message' => 'Logout other devices success'
    ]);
});
});
```

You can get the number of revoked tokens of each user

```
User::findOrFail(1)->revokedTokens();
```

### Hope you enjoy!

[](#hope-you-enjoy)

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 Bus Factor1

Top contributor holds 96% of commits — single point of failure

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/79d474fd8574bf6fb6a471530869071003a9ea38bbd5c25abfe7dc3f92d28676?d=identicon)[JiJiHoHoCoCo](/maintainers/JiJiHoHoCoCo)

---

Top Contributors

[![suzume98](https://avatars.githubusercontent.com/u/48427296?v=4)](https://github.com/suzume98 "suzume98 (170 commits)")[![hasesuki98](https://avatars.githubusercontent.com/u/46418674?v=4)](https://github.com/hasesuki98 "hasesuki98 (6 commits)")[![jijihohococo](https://avatars.githubusercontent.com/u/53247594?v=4)](https://github.com/jijihohococo "jijihohococo (1 commits)")

---

Tags

authauthenticationlaravelphpphp-library

### Embed Badge

![Health badge](/badges/jijihohococo-ichi-api-authentication/health.svg)

```
[![Health](https://phpackages.com/badges/jijihohococo-ichi-api-authentication/health.svg)](https://phpackages.com/packages/jijihohococo-ichi-api-authentication)
```

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M100](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M117](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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