TokenGuard<T extends Authenticatable> class
final
Sanctum-style personal access token guard (BLUEPRINT_V2 §7.6.2).
Token format id|secret: the id gives an O(1) lookup, the secret is
compared as sha256(secret) in constant time. Tokens issued by a Laravel
app sharing the database are accepted and vice versa.
- Inheritance
-
- Object
- RequestGuard<
T> - TokenGuard
Constructors
-
TokenGuard({required String name, required UserProvider<
T> provider, String table = 'personal_access_tokens', Duration? expiration, Duration lastUsedDebounce = const Duration(minutes: 1), String tokenPrefix = '', DatabaseManager? db, DateTime clock()?})
Properties
- db → DatabaseManager
-
no setter
- expiration → Duration?
-
Global lifetime measured from
created_at(Sanctumexpiration);nullmeans tokens live until revoked unless they carryexpires_at.final - hashCode → int
-
The hash code for this object.
no setterinherited
- lastUsedDebounce → Duration
-
Minimum interval between
last_used_atwrites for one token.final - name → String
-
finalinherited
-
provider
→ UserProvider<
T> ? -
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- table → String
-
final
- tokenPrefix → String
-
Prepended to new secrets (Sanctum
token_prefix, e.g.myapp_).final -
users
→ UserProvider<
T> -
no setter
Methods
-
check(
) → Future< bool> -
inherited
-
currentAccessToken(
) → Future< PersonalAccessToken?> - The token used by the current request, if any.
-
findToken(
String plainText) → Future< PersonalAccessToken?> -
Finds the token row for a plain-text token (
id|secretor legacy secret-only) without checking expiry. -
forgetUser(
) → void -
Clears the cached user for the current request/scope.
inherited
-
guest(
) → Future< bool> -
inherited
-
id(
) → Future< Object?> -
inherited
-
issue(
Authenticatable user, String name, {List< String> abilities = const <String>['*'], DateTime? expiresAt}) → Future<NewAccessToken> -
Issues a token for
user($user->createToken()in Sanctum). -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pruneExpired(
{Duration olderThan = Duration.zero}) → Future< int> -
Deletes tokens expired for longer than
olderThan(sanctum:prune-expired --hours=). -
resolveUser(
Request request) → Future< T?> -
Resolves the user for
request(nullwhen unauthenticated).override -
revoke(
Authenticatable user, Object tokenId) → Future< int> -
Deletes one token of
userby id. -
revokeAll(
Authenticatable user) → Future< int> -
Deletes every token of
user. -
revokeCurrent(
) → Future< int> - Deletes the token used by the current request. Returns rows deleted.
-
setUser(
T user) → void -
Sets the user for the current request/scope (tests,
once).inherited -
tokenCan(
String ability) → Future< bool> -
Whether the current request's token grants
ability. -
tokens(
Authenticatable user) → Future< List< PersonalAccessToken> > -
Lists the tokens of
user(newest first). -
toString(
) → String -
A string representation of this object.
inherited
-
user(
) → Future< T?> -
The authenticated user, cached for the current request/scope.
inherited
-
validate(
Map< String, Object?> credentials) → Future<bool> -
Validates credentials without logging the user in.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited