Skip to content

Commit

Permalink
Merge pull request #17 from sander3/skip-re-authentication-feature
Browse files Browse the repository at this point in the history
Re-authentication configuration option
  • Loading branch information
sander3 authored Jul 29, 2018
2 parents f27d62e + 6e2bf4d commit 9e71bf4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
12 changes: 12 additions & 0 deletions config/gdpr.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
'auth',
],

/*
|--------------------------------------------------------------------------
| Re-authentication
|--------------------------------------------------------------------------
|
| Only authenticated users should be able to download their data.
| Re-authentication is recommended to prevent information leakage.
|
*/

're-authenticate' => true,

/*
|--------------------------------------------------------------------------
| Cleanup Strategy
Expand Down
23 changes: 19 additions & 4 deletions src/Http/Controllers/GdprController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GdprController extends Controller
*/
public function download(GdprDownload $request)
{
if (!$this->attemptLogin($request)) {
if (!$this->validateRequest($request)) {
return $this->sendFailedLoginResponse();
}

Expand All @@ -38,19 +38,34 @@ public function download(GdprDownload $request)
}

/**
* Attempt to log the user into the application.
* Validate the request.
*
* @param \Illuminate\Foundation\Http\FormRequest $request
* @return bool
*/
protected function attemptLogin(FormRequest $request)
protected function validateRequest(FormRequest $request)
{
if (config('gdpr.re-authenticate', true)) {
return $this->hasValidCredentials($request);
}

return Auth::check();
}

/**
* Validate a user's credentials.
*
* @param \Illuminate\Foundation\Http\FormRequest $request
* @return bool
*/
protected function hasValidCredentials(FormRequest $request)
{
$credentials = [
$request->user()->getAuthIdentifierName() => $request->user()->getAuthIdentifier(),
'password' => $request->input('password'),
];

return Auth::attempt($credentials);
return Auth::validate($credentials);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Requests/GdprDownload.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function authorize()
public function rules()
{
return [
'password' => 'required|string',
'password' => 'string',
];
}
}

0 comments on commit 9e71bf4

Please sign in to comment.