Download the PHP package agungsugiarto/codeigniter4-authentication-jwt without Composer

On this page you can find all versions of the php package agungsugiarto/codeigniter4-authentication-jwt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package codeigniter4-authentication-jwt

CodeIgniter4 Authentication JWT

Latest Stable Version Total Downloads Latest Unstable Version License

About

JSON Web Token for codeigniter4-authentication. This package is port from tymondesigns/jwt-auth for compability with agungsugiarto/codeigniter4-authentication.

Documentation

Install Via Composer

Copy the config

Copy the config file from vendor/agungsugiarto/codeigniter4-authentication-jwt/src/Config/JWT.php to config folder of your codeigniter4 application and change class extends from BaseConfig to \Fluent\JWTAuth\Config\JWT

Update your User entities

Firstly you need to implement the Fluent\JWTAuth\Contracts\JWTSubjectInterface contract on your User entities, which requires that you implement the 2 methods getJWTIdentifier() and getJWTCustomClaims().

The example below should give you an idea of how this could look. Obviously you should make any changes, as necessary, to suit your own needs.

Adding \Fluent\JWTAuth\JWTGuard::class Guards

We need to define \Fluent\JWTAuth\JWTGuard::class authentication guards using the extend method on the Auth facade or service. You should place your call to the extend method within a service provider. Since codeigniter4-authentication already ships with an AuthServiceProvider, we can place the code in that provider. Open \App\Providers\AuthServiceProvider:

Configure Auth guard

Inside the app/Config/Auth.php file you will need to make a few changes to configure codeigniter4-authentication to use the jwt guard to power your application authentication.

Make the following changes to the file:

Here we are telling the api guard to use the \Fluent\JWTAuth\JWTGuard::class driver, and we are setting the api guard.

Next we need to register this App\Providers\AuthServiceProvider to lifecycle application. Open App\Config\Events add this line:

We can now use codeigniter4-authentication built in Auth system, with codeigniter4-authentication-jwt doing the work behind the scenes!

Add some basic authentication routes

First let's add some routes in app/Config/Routes.php as follows:

Create the AuthController

Then create the JwtauthController, either manually or by running the spark command:

Then add the following:

You should now be able to POST to the login endpoint (e.g. http://example.dev/jwt/login) with some valid credentials and see a response like:

This token can then be used to make authenticated requests to your application.

Authenticated requests

There are a number of ways to send the token via http:

Authorization header

Query string parameter

Post parameter

Cookies

Methods

The following methods are available on the Auth guard instance.

Multiple Guards

If the newly created 'api' guard is not set as a default guard or you have defined multiple guards to handle authentication, you should specify the guard when calling auth().

attempt()

Attempt to authenticate a user via some credentials.

This will return either a jwt or boolean

login()

Log a user in and return a jwt for them.

user()

Get the currently authenticated user.

If the user is not then authenticated, then null will be returned.

userOrFail()

Get the currently authenticated user or throw an exception.

If the user is not set, then a Fluent\JWTAuth\Exceptions\UserNotDefinedException will be thrown

logout()

Log the user out - which will invalidate the current token and unset the authenticated user.

refresh()

Refresh a token, which invalidates the current one

invalidate()

Invalidate the token (add it to the blacklist)

tokenById()

Get a token based on a given user's id.

payload()

Get the raw JWT payload

validate()

Validate a user's credentials

More advanced usage

Adding custom claims

Set the token explicitly

Set the request instance explicitly

Override the token ttl

Contributing

Contributions are very welcome.

License

Released under the MIT License, see LICENSE.


All versions of codeigniter4-authentication-jwt with dependencies

PHP Build Version
Package Version
Requires agungsugiarto/codeigniter4-authentication Version ^1.0|^2.0
codeigniter4/framework Version ^4.1
php Version ^7.3|^8.0
lcobucci/jwt Version <3.4
nesbot/carbon Version ^2.0
tightenco/collect Version ^8.19
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package agungsugiarto/codeigniter4-authentication-jwt contains the following files

Loading the files please wait ....