TokenBindingService
in package
Table of Contents
Properties
- $geoLocationService : GeoLocationService
- $logger : LoggerInterface
Methods
- __construct() : mixed
- cleanupExpiredTrackingData() : int
- Clean up expired tracking data (call this from a scheduled job)
- generateClientFingerprint() : string
- generateSessionId() : string
- getSecurityStats() : array<string|int, mixed>
- Get security statistics for monitoring
- validateTokenBinding() : array<string|int, mixed>
- checkConcurrentIpUsage() : array<string|int, mixed>
- Check if token is being used from multiple IPs concurrently This is our primary defense against token theft
- isRapidIpChange() : bool
- Check if IP is changing too rapidly (possible attack)
- isSuspiciousGeoJump() : bool
- Check for suspicious geographic jumps (too far, too fast)
- revokeAllUserTokens() : void
- Revoke all tokens for a user (security breach response)
- sendConcurrentAccessNotification() : void
- Send critical notification for concurrent access attempt
- sendGeoChangeNotification() : void
- shouldNotifyGeoChange() : bool
- trackTokenIpUsage() : void
- Track token usage by IP for concurrent detection
- updateTokenIpData() : void
- validateIpAddress() : array<string|int, mixed>
Properties
$geoLocationService read-only
private
GeoLocationService
$geoLocationService
$logger read-only
private
LoggerInterface
$logger
Tags
Attributes
- #[LogChannel]
- \App\Modules\Logging\Channel::Security
Methods
__construct()
public
__construct(GeoLocationService $geoLocationService) : mixed
Parameters
- $geoLocationService : GeoLocationService
cleanupExpiredTrackingData()
Clean up expired tracking data (call this from a scheduled job)
public
cleanupExpiredTrackingData() : int
Return values
intgenerateClientFingerprint()
public
generateClientFingerprint(Request $request) : string
Parameters
- $request : Request
Return values
stringgenerateSessionId()
public
generateSessionId() : string
Return values
stringgetSecurityStats()
Get security statistics for monitoring
public
getSecurityStats() : array<string|int, mixed>
Return values
array<string|int, mixed>validateTokenBinding()
public
validateTokenBinding(PersonalAccessToken $token, Request $request) : array<string|int, mixed>
Parameters
- $token : PersonalAccessToken
- $request : Request
Return values
array<string|int, mixed>checkConcurrentIpUsage()
Check if token is being used from multiple IPs concurrently This is our primary defense against token theft
private
checkConcurrentIpUsage(PersonalAccessToken $token, string $currentIp) : array<string|int, mixed>
Parameters
- $token : PersonalAccessToken
- $currentIp : string
Return values
array<string|int, mixed>isRapidIpChange()
Check if IP is changing too rapidly (possible attack)
private
isRapidIpChange(PersonalAccessToken $token, string $newIp) : bool
Parameters
- $token : PersonalAccessToken
- $newIp : string
Return values
boolisSuspiciousGeoJump()
Check for suspicious geographic jumps (too far, too fast)
private
isSuspiciousGeoJump(PersonalAccessToken $token, array<string|int, mixed> $newLocationData) : bool
Parameters
- $token : PersonalAccessToken
- $newLocationData : array<string|int, mixed>
Return values
boolrevokeAllUserTokens()
Revoke all tokens for a user (security breach response)
private
revokeAllUserTokens(int $userId, string $reason) : void
Parameters
- $userId : int
- $reason : string
sendConcurrentAccessNotification()
Send critical notification for concurrent access attempt
private
sendConcurrentAccessNotification(PersonalAccessToken $token, string $currentIp, array<string|int, mixed> $concurrentIps) : void
Parameters
- $token : PersonalAccessToken
- $currentIp : string
- $concurrentIps : array<string|int, mixed>
sendGeoChangeNotification()
private
sendGeoChangeNotification(PersonalAccessToken $token, array<string|int, mixed> $locationData, string $ipAddress, Request $request) : void
Parameters
- $token : PersonalAccessToken
- $locationData : array<string|int, mixed>
- $ipAddress : string
- $request : Request
shouldNotifyGeoChange()
private
shouldNotifyGeoChange(PersonalAccessToken $token, array<string|int, mixed> $currentLocationData) : bool
Parameters
- $token : PersonalAccessToken
- $currentLocationData : array<string|int, mixed>
Return values
booltrackTokenIpUsage()
Track token usage by IP for concurrent detection
private
trackTokenIpUsage(PersonalAccessToken $token, string $ip) : void
Parameters
- $token : PersonalAccessToken
- $ip : string
updateTokenIpData()
private
updateTokenIpData(PersonalAccessToken $token, string $currentIpAddress, array<string|int, mixed> $locationData) : void
Parameters
- $token : PersonalAccessToken
- $currentIpAddress : string
- $locationData : array<string|int, mixed>
validateIpAddress()
private
validateIpAddress(PersonalAccessToken $token, string $currentIpAddress, Request $request) : array<string|int, mixed>
Parameters
- $token : PersonalAccessToken
- $currentIpAddress : string
- $request : Request