Skip to content

Commit

Permalink
Invalidates token when user changes their password
Browse files Browse the repository at this point in the history
  • Loading branch information
artstorm committed Aug 26, 2015
1 parent d901fd3 commit 00be998
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/app/Http/Controllers/UserController.php
Expand Up @@ -177,6 +177,12 @@ public function patchOne(Request $request, $id)
// Extract the credentials and update if necessary
$credentialUpdateDetails = $request->get('_user_credential', []);
if (!empty($credentialUpdateDetails)) {
// Invalidate token for the user when user changes their password
if ($this->jwtAuth->user()->user_id == $model->user_id) {
$token = $this->jwtAuth->getTokenFromRequest();
$this->jwtAuth->invalidate($token);
}

$credentials = UserCredential::findOrNew($id);
/** @var UserCredential $credentials */
$credentials->fill($credentialUpdateDetails);
Expand Down
7 changes: 7 additions & 0 deletions api/tests/integration/UserTest.php
Expand Up @@ -304,6 +304,13 @@ public function testPatchOneBySelfUserPassword()
$this->assertResponseStatus(204);
$this->assertResponseHasNoContent();
$this->assertTrue(Hash::check('foobarfoobar', $updatedCredentials->password));

// Assert token is invalid
$jwtAuth = App::make('Tymon\JWTAuth\JWTAuth');
$blacklist = $jwtAuth->getBlacklist();
$payload = $jwtAuth->getJWTProvider()->decode($token);
$payload = $jwtAuth->getPayloadFactory()->setRefreshFlow(false)->make($payload);
$this->assertTrue($blacklist->has($payload));
}

public function testPatchOneByGuestUser()
Expand Down

0 comments on commit 00be998

Please sign in to comment.