-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Support swagger-ui's oauth2 redirect
- Loading branch information
1 parent
b87d407
commit 0958daa
Showing
5 changed files
with
59 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace NextApps\SwaggerUi\Http\Controllers; | ||
|
||
use Illuminate\Support\Facades\Http; | ||
|
||
class SwaggerOAuth2RedirectController | ||
{ | ||
public function __invoke() : string | ||
{ | ||
return Http::get('https://unpkg.com/swagger-ui-dist@latest/oauth2-redirect.html')->body(); | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
namespace NextApps\SwaggerUi\Tests; | ||
|
||
use Illuminate\Contracts\Auth\Authenticatable; | ||
use Illuminate\Support\Facades\Gate; | ||
use Illuminate\Support\Facades\Http; | ||
use NextApps\SwaggerUi\Http\Middleware\EnsureUserIsAuthorized; | ||
use NextApps\SwaggerUi\SwaggerUiServiceProvider; | ||
|
||
class SwaggerOAuth2RedirectRouteTest extends TestCase | ||
{ | ||
protected function setUp() : void | ||
{ | ||
parent::setUp(); | ||
|
||
config()->set('swagger-ui.files.0.versions', ['v1' => __DIR__ . '/testfiles/openapi.json']); | ||
config()->set('swagger-ui.files.0.oauth', ['client_id' => 1, 'client_secret' => 'foobar']); | ||
|
||
Gate::define('viewSwaggerUI', fn (?Authenticatable $user) => true); | ||
} | ||
|
||
protected function getPackageProviders($app) : array | ||
{ | ||
return [SwaggerUiServiceProvider::class]; | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_swagger_ui_oauth2_redirect_html_file_content() | ||
{ | ||
Http::fake([ | ||
'https://unpkg.com/swagger-ui-dist@latest/oauth2-redirect.html' => Http::response('foo'), | ||
]); | ||
|
||
$this->get('swagger/oauth2-redirect') | ||
->assertStatus(200) | ||
->assertSeeText('foo'); | ||
|
||
Http::assertSentCount(1); | ||
} | ||
} |