定制 co-stack/typo3-easy-request-token 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

co-stack/typo3-easy-request-token

最新稳定版本:1.0.1

Composer 安装命令:

composer require co-stack/typo3-easy-request-token

包简介

TYPO3 CMS Extension to make handling RequestToken easy

README 文档

README

Takes the mental load of JWT, Nonce, Cookie, URI, etc. in TYPO3 away. Focus on your application, nothing more.

Usage

This usage illustrates the generation and consumption of the SecurityObjects.

namespace Vendor\Package;

use Exception;use TYPO3\CMS\Core\Utility\GeneralUtility;
use CoStack\EasyRequestToken\Security\SecurityObjectsFactory;
use CoStack\EasyRequestToken\Security\LockedSecurityObjects;
use CoStack\EasyRequestToken\Http\NonceCookie;
use CoStack\EasyRequestToken\Http\RedirectResponse;
use TYPO3\CMS\Core\Http\PropagateResponseException;
use TYPO3\CMS\Backend\Routing\UriBuilder;

class YourConsumer
{
    public function redirect(): never
    {
        // You can put anything in params which can be json_encoded.
        // These values are accessible (and trusted!) when receiving the request token.
        $params = [];

        // If using for something else than a backend authentication, define your own scope!
        $scope = 'core/user-auth/be';

        // Create the factory
        $securityObjectsFactory = GeneralUtility::makeInstance(SecurityObjectsFactory::class);
        // Create a mutable version of the security objects
        $securityObjects = $securityObjectsFactory->create($scope, $params);
        // You can alter the security object params until they are locked
        $securityObjects->params['foo'] = 'example';
        
        // After locking, params can not be altered. Anything is immutable.
        $securityObjects = $securityObjects->lock();

        // Build the callback Uri
        $callbackUrl = $this->getCallbackUrl($securityObjects);
        $redirectUrl = $this->getRedirectUrl($callbackUrl);

        // Use NonceCookie and RedirectResponse, because the PropagateResponseException
        // will bypass setting nonce cookies via middleware.
        // In case you can return a RedirectResponse without using the PropagateResponseException, you should always
        // prefer returning the response. You can use the TYPO3 RedirectResponse in that case.
        $nonceCookie = new NonceCookie($securityObjects->signingSecret, $sitePath);
        $redirectResponse = new RedirectResponse($redirectUrl, $nonceCookie);
        
        throw new PropagateResponseException($redirectResponse);
    }
    
    // Assuming this is the method of your callback URI after successful redirect
    public function handle()
    {
        // Change accordingly
        $scope = 'core/user-auth/be';

        $securityObjectsFactory = GeneralUtility::makeInstance(SecurityObjectsFactory::class);
        $securityObjects = $securityObjectsFactory->getCurrentSecurityObjects($scope)

        // Don't forget to actually check the return value
        if (!$securityObjects instanceof LockedSecurityObjects) {
            throw new Exception('Something went wrong');
        }

        // trusted params
        $params = $securityObjects->requestToken->params;
    }

    function getCallbackUrl(LockedSecurityObjects $securityObjects): string
    {
        $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
        return (string) $uriBuilder->buildUriFromRoute(
            'login',
            $securityObjects->addSecurityObjectsToParams(),
            UriBuilder::ABSOLUTE_URL,
        );
    }

    function getRedirectUrl(string $callbackUrl): string
    {
        return 'https://example.com?callbackUri=' . rawurlencode($callbackUrl);
    }
}

Licenses

License of this package: GPL-3.0-or-later

List of used assets with source and license

LICENSE

Resources/Public/Icons/Extension.svg

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-only
  • 更新时间: 2025-07-18