Skip to content

Commit dc0c119

Browse files
authored
Merge pull request #10 from RhubarbPHP/feature/tokenExpiryExtension
Feature/token expiry extension
2 parents f552ad6 + 9558319 commit dc0c119

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
### 3.0.6
4+
5+
* Added: RememberMe body parameter for extending login token to 30 days rather than 1 day.
6+
37
### 3.0.5
48

59
* Changed: Extract JWT token generation to a public function so it can be used from other places.

src/TokenBasedRestApiModule.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ protected function authenticate(Request $request)
119119
}
120120
}
121121

122-
public function createJwtTokenForLoggedInUser($authData) : string {
123-
$expiry = new \DateTime('now +1 day');
122+
public function createJwtTokenForLoggedInUser($authData, $expiry = null) : string {
123+
$expiry = isset($expiry) ? $expiry : new \DateTime('now +1 day');
124124

125125
return JWT::encode(
126126
[
@@ -170,10 +170,12 @@ public function registerRoutes(App $app)
170170
}
171171

172172
list($status, $authData) = $self->authenticate($request);
173+
$rememberMe = $request->getParsedBodyParam('rememberMe');
174+
$expiry = $rememberMe ? new \DateTime('now +30 day'): new \DateTime('now +1 day');
173175

174176
if ($status) {
175177
$data = [
176-
'token' => $self->createJwtTokenForLoggedInUser($authData)
178+
'token' => $self->createJwtTokenForLoggedInUser($authData, $expiry)
177179
];
178180

179181
return $response

0 commit comments

Comments
 (0)