Skip to content

Commit b76f08f

Browse files
authored
docs: 📚 update README.md
docs: 📚 update README.md
2 parents 8681dbd + 3fe3a56 commit b76f08f

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
![JWT Auth](https://raw.githubusercontent.com/andrewdyer/andrewdyer/refs/heads/main/assets/images/covers/jwt-auth.png)
22

3-
# JWT Auth
3+
# 🔑 JWT Auth
44

55
A simple framework-agnostic JSON Web Token authentication solution.
66

7-
## Installation
7+
## 📄 License
8+
9+
Licensed under the [MIT license](https://opensource.org/licenses/MIT) and is free for private or commercial projects.
10+
11+
## 📥 Installation
812

913
```bash
1014
composer require andrewdyer/jwt-auth
1115
```
1216

13-
## Getting Started
17+
## 🚀 Getting Started
1418

15-
### Define the JWT Subject
19+
### 1. Define the JWT Subject
1620

1721
Create a class (e.g., `User`) that implements the `JWTSubject` interface. This class must provide a method `getJWTIdentifier` to return the user’s unique identifier.
1822

@@ -32,7 +36,7 @@ class User implements JWTSubject
3236

3337
> **Note:** This example is simplified for demonstration purposes. In a real-world application, you would typically use a proper user model, such as one provided by your framework. Ensure the `getJWTIdentifier` method returns a unique user identifier appropriate for your system.
3438
35-
### Create an Authentication Provider
39+
### 2. Create an Authentication Provider
3640

3741
Create an authentication provider class that implements `AuthProviderInterface`. This class will handle credential validation and user retrieval by ID.
3842

@@ -66,7 +70,7 @@ class AuthProvider implements AuthProviderInterface
6670

6771
> **Note:** This example uses hardcoded credentials for demonstration purposes. In a real-world application, you should validate credentials securely by checking against a database and using hashed passwords (e.g., via libraries like `bcrypt` or `password_hash`). Ensure you follow best practices for secure authentication.
6872
69-
### Create a JWT Provider
73+
### 3. Create a JWT Provider
7074

7175
Create a JWT provider class that implements `JWTProviderInterface`. This class should handle encoding and decoding JWT tokens.
7276

@@ -91,7 +95,7 @@ class JWTProvider implements JWTProviderInterface
9195

9296
> **Note:** This examples used `base64_encode` and `base64_decode` for simplicity. For real-world usage, consider using a proper JWT library such as [firebase/php-jwt](https://github.com/firebase/php-jwt) for better security.
9397
94-
### Generate JWT Claims
98+
### 4. Generate JWT Claims
9599

96100
The `ClaimsFactory` class helps create a JWT claims instance. The `build` method accepts an array of claims and returns an instance of `ClaimsInterface`.
97101

@@ -110,7 +114,7 @@ $claims = ClaimsFactory::build([
110114

111115
> **Note:** This example uses hardcoded Unix timestamps for demonstration purposes. Consider using libraries like [nesbot/carbon](https://github.com/briannesbitt/carbon) or PHP's native `DateTime` class to generate timestamps dynamically. This helps improve readability and ensures accurate date handling.
112116
113-
### Initialize the JWT Authenticator
117+
### 5. Initialize the JWT Authenticator
114118

115119
Create a new instance of the `JWTAuth` class. This requires an instance of `AuthProviderInterface`, `JWTProviderInterface`, and `ClaimsInterface`.
116120

@@ -126,7 +130,7 @@ $jwtProvider = new JWTProvider();
126130
$jwtAuth = new JWTAuth($authProvider, $jwtProvider, $claims);
127131
```
128132

129-
## Usage
133+
## 📖 Usage
130134

131135
### Attempt Authentication
132136

@@ -154,7 +158,3 @@ if ($subject) {
154158
echo "Invalid token";
155159
}
156160
```
157-
158-
## License
159-
160-
Licensed under MIT. Totally free for private or commercial projects.

0 commit comments

Comments
 (0)