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
6 changed files
with
132 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Hydra; | ||
|
||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Support\Facades\Redirect; | ||
use Ory\Hydra\Client\Api\AdminApi; | ||
use Ory\Hydra\Client\Model\AcceptConsentRequest; | ||
use RuntimeException; | ||
|
||
class AcceptConsent | ||
{ | ||
public function __invoke(Request $request, AdminApi $adminApi): RedirectResponse | ||
{ | ||
$consentChallenge = $request->input('challenge'); | ||
|
||
if (empty($consentChallenge)) { | ||
throw new RuntimeException('No consent_challenge'); | ||
} | ||
|
||
$scopes = $request->input('scopes'); | ||
|
||
if (empty($scopes)) { | ||
// 沒填 scope 就請回去按 reject 的按鈕 | ||
return Redirect::back(); | ||
} | ||
|
||
$acceptConsentRequest = new AcceptConsentRequest([ | ||
'grantScope' => array_keys($scopes), | ||
'remember' => true, | ||
'rememberFor' => 120, | ||
]); | ||
|
||
Log::debug('Accept consent Request', json_decode((string)$acceptConsentRequest, true)); | ||
|
||
try { | ||
$completedRequest = $adminApi->acceptConsentRequest($consentChallenge, $acceptConsentRequest); | ||
} catch (\Throwable $e) { | ||
dd($e); | ||
throw new RuntimeException('Hydra Server error: ' . $e->getMessage()); | ||
} | ||
|
||
Log::debug('Consent Completed Request', json_decode((string)$completedRequest, true)); | ||
|
||
return Redirect::away($completedRequest->getRedirectTo()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Support\Facades\Redirect; | ||
use Ory\Hydra\Client\Api\AdminApi; | ||
use Ory\Hydra\Client\Model\RejectRequest; | ||
use RuntimeException; | ||
|
||
class RejectConsent | ||
{ | ||
public function __invoke(Request $request, AdminApi $adminApi): RedirectResponse | ||
{ | ||
$consentChallenge = $request->input('challenge'); | ||
|
||
if (empty($consentChallenge)) { | ||
throw new RuntimeException('No consent_challenge'); | ||
} | ||
|
||
$rejectRequest = new RejectRequest([ | ||
'error' => 'access_denied', | ||
'errorDescription' => 'The request was rejected by end-user', | ||
]); | ||
|
||
Log::debug('Reject consent Request', json_decode((string)$rejectRequest, true)); | ||
|
||
try { | ||
$completedRequest = $adminApi->rejectConsentRequest($consentChallenge, $rejectRequest); | ||
} catch (\Throwable $e) { | ||
throw new RuntimeException('Hydra Server error: ' . $e->getMessage()); | ||
} | ||
|
||
Log::debug('Consent 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
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