-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to set fully customizable response-handler (#59)
* wip * Rewrite tests in Pest * Remove obsolete workflows, require PHP 7.4 * Fix DefaultResponseHandler namespacing * Fix for dependencies (phpunit) * Testing for response handlers * Check compatibility issue (testbench) * Update response-handler key * Update readme
- Loading branch information
Showing
14 changed files
with
293 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# The MIT License (MIT) | ||
|
||
Copyright (c) 2021 Marcus Olsson <[email protected]> | ||
Copyright (c) 2022 Marcus Olsson <[email protected]> | ||
|
||
> Permission is hereby granted, free of charge, to any person obtaining a copy | ||
> of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Olssonm\VeryBasicAuth\Handlers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
class DefaultResponseHandler implements ResponseHandler | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
// Build header | ||
$header = [ | ||
'WWW-Authenticate' => sprintf( | ||
'Basic realm="%s", charset="UTF-8"', | ||
config('very_basic_auth.realm', 'Basic Auth') | ||
) | ||
]; | ||
|
||
// View | ||
$view = config('very_basic_auth.error_view'); | ||
|
||
// If the request want's JSON, else view | ||
if ($request->wantsJson()) { | ||
return response()->json([ | ||
'message' => config('very_basic_auth.error_message') | ||
], 401, $header); | ||
} elseif (isset($view)) { | ||
return response()->view($view, [], 401) | ||
->withHeaders($header); | ||
} | ||
|
||
// Return default message | ||
return response(config('very_basic_auth.error_message'), 401, $header); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Olssonm\VeryBasicAuth\Handlers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
interface ResponseHandler | ||
{ | ||
public function __invoke(Request $request); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Olssonm\VeryBasicAuth\Tests\Fixtures; | ||
|
||
use Illuminate\Http\Request; | ||
use Olssonm\VeryBasicAuth\Handlers\ResponseHandler; | ||
|
||
class CustomResponseHandler implements ResponseHandler | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
return response('Custom response', 401); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace Olssonm\VeryBasicAuth\Tests; | ||
|
||
uses(TestCase::class)->in(__DIR__); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Olssonm\VeryBasicAuth\Tests; | ||
|
||
use Olssonm\VeryBasicAuth\VeryBasicAuthServiceProvider; | ||
use Orchestra\Testbench\TestCase as OrchestraTestCase; | ||
|
||
abstract class TestCase extends OrchestraTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
} | ||
|
||
protected function getPackageProviders($app) | ||
{ | ||
return [ | ||
VeryBasicAuthServiceProvider::class | ||
]; | ||
} | ||
|
||
public static function tearDownAfterClass(): void | ||
{ | ||
parent::tearDownAfterClass(); | ||
unlink(__DIR__ . '/../src/config.php'); | ||
} | ||
} |
Oops, something went wrong.