Skip to content

Commit 82cfef7

Browse files
committed
wip
1 parent 4303147 commit 82cfef7

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

config/mailbox.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,28 @@
2626
*/
2727
'store_incoming_emails_for_days' => 1,
2828

29+
/*
30+
* Some services do not have their own authentication methods to
31+
* verify the incoming request. For these services, you need
32+
* to use this username and password combination for HTTP
33+
* basic authentication.
34+
*
35+
* See the driver specific documentation if it applies to your
36+
* driver.
37+
*/
38+
'basic_auth' => [
39+
'username' => env('MAILBOX_HTTP_USERNAME', 'laravel-mailbox'),
40+
'password' => env('MAILBOX_HTTP_PASSWORD')
41+
],
42+
2943
/*
3044
* Third party service configuration.
3145
*/
3246
'services' => [
3347

3448
'mailgun' => [
3549
'key' => env('MAILBOX_MAILGUN_KEY'),
36-
]
50+
],
3751

3852
]
3953

src/Http/Controllers/SendGridController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
namespace BeyondCode\Mailbox\Http\Controllers;
44

5+
use Illuminate\Routing\Controller;
56
use BeyondCode\Mailbox\Facades\Mailbox;
67
use BeyondCode\Mailbox\Http\Requests\SendGridRequest;
78

8-
class SendGridController
9+
class SendGridController extends Controller
910
{
11+
public function __construct()
12+
{
13+
$this->middleware('laravel-mailbox');
14+
}
15+
1016
public function __invoke(SendGridRequest $request)
1117
{
1218
Mailbox::callMailboxes($request->email());
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace BeyondCode\Mailbox\Http\Middleware;
4+
5+
use Closure;
6+
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
7+
8+
class MailboxBasicAuthentication
9+
{
10+
public function handle($request, Closure $next)
11+
{
12+
$user = $request->getUser();
13+
$password = $request->getPassword();
14+
15+
if (($user === config('mailbox.basic_auth.username') && $password === config('mailbox.basic_auth.password'))) {
16+
return $next($request);
17+
}
18+
19+
throw new UnauthorizedHttpException('Laravel Mailbox');
20+
}
21+
}

src/MailboxServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace BeyondCode\Mailbox;
44

5+
use BeyondCode\Mailbox\Http\Middleware\MailboxBasicAuthentication;
56
use BeyondCode\Mailbox\Routing\Router;
7+
use Illuminate\Support\Facades\Route;
68
use Illuminate\Support\ServiceProvider;
79

810
class MailboxServiceProvider extends ServiceProvider
@@ -22,6 +24,8 @@ public function boot()
2224
__DIR__.'/../config/mailbox.php' => config_path('mailbox.php')
2325
], 'config');
2426

27+
Route::aliasMiddleware('laravel-mailbox', MailboxBasicAuthentication::class);
28+
2529
$this->registerDriver();
2630
}
2731

0 commit comments

Comments
 (0)