You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
22
22
@@ -36,7 +36,7 @@ class User implements JWTSubject
36
36
37
37
> **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.
38
38
39
-
### Create an Authentication Provider
39
+
### 2. Create an Authentication Provider
40
40
41
41
Create an authentication provider class that implements `AuthProviderInterface`. This class will handle credential validation and user retrieval by ID.
42
42
@@ -70,7 +70,7 @@ class AuthProvider implements AuthProviderInterface
70
70
71
71
> **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.
72
72
73
-
### Create a JWT Provider
73
+
### 3. Create a JWT Provider
74
74
75
75
Create a JWT provider class that implements `JWTProviderInterface`. This class should handle encoding and decoding JWT tokens.
76
76
@@ -95,7 +95,7 @@ class JWTProvider implements JWTProviderInterface
95
95
96
96
> **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.
97
97
98
-
### Generate JWT Claims
98
+
### 4. Generate JWT Claims
99
99
100
100
The `ClaimsFactory` class helps create a JWT claims instance. The `build` method accepts an array of claims and returns an instance of `ClaimsInterface`.
> **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.
116
116
117
-
### Initialize the JWT Authenticator
117
+
### 5. Initialize the JWT Authenticator
118
118
119
119
Create a new instance of the `JWTAuth` class. This requires an instance of `AuthProviderInterface`, `JWTProviderInterface`, and `ClaimsInterface`.
0 commit comments