-
Notifications
You must be signed in to change notification settings - Fork 17
JWT Auth integration #460
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
Closed
Closed
JWT Auth integration #460
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2bfcdb4
upgrade Opencast PHP Library to 2.0.0
ferishili 5214079
JWT Integration:
ferishili 8c5da84
improvements and fixes
ferishili 390f790
minor styling
ferishili 61d353d
change request: get rid of class PluginConfig in src classes
ferishili 3a8abf8
jwt iframe player
ferishili 1199726
latest changes regarding livestreams + iframe
ferishili 385daed
additional adjustments
ferishili ec836af
fix: no dynamic property
ferishili b26ef48
minor fix
ferishili 7ab2a5a
Merge branch 'release_9' into jwt
ferishili 2c29c85
changes according to request: part 1
ferishili 4e25a9f
require and rebuild composer with php 8.1,
ferishili b8c59db
annotation-tool JWT compatibility
ferishili ed488f3
enhancement: make sure specific publication usages remain untouched
ferishili File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -16,7 +16,6 @@ | |
| use srag\Plugins\Opencast\Util\Player\PlayerDataBuilderFactory; | ||
| use srag\Plugins\Opencast\Util\FileTransfer\PaellaConfigStorageService; | ||
| use srag\Plugins\Opencast\LegacyHelpers\TranslatorTrait; | ||
| use ILIAS\DI\HTTPServices; | ||
| use srag\Plugins\Opencast\Util\OutputResponse; | ||
|
|
||
| /** | ||
|
|
@@ -65,31 +64,54 @@ public function streamVideo(): void | |
| if ($this->identifier === null || empty($this->identifier)) { | ||
| $this->sendReponse("Error: invalid identifier"); | ||
| } | ||
|
|
||
| $jwt_iframe_capable = false; | ||
| $event = $this->event_repository->find($this->identifier); | ||
| if (!PluginConfig::getConfig(PluginConfig::F_INTERNAL_VIDEO_PLAYER) && !$event->isLiveEvent()) { | ||
| if (!$this->api->isJWTActivated() // We don't offer this redirect if JWT is activated. | ||
| && !PluginConfig::getConfig(PluginConfig::F_INTERNAL_VIDEO_PLAYER) | ||
| && !$event->isLiveEvent()) { | ||
| // redirect to opencast | ||
| header('Location: ' . $event->publications()->getPlayerLink()); | ||
| $this->closeResponse(); | ||
| } | ||
|
|
||
| try { | ||
| $data = PlayerDataBuilderFactory::getInstance()->getBuilder($event)->buildStreamingData(); | ||
| $player_data_builder = PlayerDataBuilderFactory::getInstance()->getBuilder($event); | ||
| $jwt_iframe_capable = $player_data_builder->shouldPlayInJWTIframe(); | ||
| // For the data structure, we have now a new parameter "jwt", which contains the jwt related data and needs to extracted later on. | ||
| $data = $player_data_builder->buildStreamingData(); | ||
| } catch (xoctException $e) { | ||
| xoctLog::getInstance()->logError((string) $e->getCode(), $e->getMessage()); | ||
| xoctLog::getInstance()->logStack($e->getTraceAsString()); | ||
| $this->sendReponse("Error: " . $e->getMessage()); | ||
| } | ||
|
|
||
| // We load different template for the JWT Iframe Player. | ||
| if ($this->api->isJWTActivated() && $jwt_iframe_capable) { | ||
| $tpl = $this->plugin->getTemplate("jwt_iframe_player.html", true, true); | ||
| $jwt_data = $data['jwt'] ?? []; | ||
| $tpl->setVariable("JWT_MODULE_CONFIG", | ||
|
ferishili marked this conversation as resolved.
|
||
| json_encode($this->buildJwtModuleConfig($event, $jwt_data))); | ||
| } else { | ||
| // The normal paella player. | ||
| $tpl = $this->plugin->getTemplate("paella_player.html", true, true); | ||
| // Clear the data from JWT specific data. | ||
| if (isset($data['jwt'])) { | ||
| unset($data['jwt']); | ||
| } | ||
| $tpl->setVariable("DATA", json_encode($data)); | ||
| $tpl->setVariable("JS_CONFIG", json_encode($this->buildJSConfig($event))); | ||
| } | ||
|
|
||
| if (empty($tpl)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. due to the if/else, $tpl cannot be empty right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean, we should get rid of |
||
| $this->sendReponse("Error: unable to render proper template!"); | ||
| } | ||
|
|
||
| $jquery_path = iljQueryUtil::getLocaljQueryPath(); | ||
| $ilias_basic_js_path = './Services/JavaScript/js/Basic.js'; | ||
| $tpl = $this->plugin->getTemplate("paella_player.html", true, true); | ||
|
|
||
| $tpl->setVariable("JQUERY_PATH", $jquery_path); | ||
| $tpl->setVariable("ILIAS_BASIC_JS_PATH", $ilias_basic_js_path); | ||
|
|
||
| $tpl->setVariable("TITLE", $event->getTitle()); | ||
| $tpl->setVariable("DATA", json_encode($data)); | ||
| $tpl->setVariable("JS_CONFIG", json_encode($this->buildJSConfig($event))); | ||
|
|
||
| if ($event->isLiveEvent()) { | ||
| $tpl->setVariable( | ||
|
|
@@ -167,6 +189,42 @@ protected function buildJSConfig(Event $event): stdClass | |
| return $js_config; | ||
| } | ||
|
|
||
| protected function buildJwtModuleConfig(Event $event, array $jwt_data): stdClass | ||
| { | ||
| $jwt_module_config = new stdClass(); | ||
| $jwt_module_config->refresh_token_url = $this->getRefreshJwtAsyncUrl($event->getIdentifier(), $this->object_settings->getObjId()); | ||
| $player_url = null; | ||
| if (!empty($jwt_data['jwt_iframe_urls'])) { | ||
| $player_url = reset($jwt_data['jwt_iframe_urls']); // We take the first one, no matter how many is there! | ||
| } | ||
| // We make the fallback here! | ||
| if (empty($player_url)) { | ||
| $base_url = PluginConfig::getConfig(PluginConfig::F_PRESENTATION_NODE) | ||
| ?? PluginConfig::getConfig(PluginConfig::F_API_BASE); | ||
| $player_url = $this->api->makeJwtIframeSourceUrl($base_url, $event->getIdentifier()); | ||
| } | ||
| $jwt_module_config->player_url = $player_url; | ||
| $jwt_module_config->event_id = $event->getIdentifier(); | ||
| $jwt_module_config->is_live_stream = $event->isLiveEvent(); | ||
| if ($jwt_module_config->is_live_stream) { | ||
| $jwt_module_config->hls_source_urls = $jwt_data['urls'] ?? []; | ||
| $jwt_module_config->hls_check_script = ILIAS_HTTP_PATH . '/' . $this->plugin->getDirectory() . '/src/Util/check_hls_status.php'; | ||
| $jwt_module_config->hls_source_format = | ||
| PluginConfig::getConfig(PluginConfig::F_LIVESTREAM_TYPE) ?? 'hls'; | ||
| $start_utc_atom = $event->getScheduling() | ||
|
ferishili marked this conversation as resolved.
|
||
| ?->getStart() | ||
| ->setTimezone(new \DateTimeZone('UTC')) | ||
| ->format(\DateTime::ATOM) ?? null; | ||
| $end_utc_atom = $event->getScheduling() | ||
| ?->getEnd() | ||
| ->setTimezone(new \DateTimeZone('UTC')) | ||
| ->format(\DateTime::ATOM) ?? null; | ||
| $jwt_module_config->start_time_utc = $start_utc_atom; | ||
| $jwt_module_config->end_time_utc = $end_utc_atom; | ||
| } | ||
| return $jwt_module_config; | ||
| } | ||
|
|
||
| /** | ||
| * Function to check whether the chat must be provided to the user based on the following conditions: | ||
| * - Event must be identified as Live or has chat records already (was live before) | ||
|
|
||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.