Skip to content

Commit

Permalink
feature/main setting up signed webkey authentication. removing unused…
Browse files Browse the repository at this point in the history
… cold.
  • Loading branch information
2amjsouza committed Aug 9, 2023
1 parent 5d66d71 commit c206e33
Show file tree
Hide file tree
Showing 29 changed files with 195 additions and 1,094 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ use Laravel\Sanctum\PersonalAccessToken;
// from this
return [
...
'attachments-allowed-mimetypes' => env('ATTACHMENT_MIMETYPES', ['application/pdf', 'image/*']),
'attachmentsAllowedMimetypes' => env('ATTACHMENT_MIMETYPES', ['application/pdf', 'image/*']),
];

// to this
return [
...
'attachments-allowed-mimetypes' => env('ATTACHMENT_MIMETYPES', '*'),
'attachmentsAllowedMimetypes' => env('ATTACHMENT_MIMETYPES', '*'),
];
```

Expand Down
52 changes: 52 additions & 0 deletions app/Console/Commands/CreateSignature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Console\Commands;

use App\Models\User;
use App\Providers\AuthorizationProvider;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;

class CreateSignature extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:create-signature';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Creates signature for http requests';

/**
* Execute the console command.
*/
public function handle()
{
$this->info('Laravel API Service');
$this->info('Signed access token generation script.');
$this->warn('Before moving ahead, define your access key in ./config/laravel-mail-api-token.php');
$this->info('---------------------------------------');

$accessKey = $this->ask('Inform the Token Access Key');

$tokenAttributes = AuthorizationProvider::getTokenProperties($accessKey);
$timezone = Carbon::now()->toIso8601String();
$this->info('tz: ' . $timezone);
$signature = AuthorizationProvider::signToken(
token: $tokenAttributes['appKey'],
timeStamp: $timezone,
secret: $tokenAttributes['appSecret'],
);

$this->info($signature);

return 1;
}
}
50 changes: 0 additions & 50 deletions app/Console/Commands/CreateUser.php

This file was deleted.

77 changes: 0 additions & 77 deletions app/Http/Controllers/Api/AuthController.php

This file was deleted.

27 changes: 0 additions & 27 deletions app/Http/Controllers/Api/CreateToken.php

This file was deleted.

9 changes: 7 additions & 2 deletions app/Http/Controllers/Api/SendEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
use App\Http\Controllers\Controller;
use App\Jobs\EmailDispatcher;
use App\Jobs\FilesCleanup;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Bus;

class SendEmail extends Controller
{
public function send(Request $request)
/**
* @param Request $request
* @return JsonResponse
*/
public function __invoke(Request $request): JsonResponse
{
$this->validateRequest($request);

Expand Down Expand Up @@ -52,7 +57,7 @@ public function send(Request $request)
*/
private function validateRequest(Request $request): void
{
$allowedMimeTypes = config('laravel-mail-api.attachments-allowed-mimetypes');
$allowedMimeTypes = config('laravel-mail-api.attachmentsAllowedMimetypes');

$rules = [
'from' => 'required|email',
Expand Down
7 changes: 3 additions & 4 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Http;

use App\Http\Middleware\CheckAuth;
use App\Http\Middleware\Authorize;
use App\Http\Middleware\ExpectsJsonResponse;
use Illuminate\Foundation\Http\Kernel as HttpKernel;

Expand Down Expand Up @@ -37,10 +37,9 @@ class Kernel extends HttpKernel
],

'api' => [
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
\Illuminate\Routing\Middleware\ThrottleRequests::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
CheckAuth::class,
Authorize::class,
ExpectsJsonResponse::class,
],
];
Expand Down
25 changes: 25 additions & 0 deletions app/Http/Middleware/Authorize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use App\Providers\AuthorizationProvider;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class Authorize
{
/**
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
Log::info('Validate token authorization');

AuthorizationProvider::authorize($request);

return $next($request);
}
}
34 changes: 0 additions & 34 deletions app/Http/Middleware/CheckAuth.php

This file was deleted.

Loading

0 comments on commit c206e33

Please sign in to comment.