All packages
Refresh Tokens for Laravel
Device & location enrichment
The package never parses a user agent or geolocates an IP — the host supplies already-parsed data through two DTOs:
use RoundlyConsulting\RefreshTokens\DataTransferObjects\DeviceData;
use RoundlyConsulting\RefreshTokens\DataTransferObjects\LocationData;
use RoundlyConsulting\RefreshTokens\Enums\DeviceType;
// Pass the RefreshToken model you already hold, or its id:
RefreshTokens::session($new->token)->enrich(
new DeviceData(browser: 'Firefox', os: 'Linux', deviceType: DeviceType::Desktop, isBot: false),
new LocationData(country: 'Slovakia', city: 'Bratislava', countryCode: 'SK', ipAddress: '203.0.113.9'),
);- DeviceData — browser, browserVersion, os, osVersion, deviceType (a DeviceType case or a string) and isBot. All optional.
- LocationData — country, city, countryCode and ipAddress. All optional.
Write semantics
- session() accepts the RefreshToken model, an int or a string key; an unknown key throws SessionNotFoundException.
- It only ever touches device and geo columns — never token_hash, revoked_at, expires_at, access_reference or family_id.
- The six device columns are always overwritten — an absent DeviceData field nulls its column.
- Location columns are written only when a LocationData is supplied, so a later device-only enrich never clobbers stored geo.
- Enriched data is carried forward to every replacement on rotation.
Enrich asynchronously
Hook RefreshTokenIssued and do the parsing off the request path:
use Illuminate\Support\Facades\Event;
use RoundlyConsulting\RefreshTokens\Events\RefreshTokenIssued;
Event::listen(function (RefreshTokenIssued $event): void {
// queue your own job: parse the user agent, geolocate the IP,
// then call RefreshTokens::session($event->tokenId)->enrich($device, $location)
});Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.