Skip to content
This repository was archived by the owner on Sep 5, 2017. It is now read-only.

Commit 5013cdc

Browse files
committed
Setup AutoJoiner route & check GitHub secret
1 parent 507d1cd commit 5013cdc

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ GITHUB_ID=
3737
GITHUB_SECRET=
3838
GITHUB_CALLBACK=
3939

40+
GITHUB_AUTOJOINER_SECRET=
41+
4042
RECAPTCHA_PUBLIC_KEY=
4143
RECAPTCHA_PRIVATE_KEY=
4244

app/Http/Controllers/AutoJoinerController.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,19 @@
66

77
class AutoJoinerController extends Controller
88
{
9-
//
9+
public function index(Request $request)
10+
{
11+
abort_unless($this->requestSignatureIsValid(), 403);
12+
13+
//
14+
}
15+
16+
protected function requestSignatureIsValid() : bool
17+
{
18+
$gitHubSignature = request()->header('X-Hub-Signature');
19+
list($usedAlgorithm, $gitHubHash) = explode('=', $gitHubSignature, 2);
20+
$payload = file_get_contents('php://input');
21+
$calculatedHash = hash_hmac($usedAlgorithm, $payload, config('auth.github_secret'));
22+
return $calculatedHash === $gitHubHash;
23+
}
1024
}

app/Http/Middleware/VerifyCsrfToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ class VerifyCsrfToken extends BaseVerifier
1212
* @var array
1313
*/
1414
protected $except = [
15-
//
15+
'autojoiner',
1616
];
1717
}

config/auth.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,17 @@
9999
],
100100
],
101101

102+
/*
103+
|--------------------------------------------------------------------------
104+
| GitHub Secret
105+
|--------------------------------------------------------------------------
106+
|
107+
| You may specify a secret so we can check the data comes from GitHub
108+
| and prevent attacks.
109+
|
110+
*/
111+
112+
'github_secret' => env('GITHUB_AUTOJOINER_SECRET'),
113+
114+
102115
];

routes/web.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@
3636
Route::get('login', 'LoginController@authorizeUser');
3737
Route::get('callback', 'LoginController@loginUser');
3838
Route::post('logout', 'LoginController@logoutUser');
39+
40+
// Autojoiner
41+
Route::post('autojoiner', 'AutoJoinerController@index');

0 commit comments

Comments
 (0)