Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JWT requirement for metadata endpoint access #32

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/Resources/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace DreamFactory\Core\Saml\Resources;

use DreamFactory\Core\Exceptions\BadRequestException;
use DreamFactory\Core\Exceptions\InternalServerErrorException;
use DreamFactory\Core\Saml\Services\SAML;
use DreamFactory\Core\Utility\ResponseFactory;
use DreamFactory\Core\Utility\Session as SessionUtilities;

class Metadata extends BaseSamlResource
{
Expand All @@ -15,6 +17,20 @@ class Metadata extends BaseSamlResource
*/
protected function handleGET()
{
// Check if the user is authenticated
if (!SessionUtilities::isAuthenticated()) {
// Return a JSON response with the appropriate headers
return ResponseFactory::create(
[
'error' => [
'code' => 400,
'message' => "No session token (JWT) provided. Please provide a valid JWT using X-DreamFactory-Session-Token request header or 'session_token' url query parameter."
]
],
'application/json', // Set content-type to JSON
400 // HTTP status code
);
}
/** @var SAML $service */
$service = $this->getParent();
$settings = $service->getAuth()->getSettings();
Expand Down Expand Up @@ -53,4 +69,4 @@ protected function getApiDocPaths()

return $base;
}
}
}