-
Notifications
You must be signed in to change notification settings - Fork 7
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
1 parent
2c23905
commit f3ff6ac
Showing
7 changed files
with
51 additions
and
12 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
34 changes: 34 additions & 0 deletions
34
sourcecode/apis/contentauthor/app/Http/Middleware/LtiSignedLaunch.php
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,34 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; | ||
|
||
/** | ||
* Verify that a signed LTI launch happened. | ||
*/ | ||
final readonly class LtiSignedLaunch | ||
{ | ||
/** | ||
* @param (Closure(Request): Response) $next | ||
*/ | ||
public function handle(Request $request, Closure $next): Response | ||
{ | ||
if ( | ||
$request->session()->get('signedLaunch') || | ||
// For backwards compat. | ||
// Cannot be set without a signed launch also having occurred. | ||
$request->session()->get('authId') | ||
) { | ||
return $next($request); | ||
} | ||
|
||
throw new UnauthorizedHttpException( | ||
challenge: 'OAuth', | ||
message: 'A valid LTI launch is required to have occurred', | ||
); | ||
} | ||
} |
13 changes: 8 additions & 5 deletions
13
sourcecode/apis/contentauthor/app/Http/Middleware/LtiVerifyAuth.php
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,26 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Session; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
use function abort; | ||
|
||
/** | ||
* Verify that the user is authenticated via LTI. | ||
*/ | ||
class LtiVerifyAuth | ||
final readonly class LtiVerifyAuth | ||
{ | ||
/** | ||
* @param (Closure(Request): Response) $next | ||
*/ | ||
public function handle(Request $request, Closure $next): Response | ||
{ | ||
if (Session::get('authId')) { | ||
return $next($request); | ||
if (!$request->session()->get('authId')) { | ||
abort(Response::HTTP_FORBIDDEN); | ||
} | ||
|
||
return redirect('auth/login'); | ||
return $next($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