Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update auth-guard.md: intro text for custom claims and TTL #2110

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions docs/auth-guard.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ try {

```

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

### logout()

Expand All @@ -73,7 +73,7 @@ auth()->logout(true);

### refresh()

Refresh a token, which invalidates the current one
Refresh a token, which invalidates the current one.

```php
$newToken = auth()->refresh();
Expand All @@ -85,7 +85,7 @@ $newToken = auth()->refresh(true, true);

### invalidate()

Invalidate the token (add it to the blacklist)
Invalidate the token (add it to the blacklist).

```php
auth()->invalidate();
Expand All @@ -104,7 +104,7 @@ $token = auth()->tokenById(123);

### payload()

Get the raw JWT payload
Get the raw JWT payload.

```php
$payload = auth()->payload();
Expand All @@ -118,7 +118,7 @@ $payload->toArray(); // = ['sub' => 123, 'exp' => 123456, 'jti' => 'asfe4fq434as

### validate()

Validate a user's credentials
Validate a user's credentials.

```php
if (auth()->validate($credentials)) {
Expand All @@ -129,6 +129,7 @@ if (auth()->validate($credentials)) {
## More advanced usage

### Adding custom claims
Use `getJWTCustomClaims` on your `JWTSubject` for claims specific to your authenticated users. Other than that, add custom claims like this:

```php
$token = auth()->claims(['foo' => 'bar'])->attempt($credentials);
Expand All @@ -147,7 +148,8 @@ $user = auth()->setRequest($request)->user();
```

### Override the token ttl
This example sets the token to expire after 2 hours.

```php
$token = auth()->setTTL(7200)->attempt($credentials);
$token = auth()->setTTL(120)->attempt($credentials);
```