{"id":18782892,"url":"https://github.com/jijihohococo/ichi-api-authentication","last_synced_at":"2026-04-29T22:32:16.397Z","repository":{"id":56999004,"uuid":"371997671","full_name":"jijihohococo/ichi-api-authentication","owner":"jijihohococo","description":"Api Authentication for laravel","archived":false,"fork":false,"pushed_at":"2021-08-02T09:11:30.000Z","size":2508,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-29T11:31:07.955Z","etag":null,"topics":["auth","authentication","laravel","php","php-library"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jijihohococo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-29T14:44:57.000Z","updated_at":"2023-09-04T17:28:19.000Z","dependencies_parsed_at":"2022-08-21T11:40:38.440Z","dependency_job_id":null,"html_url":"https://github.com/jijihohococo/ichi-api-authentication","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jijihohococo%2Fichi-api-authentication","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jijihohococo%2Fichi-api-authentication/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jijihohococo%2Fichi-api-authentication/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jijihohococo%2Fichi-api-authentication/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jijihohococo","download_url":"https://codeload.github.com/jijihohococo/ichi-api-authentication/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239699581,"owners_count":19682574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth","authentication","laravel","php","php-library"],"created_at":"2024-11-07T20:37:23.972Z","updated_at":"2025-12-20T06:30:14.337Z","avatar_url":"https://github.com/jijihohococo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ichi API Authentication For Laravel\n\n\u003cp\u003eSince 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.\u003c/p\u003e\n\n\u003cp\u003eThis library can be used for Laravel Version 5.6 to 8 with PHP Version 7.0 to above\u003c/p\u003e\n\n## License\n\nThis package is Open Source According to [MIT license](LICENSE.md)\n\n## Installing Library\n```php\ncomposer require jijihohococo/ichi-api-authentication:dev-master\n```\n\n## Before Using\n\u003cp\u003eYou need to have \"id\" , \"email\" and \"password\" columns in your user table to use this library.\u003c/p\u003e\n\n## Using the library\n\n\u003cp\u003eTo use the library, firstly we need to assign the guards like below code in \"config/auth.php\" of your Laravel Project. \u003c/p\u003e\n\n```php\n'guards' =\u003e [\n\t'user_api' =\u003e [\n\t\t'driver' =\u003e 'ichi',\n\t\t'provider' =\u003e 'users',\n\t\t'hash' =\u003e false,\n\t],\n]\n```\n\n\u003cp\u003eAnd then we need to add User API Guard into Ichi API Database by the below code in terminal\u003c/p\u003e\n\n```php\nphp artisan ichi:client --password\n```\n\n\u003cp\u003eAfter 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.\u003c/p\u003e\n\n```php\nnamespace App\\Models;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\nuse JiJiHoHoCoCo\\IchiApiAuthentication\\HasApi;\nclass User extends Authenticatable{\n\tuse HasApi;\n}\n```\n\n\u003cp\u003eThe configuration is finished, you can override the database models of Ichi library with command line as shown as below.\u003c/p\u003e\n\n```php\nphp artisan vendor:publish --tag=ichi-migrations\n```\n\n\u003cp\u003eYou can also override the configurations of Ichi Library with command line as shown as below\u003c/p\u003e\n\n```php\nphp artisan vendor:publish --tag=ichi-config\n```\n\n\u003cp\u003eYou can test the registration of your token like below\u003c/p\u003e\n\n```php\n$user= User::create([\n\t'name' =\u003e 'jiji' , \n\t'email' =\u003e 'ji@gmail.com' ,\n\t'password' =\u003e Hash::make( 'password' )\n]);\n$token=$user-\u003eichiToken();\nreturn response()-\u003ejson([\n\t'name' =\u003e $user-\u003ename ,\n\t'token' =\u003e $token-\u003etoken ,\n\t'expired_at' =\u003e $token-\u003eexpired_at ,\n    'refresh_token' =\u003e $token-\u003erefreshToken ,\n    'refreshTokenExpiredTime' =\u003e $token-\u003erefreshTokenExpiredTime\n]);\n```\n\n\u003cp\u003eYou can test the login of your token like below\u003c/p\u003e\n\u003ci\u003eYou need to make Accept =\u003e application/json and Authorization =\u003e Bearer {token} in your headers to make login actions.\u003c/i\u003e\n\n```php\nRoute::group(['middleware' =\u003e ['auth:user_api']], function() {\n\tRoute::get('user_profile',function(){\n\t\t$user=\\Auth::guard('user_api')-\u003euser();\n\t\tdd($user-\u003ename);\n\t});\n});\n```\n\u003cp\u003eYou can revoke the login token as shown as below.\u003c/p\u003e\n\n```php\nRoute::group(['middleware' =\u003e ['auth:user_api']], function() {\n    Route::get('user_logout',function(){\n        $user=\\Auth::guard('user_api')-\u003euser();\n        $user-\u003erevoke();\n        return response()-\u003ejson([\n            'message' =\u003e 'Log out successfully'\n        ]);\n    });\n```\n\n\u003cp\u003eThe default expiration time of token is 1 Year. You can customize this expiration time like below in \"app/Providers/AuthServiceProvider.php\" \u003c/p\u003e\n\n\u003ci\u003eGate has no connection with our library.\u003c/i\u003e\n\n```php\nnamespace App\\Providers;\n\nuse Illuminate\\Foundation\\Support\\Providers\\AuthServiceProvider as ServiceProvider;\nuse Illuminate\\Support\\Facades\\Gate;\nuse JiJiHoHoCoCo\\IchiApiAuthentication\\Ichi;\nclass AuthServiceProvider extends ServiceProvider\n{\n    /**\n     * The policy mappings for the application.\n     *\n     * @var array\n     */\n    protected $policies = [\n        // 'App\\Models\\Model' =\u003e 'App\\Policies\\ModelPolicy',\n    ];\n\n    /**\n     * Register any authentication / authorization services.\n     *\n     * @return void\n     */\n    public function boot()\n    {\n        $this-\u003eregisterPolicies();\n        Ichi::setExpiredAt(now()-\u003eaddDays(2));\n    }\n\n```\n\n\u003cp\u003eYou can select all the tokens of selected User By\u003c/p\u003e\n\n```php\nUser::findOrFail(1)-\u003egetAllTokens();\n```\n\n\u003cp\u003eYou can delete the revoked tokens in command line as shown as below\u003c/p\u003e\n\n```php\nphp artisan ichi:remove --revoke\n```\n\n\u003cp\u003eYou can delete the expired tokens in command line as shown as below\u003c/p\u003e\n\n```php\nphp artisan ichi:remove --expired\n```\n\n## Refresh Token\n\n\u003cp\u003eYou can refresh token outside of authentication route like that with the headers Accept =\u003e application/json and refresh_token =\u003e Bearer {refreshToken}. You must refresh token when your token is expired when he/she is login.\u003c/p\u003e\n\n```php\nRoute::get('refresh_user_token',function(){\n    $user=new User;\n    $refreshToken=$user-\u003erefreshToken();\n    return response()-\u003ejson([\n        'name' =\u003e $refreshToken-\u003euser-\u003ename ,\n        'token' =\u003e $refreshToken-\u003etoken ,\n        'expired_at' =\u003e $refreshToken-\u003eexpired_at ,\n        'refresh_token' =\u003e $refreshToken-\u003erefreshToken ,\n        'refreshTokenExpiredTime' =\u003e $refreshToken-\u003erefreshTokenExpiredTime\n     ]);\n});\n```\n\n\n\u003cp\u003eThe default expiration time of refresh token is 1 Year. You can customize this expiration time like below in \"app/Providers/AuthServiceProvider.php\" \u003c/p\u003e\n\n\u003ci\u003eGate has no connection with our library.\u003c/i\u003e\n\n```php\nnamespace App\\Providers;\n\nuse Illuminate\\Foundation\\Support\\Providers\\AuthServiceProvider as ServiceProvider;\nuse Illuminate\\Support\\Facades\\Gate;\nuse JiJiHoHoCoCo\\IchiApiAuthentication\\Ichi;\nclass AuthServiceProvider extends ServiceProvider\n{\n    /**\n     * The policy mappings for the application.\n     *\n     * @var array\n     */\n    protected $policies = [\n        // 'App\\Models\\Model' =\u003e 'App\\Policies\\ModelPolicy',\n    ];\n\n    /**\n     * Register any authentication / authorization services.\n     *\n     * @return void\n     */\n    public function boot()\n    {\n        $this-\u003eregisterPolicies();\n        Ichi::setRefreshExpiredAt(now()-\u003eaddDays(2));\n    }\n\n```\n## Revoke Other Tokens \n\n\u003cp\u003eYou can make log out other devices Accept =\u003e application/json and Authroization =\u003e Bearer {token} (that token will not be revoked).\u003c/p\u003e\n\n```php\nRoute::group(['middleware' =\u003e ['auth:user_api']], function() {\nRoute::get('revoke_other_token',function(){\n    $user=\\Auth::guard('user_api')-\u003euser();\n    $user-\u003elogOutOtherTokens();\n    return response()-\u003ejson([\n        'message' =\u003e 'Logout other devices success'\n    ]);\n});\n});\n```\n\n\u003cp\u003eYou can get the number of revoked tokens of each user\u003c/p\u003e\n\n```php\nUser::findOrFail(1)-\u003erevokedTokens();\n```\n\n### Hope you enjoy!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjijihohococo%2Fichi-api-authentication","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjijihohococo%2Fichi-api-authentication","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjijihohococo%2Fichi-api-authentication/lists"}