Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
116 additions
and
0 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
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,40 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Hydra; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Support\Facades\Redirect; | ||
use Ory\Hydra\Client\Api\AdminApi; | ||
use RuntimeException; | ||
use Throwable; | ||
|
||
class LogoutProvider | ||
{ | ||
public function __invoke(Request $request, AdminApi $adminApi) | ||
{ | ||
$logoutChallenge = $request->get('logout_challenge'); | ||
|
||
if (empty($logoutChallenge)) { | ||
throw new RuntimeException('No login_challenge'); | ||
} | ||
|
||
try { | ||
$logoutRequest = $adminApi->getLogoutRequest($logoutChallenge); | ||
} catch (Throwable $e) { | ||
throw new RuntimeException('Hydra Server error: ' . $e->getMessage()); | ||
} | ||
|
||
Log::debug('Logout Request', json_decode((string)$logoutRequest, true)); | ||
|
||
try { | ||
$completedRequest = $adminApi->acceptLogoutRequest($logoutChallenge); | ||
} catch (Throwable $e) { | ||
throw new RuntimeException('Hydra Server error: ' . $e->getMessage()); | ||
} | ||
|
||
Log::debug('Logout Completed Request', json_decode((string)$completedRequest, true)); | ||
|
||
return Redirect::away($completedRequest->getRedirectTo()); | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Support\Facades\Redirect; | ||
|
||
class Logout | ||
{ | ||
public function __invoke(Request $request): RedirectResponse | ||
{ | ||
$idToken = $request->session()->get('id_token'); | ||
|
||
if (null === $idToken) { | ||
throw new \RuntimeException('No login session'); | ||
} | ||
|
||
$query = Arr::query([ | ||
'client_id' => 'my-rp', | ||
'id_token_hint' => $idToken, | ||
'post_logout_redirect_uri' => 'http://127.0.0.1:8000/logout/callback', | ||
'state' => '1a2b3c4d', | ||
]); | ||
|
||
$endSessionEndpoint = 'http://127.0.0.1:4444/oauth2/sessions/logout'; | ||
|
||
$LogoutRequest = $endSessionEndpoint . '?' . $query; | ||
|
||
Log::info('End session request: ' . $LogoutRequest); | ||
|
||
return Redirect::away($LogoutRequest); | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
class LogoutCallback | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
$error = $request->input('error'); | ||
|
||
if (null !== $error) { | ||
dd($request->all()); | ||
} | ||
|
||
return response('登出成功'); | ||
} | ||
} |
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