Skip to content

Commit 9e71bf4

Browse files
authored
Merge pull request #17 from sander3/skip-re-authentication-feature
Re-authentication configuration option
2 parents f27d62e + 6e2bf4d commit 9e71bf4

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

config/gdpr.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@
2929
'auth',
3030
],
3131

32+
/*
33+
|--------------------------------------------------------------------------
34+
| Re-authentication
35+
|--------------------------------------------------------------------------
36+
|
37+
| Only authenticated users should be able to download their data.
38+
| Re-authentication is recommended to prevent information leakage.
39+
|
40+
*/
41+
42+
're-authenticate' => true,
43+
3244
/*
3345
|--------------------------------------------------------------------------
3446
| Cleanup Strategy

src/Http/Controllers/GdprController.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class GdprController extends Controller
1818
*/
1919
public function download(GdprDownload $request)
2020
{
21-
if (!$this->attemptLogin($request)) {
21+
if (!$this->validateRequest($request)) {
2222
return $this->sendFailedLoginResponse();
2323
}
2424

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

4040
/**
41-
* Attempt to log the user into the application.
41+
* Validate the request.
4242
*
4343
* @param \Illuminate\Foundation\Http\FormRequest $request
4444
* @return bool
4545
*/
46-
protected function attemptLogin(FormRequest $request)
46+
protected function validateRequest(FormRequest $request)
47+
{
48+
if (config('gdpr.re-authenticate', true)) {
49+
return $this->hasValidCredentials($request);
50+
}
51+
52+
return Auth::check();
53+
}
54+
55+
/**
56+
* Validate a user's credentials.
57+
*
58+
* @param \Illuminate\Foundation\Http\FormRequest $request
59+
* @return bool
60+
*/
61+
protected function hasValidCredentials(FormRequest $request)
4762
{
4863
$credentials = [
4964
$request->user()->getAuthIdentifierName() => $request->user()->getAuthIdentifier(),
5065
'password' => $request->input('password'),
5166
];
5267

53-
return Auth::attempt($credentials);
68+
return Auth::validate($credentials);
5469
}
5570

5671
/**

src/Http/Requests/GdprDownload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function authorize()
2424
public function rules()
2525
{
2626
return [
27-
'password' => 'required|string',
27+
'password' => 'string',
2828
];
2929
}
3030
}

0 commit comments

Comments
 (0)