Download the PHP package alajusticia/laravel-sanctum-tracker without Composer

On this page you can find all versions of the php package alajusticia/laravel-sanctum-tracker. 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 laravel-sanctum-tracker

Laravel Sanctum Tracker

⚠️ This package is now archived. Use Laravel Logins instead.

Track Sanctum tokens in Laravel.

This package allows you to track Sanctum tokens, attaching informations by parsing the User-Agent and saving the IP address.

Using a supported provider or creating your own custom providers, you can collect even more informations with an IP address lookup to get, for example, the geolocation.

It also provides a trait introducing convenient methods: logout, logoutOthers and logoutAll for your user model.

Compatibility

For recent Laravel versions, use Laravel Logins.

This package has been tested with Laravel 8.x and Laravel Sanctum (v2).

Installation

Install the package with composer:

Publish the configuration file (config/sanctum_tracker.php) with:

Run the migrations to update the personal_access_tokens table:

Override default model

This package comes with a custom model (ALajusticia\SanctumTracker\Models\PersonalAccessToken) that extends the default Sanctum model.

Instruct Sanctum to use this custom model via the usePersonalAccessTokenModel method provided by Sanctum. Typically, you should call this method in the boot method of one of your application's service providers:

Choose and install a user-agent parser

This package relies on a User-Agent parser to extract the informations.

Currently, it supports two of the most popular parsers:

Before using the Sanctum Tracker, you need to choose a supported parser, install it and indicate in the configuration file which one you want to use.

Add the trait to your user model (optional)

This package provides a ALajusticia\SanctumTracker\Traits\SanctumTracked trait that can be used on your user model to quickly revoke Sanctum tokens.

It introduces convenient methods:

Usage

Issue Sanctum tokens like you would normally do. The PersonalAccessToken model provided by this package will automatically be populated with the extra informations.

IP address lookup

By default, the Sanctum Tracker collects the IP address and the informations given by the User-Agent header.

But you can go even further and collect other informations about the IP address, like the geolocation.

To do so, you first have to enable the IP lookup feature in the configuration file.

This package comes with two officially supported providers for IP address lookup (see the IP Address Lookup section in the config/sanctum_tracker.php configuration file).

Ip2Location Lite DB3

This package officially support the IP address geolocation with the Ip2Location Lite DB3.

Here are the steps to enable and use it:

Custom provider

You can add your own providers by creating a class that implements the ALajusticia\SanctumTracker\Interfaces\IpProvider interface and use the ALajusticia\SanctumTracker\Traits\MakesApiCalls trait.

Your custom class have to be registered in the custom_providers array of the configuration file.

Let's see an example of an IP lookup provider with the built-in IpApi provider:

As you can see, the class has a getRequest method that must return a GuzzleHttp\Psr7\Request instance.

Guzzle utilizes PSR-7 as the HTTP message interface. Check its documentation: http://docs.guzzlephp.org/en/stable/psr7.html

The IpProvider interface comes with required methods related to the geolocation. All keys of the API response are accessible in your provider via $this->result, which is a Laravel collection.

If you want to collect other informations, you can add a getCustomData method in your custom provider. This custom data will be saved in the logins table in the ip_data JSON column. Let's see an example of additional data:

Handle API errors

In case of an exception throwed during the API call of your IP address lookup provider, the FailedApiCall event is fired by this package.

This event has an exception attribute containing the GuzzleHttp\Exception\TransferException (see Guzzle documentation).

You can listen to this event to add your own logic.

Events

PersonalAccessTokenCreated

On a new login, you can listen to the ALajusticia\SanctumTracker\Events\PersonalAccessTokenCreated event. It has a personalAccessToken property containing the newly created ALajusticia\SanctumTracker\Models\PersonalAccessToken and a context property that receives a ALajusticia\SanctumTracker\RequestContext object containing all the informations collected on the request.

Available properties:

Available methods:

Available methods in the parser:

Available methods in the IP address lookup provider:

License

Open source, licensed under the MIT license.


All versions of laravel-sanctum-tracker with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
alajusticia/laravel-expirable Version ^1.5
guzzlehttp/guzzle Version ^7.3
illuminate/database Version ^7.0|^8.0
illuminate/queue Version ^7.0|^8.0
illuminate/support Version ^7.0|^8.0
laravel/sanctum Version ^2.9
nesbot/carbon Version ^2.53
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 alajusticia/laravel-sanctum-tracker contains the following files

Loading the files please wait ....