86 |
87 |
88 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # OpenID Connect integration for TYPO3 - changelog
2 |
3 | ## Version 5.x.x
4 |
5 | - Breaking: Dropped support for TYPO3 11 LTS and PHP < 8.2
6 | - Breaking: Introduced OidcConfiguration class to represent extension configuration.
7 | Default values of endpoints have been removed. Please validate your configuration during upgrade.
8 | - Breaking: Dropped direct felogin-integration (via event).
9 | Please use the `OidcLinkViewHelper` instead, if you previously relied on the `{openidConnectUri}` variable in your template.
10 | - Breaking: Move OIDC Login Plugin from "list_type" to real content type.
11 | - Breaking: The default scope separator is changed from comma (`,`) to the space-character (` `)
12 | to follow official [RFC-6749](https://datatracker.ietf.org/doc/html/rfc6749#section-3.3).
13 | Change extension configuration `oidcClientScopeSeparator = ,` for old behaviour.
14 | - Feature: Added extension setting `enablePasswordCredentials` to disable password-authentication.
15 | - Method `getFreshAccessToken()` now actually returns the fresh access token.
16 |
17 |
18 | ## Version 4.0.0
19 |
20 | - Breaking: Existing fe_users are not looked up by their username anymore.
21 | You may use the `AuthenticationFetchUserEvent` to re-add this functionality,
22 | if this is secure for your use case.
23 | See commit `[!!!][SECURITY] Do not look up existing users via username field` for details.
24 | - Breaking: Upon login the user's username and email address will now be updated
25 | according to the mapping configuration. The default mapping configuration maps
26 | the username, but not the email address. Custom mapping configurations can now
27 | map none, one or both of those fields.
28 | It is now possible to post-process the mapping by ìmplementing the `AuthenticationProcessMappingEvent`
29 | - The query parameters for the authorization URL can now be modified via `GetAuthorizationUrlEvent`.
30 |
31 | ## Version 3.0.0
32 |
33 | - The callback URL changed from `/typo3conf/ext/oidc/Public/callback.php` to `TYPO3_SITE_URL`. (configurable with option `oidcRedirectUri`) [#116](https://github.com/xperseguers/t3ext-oidc/issues/116)
34 | - No PHP native session is needed anymore. A JWT-Cookie (named `oidc_context`) is now used to store relevant information during an authentication process. [#155](https://github.com/xperseguers/t3ext-oidc/issues/155)
35 | - A dedicated route is used to initiate the authorization flow with the identity provider. (configurable with option `authenticationUrlRoute`)
36 | This avoids creating loads of authentication sessions with the identity provider (IdP), if the Login-button
37 | is placed on a Login-page for instance. Formerly a new auth-session was started with the IdP
38 | every time the page was rendered. [#159](https://github.com/xperseguers/t3ext-oidc/issues/159)
39 | - All previous hooks have been replaced with PSR-14 events. More events were added.
40 | - The extension is now wiring the underlying OAuth2 library with TYPO3's Guzzle wrapper (`GuzzleClientFactory`).
41 | This means that requests done by the library now adhere to TYPO3 configuration. [#167](https://github.com/xperseguers/t3ext-oidc/issues/167)
42 | - Added an event allowing to adjust the where-conditions for fetching the existing fe_users [#164](https://github.com/xperseguers/t3ext-oidc/issues/164)
43 | - Enhanced events to include a reference to the AuthenticationService [#136](https://github.com/xperseguers/t3ext-oidc/issues/136)
44 | - Added a user groups event to map groups by a different pattern than "Roles", e.g. "claims" [#129](https://github.com/xperseguers/t3ext-oidc/pull/129)
45 |
--------------------------------------------------------------------------------
/Build/typo3/Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1.7-labs
2 | FROM php:8.3-apache AS webserver
3 |
4 | # Install common tools
5 | # gettext-base provides envsubst, used for fixture import to db
6 | RUN apt-get update \
7 | && apt-get install -y \
8 | wget \
9 | rsync \
10 | unzip \
11 | gettext-base \
12 | curl \
13 | && rm -rf /var/lib/apt/lists/*
14 |
15 | # Install mysql client
16 | RUN apt-get update \
17 | && apt-get install -y \
18 | mariadb-client \
19 | && rm -rf /var/lib/apt/lists/*
20 |
21 | # Install imagemagick
22 | RUN apt-get update \
23 | && apt-get install -y \
24 | imagemagick \
25 | && rm -rf /var/lib/apt/lists/*
26 | ENV TYPO3_GFX_PROCESSOR_PATH=/usr/bin/
27 | ENV TYPO3_GFX_PROCESSOR_PATH_LZW=/usr/bin/
28 |
29 | # Install apcu caching
30 | RUN pecl install apcu \
31 | && docker-php-ext-enable apcu
32 |
33 | # Install PHP extensions
34 | RUN apt-get update \
35 | && apt-get install -y \
36 | libxml2-dev libfreetype6-dev \
37 | libjpeg62-turbo-dev \
38 | libmcrypt-dev \
39 | libpng-dev \
40 | libzip-dev \
41 | python3 \
42 | python3-setuptools \
43 | libcurl4-openssl-dev \
44 | && rm -rf /var/lib/apt/lists/*
45 | RUN docker-php-ext-install -j$(nproc) \
46 | exif \
47 | mysqli \
48 | soap \
49 | curl \
50 | zip
51 |
52 | # Install php extension intl
53 | RUN apt-get update \
54 | && apt-get install -y \
55 | libicu-dev \
56 | && rm -rf /var/lib/apt/lists/* \
57 | && docker-php-ext-install intl
58 |
59 | # Install php redis client
60 | RUN pecl install -o -f redis \
61 | && rm -rf /tmp/pear \
62 | && docker-php-ext-enable redis
63 |
64 | # PHP gd
65 | RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
66 | RUN docker-php-ext-install -j$(nproc) gd
67 |
68 | # Link php binary where TYPO3 expects it
69 | RUN ln -s /usr/local/bin/php /usr/bin/php
70 |
71 | # Configure PHP
72 | ADD docker/typo3.ini /usr/local/etc/php/conf.d/typo3.ini
73 |
74 | # Install xdebug
75 | RUN pecl install xdebug \
76 | && docker-php-ext-enable xdebug
77 |
78 | # Setup locales
79 | RUN apt-get update \
80 | && apt-get install -y \
81 | locales \
82 | && rm -rf /var/lib/apt/lists/* \
83 | && echo "# Docker locales" > /etc/locale.gen \
84 | && echo "en_GB.UTF-8 UTF-8" >> /etc/locale.gen \
85 | && echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \
86 | && echo "de_DE.UTF-8 UTF-8" >> /etc/locale.gen \
87 | && locale-gen
88 |
89 | # Configure Apache as ssl server
90 | RUN a2enmod rewrite
91 | RUN a2enmod ssl
92 | COPY --from=certs /developer.pem /etc/ssl/certs/developer.pem
93 | COPY --from=certs /developer.key /etc/ssl/private/developer.key
94 | RUN ln -s /etc/ssl/certs/developer.pem /etc/ssl/certs/`openssl x509 -noout -hash -in /etc/ssl/certs/developer.pem`.0
95 | ADD docker/000-default.conf /etc/apache2/sites-available/000-default.conf
96 | ADD docker/000-default-ssl.conf /etc/apache2/sites-available/000-default-ssl.conf
97 | RUN a2ensite 000-default-ssl.conf
98 | RUN rm /etc/apache2/sites-available/default-ssl.conf
99 |
100 | COPY --chmod=744 docker/entrypoint.sh /entrypoint.sh
101 | CMD ["/entrypoint.sh"]
102 |
103 | WORKDIR /app
104 | EXPOSE 80
105 | EXPOSE 443
106 |
107 |
108 |
109 | FROM composer:2.7.2 AS php-composer
110 |
111 |
112 |
113 | FROM php-composer AS php-dependencies
114 | COPY --from=typo3-version composer.* /app/
115 | COPY --parents ./typo3/packages/./*/composer.json /app/packages
116 | COPY --from=oidc composer.json /app/packages/oidc/composer.json
117 |
118 | RUN composer install --no-dev
119 |
120 |
121 |
122 | FROM webserver AS oidc-webserver
123 | COPY --from=php-dependencies /app /app
124 | RUN install -d -o www-data -g www-data -m 775 -v /app/var
125 | RUN cp vendor/typo3/cms-install/Resources/Private/FolderStructureTemplateFiles/root-htaccess public/.htaccess
126 |
127 | COPY ./typo3 /app/
128 | COPY --from=oidc / /app/packages/oidc
129 |
--------------------------------------------------------------------------------
/ext_conf_template.txt:
--------------------------------------------------------------------------------
1 | # cat=basic/enable/1; type=boolean; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.enableFrontendAuthentication
2 | enableFrontendAuthentication = 0
3 |
4 | # cat=basic/enable/2; type=boolean; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.reEnableFrontendUsers
5 | reEnableFrontendUsers = 0
6 |
7 | # cat=basic/enable/3; type=boolean; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.undeleteFrontendUsers
8 | undeleteFrontendUsers = 0
9 |
10 | # cat=basic/enable/4; type=boolean; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.frontendUserMustExistLocally
11 | frontendUserMustExistLocally = 0
12 |
13 | # cat=basic/enable/5; type=boolean; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.enableCodeVerifier
14 | enableCodeVerifier = 0
15 |
16 | # cat=basic/enable/6; type=boolean; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.enablePasswordCredentials
17 | enablePasswordCredentials = 0
18 |
19 | # cat=basic//1; type=string; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.usersStoragePid
20 | usersStoragePid = 0
21 |
22 | # cat=basic//2; type=string; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.usersDefaultGroup
23 | usersDefaultGroup =
24 |
25 | # cat=basic//2a; type=string; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.oidcRedirectUri
26 | oidcRedirectUri =
27 |
28 | # cat=basic//3; type=string; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.oidcClientKey
29 | oidcClientKey =
30 |
31 | # cat=basic//4; type=string; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.oidcClientSecret
32 | oidcClientSecret =
33 |
34 | # cat=basic//5; type=string; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.oidcClientScopes
35 | oidcClientScopes = openid
36 |
37 | # cat=basic//6; type=string; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.oidcClientScopeSeparator
38 | oidcClientScopeSeparator =
39 |
40 | # cat=advanced/links/1; type=string; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.oidcEndpointAuthorize
41 | oidcEndpointAuthorize =
42 |
43 | # cat=advanced/links/2; type=string; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.oidcEndpointToken
44 | oidcEndpointToken =
45 |
46 | # cat=advanced/links/3; type=string; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.oidcEndpointUserInfo
47 | oidcEndpointUserInfo =
48 |
49 | # cat=advanced/links/4; type=string; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.oidcEndpointLogout
50 | oidcEndpointLogout =
51 |
52 | # cat=advanced/links/5; type=string; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.oidcEndpointRevoke
53 | oidcEndpointRevoke =
54 |
55 | # cat=advanced/links/6; type=string; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.oidcAuthorizeLanguageParameter
56 | oidcAuthorizeLanguageParameter = language
57 |
58 | # cat=advanced/enable/1; type=boolean; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.oidcUseRequestPathAuthentication
59 | oidcUseRequestPathAuthentication = 0
60 |
61 | # cat=advanced/enable/2; type=boolean; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.revokeAccessTokenAfterLogin
62 | oidcRevokeAccessTokenAfterLogin = 0
63 |
64 | # cat=advanced/enable/3; type=boolean; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.oidcDisableCSRFProtection
65 | oidcDisableCSRFProtection = 0
66 |
67 | # cat=advanced//3; type=string; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.oauthProviderFactory
68 | oauthProviderFactory =
69 |
70 | # cat=advanced//4; type=int+; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.authenticationServicePriority
71 | authenticationServicePriority = 82
72 |
73 | # cat=advanced//5; type=int+; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.authenticationServiceQuality
74 | authenticationServiceQuality = 80
75 |
76 | # cat=advanced//6; type=string; label=LLL:EXT:oidc/Resources/Private/Language/locallang_db.xlf:settings.authenticationUrlRoute
77 | authenticationUrlRoute = oidc/authentication
78 |
--------------------------------------------------------------------------------
/Classes/OidcConfiguration.php:
--------------------------------------------------------------------------------
1 | */
29 | public string $oauthProviderFactory = '';
30 | public string $oidcClientKey = '';
31 | public string $oidcClientSecret = '';
32 | public string $oidcClientScopes = 'openid';
33 | public string $oidcClientScopeSeparator = ' ';
34 | public string $oidcRedirectUri = '';
35 | public string $endpointAuthorize = '';
36 | public string $endpointToken = '';
37 | public string $endpointUserInfo = '';
38 | public string $endpointRevoke = '';
39 | public string $endpointLogout = '';
40 | public bool $revokeAccessTokenAfterLogin = false;
41 | public bool $enablePasswordCredentials = false;
42 |
43 | public function __construct(array $extConfig = [])
44 | {
45 | $extConfig = $extConfig ?: $this->getExtensionConfiguration();
46 |
47 | $this->enableFrontendAuthentication = (bool)$extConfig['enableFrontendAuthentication'];
48 | $this->authenticationServicePriority = (int)$extConfig['authenticationServicePriority'];
49 | $this->authenticationServiceQuality = (int)$extConfig['authenticationServiceQuality'];
50 | $this->reEnableFrontendUsers = (bool)$extConfig['reEnableFrontendUsers'];
51 | $this->undeleteFrontendUsers = (bool)$extConfig['undeleteFrontendUsers'];
52 | $this->frontendUserMustExistLocally = (bool)$extConfig['frontendUserMustExistLocally'];
53 | $this->disableCSRFProtection = (bool)$extConfig['oidcDisableCSRFProtection'];
54 | $this->enableCodeVerifier = (bool)$extConfig['enableCodeVerifier'];
55 | $this->authenticationUrlRoute = $extConfig['authenticationUrlRoute'];
56 | $this->authorizeLanguageParameter = $extConfig['oidcAuthorizeLanguageParameter'];
57 | $this->useRequestPathAuthentication = (bool)$extConfig['oidcUseRequestPathAuthentication'];
58 | $this->oauthProviderFactory = $extConfig['oauthProviderFactory'] ?: GenericOAuthProviderFactory::class;
59 | $this->oidcClientKey = $extConfig['oidcClientKey'];
60 | $this->oidcClientSecret = $extConfig['oidcClientSecret'];
61 | $this->oidcClientScopes = $extConfig['oidcClientScopes'];
62 | $this->oidcClientScopeSeparator = $extConfig['oidcClientScopeSeparator'] === '' ? ' ' : $extConfig['oidcClientScopeSeparator'];
63 | $this->endpointAuthorize = $extConfig['oidcEndpointAuthorize'];
64 | $this->endpointToken = $extConfig['oidcEndpointToken'];
65 | $this->endpointUserInfo = $extConfig['oidcEndpointUserInfo'];
66 | $this->endpointRevoke = $extConfig['oidcEndpointRevoke'];
67 | $this->endpointLogout = $extConfig['oidcEndpointLogout'];
68 | $this->usersStoragePids = GeneralUtility::intExplode(',', (string)$extConfig['usersStoragePid'], true) ?: [0];
69 | $this->usersDefaultGroup = $extConfig['usersDefaultGroup'];
70 | $this->oidcRedirectUri = $extConfig['oidcRedirectUri'];
71 | $this->revokeAccessTokenAfterLogin = (bool)$extConfig['oidcRevokeAccessTokenAfterLogin'];
72 | $this->enablePasswordCredentials = (bool)$extConfig['enablePasswordCredentials'];
73 | }
74 |
75 | protected function getExtensionConfiguration(): array
76 | {
77 | $config = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('oidc');
78 | if ($config) {
79 | return $config;
80 | }
81 | throw new \UnexpectedValueException('OIDC extension configuration not found', 1763986824);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/Classes/Controller/LoginController.php:
--------------------------------------------------------------------------------
1 | request = $GLOBALS['TYPO3_REQUEST'];
47 | }
48 |
49 | public function setContentObjectRenderer(ContentObjectRenderer $cObj): void
50 | {
51 | $this->cObj = $cObj;
52 | }
53 |
54 | /**
55 | * Main entry point for the OIDC plugin.
56 | *
57 | * If the user is not logged in, redirect to the authorization server to start the oidc process
58 | *
59 | * If the user has just been logged in and just came back from the authorization server, redirect the user to the
60 | * final redirect URL.
61 | *
62 | * @param string $_ ignored
63 | * @param array|null $pluginConfiguration
64 | * @throws PropagateResponseException
65 | */
66 | public function login(string $_, ?array $pluginConfiguration): void
67 | {
68 | if (is_array($pluginConfiguration)) {
69 | $this->pluginConfiguration = $pluginConfiguration;
70 | }
71 |
72 | /** @var Context $context */
73 | $context = GeneralUtility::makeInstance(Context::class);
74 | $loginType = $this->request->getParsedBody()['logintype'] ?? $this->request->getQueryParams()['logintype'] ?? '';
75 | if ($loginType === 'login' || $context->getAspect('frontend.user')->isLoggedIn()) {
76 | $redirectUrl = $this->determineRedirectUrl();
77 | $this->redirect($redirectUrl);
78 | }
79 |
80 | $authorizationRedirect = $this->getAuthorizationRedirect($this->request, $pluginConfiguration['authorizationUrlOptions.'] ?? []);
81 | throw new PropagateResponseException($authorizationRedirect);
82 | }
83 |
84 | protected function getAuthorizationRedirect(ServerRequestInterface $request, array $authorizationUrlOptions): RedirectResponse
85 | {
86 | $oidcService = GeneralUtility::makeInstance(OpenIdConnectService::class);
87 | $authContext = $oidcService->buildAuthenticationContext(
88 | $this->request,
89 | $authorizationUrlOptions,
90 | Uri::withQueryValue($request->getUri(), 'logintype', 'login')->__toString(),
91 | );
92 | return $oidcService->getAuthorizationRedirect($authContext);
93 | }
94 |
95 | protected function determineRedirectUrl()
96 | {
97 | $redirectUrl = $this->request->getParsedBody()['redirect_url'] ?? $this->request->getQueryParams()['redirect_url'] ?? '';
98 | if (!empty($redirectUrl)) {
99 | return $redirectUrl;
100 | }
101 |
102 | if (isset($this->pluginConfiguration['defaultRedirectPid'])) {
103 | $defaultRedirectPid = (int)$this->pluginConfiguration['defaultRedirectPid'];
104 | if ($defaultRedirectPid > 0) {
105 | return $this->cObj->typoLink_URL(['parameter' => $defaultRedirectPid]);
106 | }
107 | }
108 |
109 | return '/';
110 | }
111 |
112 | /**
113 | * @throws PropagateResponseException
114 | */
115 | protected function redirect(string $redirectUrl): void
116 | {
117 | throw new PropagateResponseException(new RedirectResponse($redirectUrl));
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/Build/typo3/typo3/packages/oidc-sitepackage/ext_tables_static+adt.sql:
--------------------------------------------------------------------------------
1 | TRUNCATE pages;
2 | TRUNCATE tt_content;
3 | TRUNCATE sys_template;
4 |
5 | # Needed for TYPO3 v12
6 | INSERT INTO `sys_template` (`uid`, `pid`, `title`, `root`)
7 | VALUES
8 | ('1', '1', 'oidc-sitepackage', '1');
9 | ;
10 |
11 | INSERT INTO pages SET
12 | uid = 1,
13 | pid = 0,
14 | title = "oidc",
15 | is_siteroot = 1,
16 | slug = "/",
17 | doktype = 1
18 | ;
19 |
20 | INSERT INTO pages
21 | SET
22 | uid = 2,
23 | pid = 1,
24 | title = "Frontend Users",
25 | slug = "/frontend-users/",
26 | doktype = 254,
27 | module = "fe_users",
28 | sorting = 16
29 | ;
30 |
31 | INSERT INTO `tt_content` (`uid`, `pid`, `CType`, `header`, `pi_flexform`)
32 | VALUES
33 | ('1', '1', 'felogin_login', 'Login', '\n\n \n \n \n \n 0\n \n \n 1\n \n \n 0\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n 0\n \n \n \n \n \n \n \n \n \n \n \n 0\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n');
34 | ;
35 |
36 | INSERT INTO pages SET
37 | uid = 3,
38 | pid = 1,
39 | title = "Login",
40 | slug = "/login/",
41 | doktype = 1,
42 | sorting = 1
43 | ;
44 |
45 | INSERT INTO `tt_content` (`uid`, `pid`, `CType`, `header`)
46 | VALUES
47 | ('2', '3', 'oidc_login', 'Login');
48 | ;
49 |
50 | INSERT INTO pages SET
51 | uid = 4,
52 | pid = 1,
53 | title = "Login Redirect Target",
54 | slug = "/login-redirect-target/",
55 | doktype = 1,
56 | sorting = 8
57 | ;
58 |
--------------------------------------------------------------------------------
/Build/typo3/typo3/config/system/settings.php:
--------------------------------------------------------------------------------
1 | [
5 | 'debug' => true,
6 | 'passwordHashing' => [
7 | 'className' => 'TYPO3\\CMS\\Core\\Crypto\\PasswordHashing\\Argon2iPasswordHash',
8 | 'options' => [],
9 | ],
10 | ],
11 | 'DB' => [
12 | 'Connections' => [
13 | 'Default' => [
14 | 'charset' => 'utf8',
15 | 'driver' => 'mysqli',
16 | ],
17 | ],
18 | ],
19 | 'EXTENSIONS' => [
20 | 'backend' => [
21 | 'backendFavicon' => '',
22 | 'backendLogo' => '',
23 | 'loginBackgroundImage' => '',
24 | 'loginFootnote' => '',
25 | 'loginHighlightColor' => '',
26 | 'loginLogo' => '',
27 | 'loginLogoAlt' => '',
28 | ],
29 | 'extensionmanager' => [
30 | 'automaticInstallation' => '1',
31 | 'offlineMode' => '0',
32 | ],
33 | 'oidc' => [
34 | 'authenticationServicePriority' => '82',
35 | 'authenticationServiceQuality' => '80',
36 | 'authenticationUrlRoute' => 'oidc/authentication',
37 | 'enableBackendAuthentication' => '1',
38 | 'enableCodeVerifier' => '1',
39 | 'enableFrontendAuthentication' => '1',
40 | 'enablePasswordCredentials' => '0',
41 | 'frontendUserMustExistLocally' => '0',
42 | 'oauthProviderFactory' => '',
43 | 'oidcAuthorizeLanguageParameter' => 'language',
44 | 'oidcClientKey' => 't3ext-oidc',
45 | 'oidcClientScopes' => 'openid',
46 | 'oidcClientSecret' => 't3ext-oidc',
47 | 'oidcDisableCSRFProtection' => '0',
48 | 'oidcEndpointAuthorize' => 'http://oidc.t3ext-oidc.test/connect/authorize',
49 | 'oidcEndpointLogout' => '',
50 | 'oidcEndpointRevoke' => 'http://oidc.t3ext-oidc.test/connect/revocation',
51 | 'oidcEndpointToken' => 'http://oidc.t3ext-oidc.test/connect/token',
52 | 'oidcEndpointUserInfo' => 'http://oidc.t3ext-oidc.test/connect/userinfo',
53 | 'oidcRedirectUri' => 'https://v13.t3ext-oidc.test/login/redirect',
54 | 'oidcRevokeAccessTokenAfterLogin' => '0',
55 | 'oidcUseRequestPathAuthentication' => '0',
56 | 'reEnableFrontendUsers' => '0',
57 | 'undeleteFrontendUsers' => '0',
58 | 'usersDefaultGroup' => '',
59 | 'usersStoragePid' => '2',
60 | ],
61 | ],
62 | 'FE' => [
63 | 'cacheHash' => [
64 | 'enforceValidation' => true,
65 | ],
66 | 'debug' => true,
67 | 'disableNoCacheParameter' => true,
68 | 'passwordHashing' => [
69 | 'className' => 'TYPO3\\CMS\\Core\\Crypto\\PasswordHashing\\Argon2iPasswordHash',
70 | 'options' => [],
71 | ],
72 | ],
73 | 'GFX' => [
74 | 'processor' => 'ImageMagick',
75 | 'processor_effects' => true,
76 | 'processor_enabled' => true,
77 | 'processor_path' => '/usr/bin/',
78 | ],
79 | 'LOG' => [
80 | 'TYPO3' => [
81 | 'CMS' => [
82 | 'deprecations' => [
83 | 'writerConfiguration' => [
84 | 'notice' => [
85 | 'TYPO3\CMS\Core\Log\Writer\FileWriter' => [
86 | 'disabled' => false,
87 | ],
88 | ],
89 | ],
90 | ],
91 | ],
92 | ],
93 | ],
94 | 'MAIL' => [
95 | 'transport' => 'sendmail',
96 | 'transport_sendmail_command' => '/usr/sbin/sendmail -t -i',
97 | 'transport_smtp_encrypt' => '',
98 | 'transport_smtp_password' => '',
99 | 'transport_smtp_server' => '',
100 | 'transport_smtp_username' => '',
101 | ],
102 | 'SYS' => [
103 | 'UTF8filesystem' => true,
104 | 'caching' => [
105 | 'cacheConfigurations' => [
106 | 'hash' => [
107 | 'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend',
108 | ],
109 | 'pages' => [
110 | 'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend',
111 | 'options' => [
112 | 'compression' => true,
113 | ],
114 | ],
115 | 'rootline' => [
116 | 'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend',
117 | 'options' => [
118 | 'compression' => true,
119 | ],
120 | ],
121 | ],
122 | ],
123 | 'devIPmask' => '*',
124 | 'displayErrors' => 1,
125 | 'encryptionKey' => 'dff1b14d5aa12e8f6c840e205a6484f7dd0bfb0f67eea73f114543d284071c020efba9f8bf99abfa14deb1b7c2d182db',
126 | 'exceptionalErrors' => 12290,
127 | 'features' => [
128 | 'frontend.cache.autoTagging' => true,
129 | ],
130 | 'sitename' => 'New TYPO3 site',
131 | ],
132 | ];
133 |
--------------------------------------------------------------------------------
/Classes/Frontend/FrontendSimulationV13.php:
--------------------------------------------------------------------------------
1 | matchRequest($originalRequest);
35 | if ($routeResult instanceof SiteRouteResult) {
36 | $site = $routeResult->getSite();
37 | if ($site instanceof Site) {
38 | try {
39 | /** @var Context $context */
40 | $context = GeneralUtility::makeInstance(Context::class);
41 | $context->setAspect('frontend.preview', new PreviewAspect());
42 |
43 | $cacheInstruction = $originalRequest->getAttribute('frontend.cache.instruction', new CacheInstruction());
44 | $originalRequest = $originalRequest->withAttribute('frontend.cache.instruction', $cacheInstruction);
45 |
46 | $pageArguments = $site->getRouter()->matchRequest($originalRequest, $routeResult);
47 | $originalRequest = $originalRequest->withAttribute('routing', $pageArguments);
48 |
49 | $pageInformationFactory = GeneralUtility::makeInstance(PageInformationFactory::class);
50 | $pageInformation = $pageInformationFactory->create($originalRequest);
51 | $originalRequest = $originalRequest->withAttribute('frontend.page.information', $pageInformation);
52 |
53 | $expressionMatcherVariables = $this->getExpressionMatcherVariables($site, $originalRequest, $tsfe);
54 | /** @var CacheManager $cacheManager */
55 | $cacheManager = GeneralUtility::makeInstance(CacheManager::class);
56 | /** @var PhpFrontend $cache */
57 | $cache = $cacheManager->getCache('typoscript');
58 |
59 | $frontendTypoScriptFactory = GeneralUtility::makeInstance(FrontendTypoScriptFactory::class);
60 | $frontendTypoScript = $frontendTypoScriptFactory->createSettingsAndSetupConditions(
61 | $site,
62 | $pageInformation->getSysTemplateRows(),
63 | // $originalRequest does not contain site ...
64 | $expressionMatcherVariables,
65 | $cache,
66 | );
67 | $frontendTypoScript = $frontendTypoScriptFactory->createSetupConfigOrFullSetup(
68 | true,
69 | $frontendTypoScript,
70 | $site,
71 | $pageInformation->getSysTemplateRows(),
72 | $expressionMatcherVariables,
73 | '0',
74 | $cache,
75 | null
76 | );
77 |
78 | return $frontendTypoScript->getSetupArray();
79 | } catch (RouteNotFoundException) {
80 | }
81 | }
82 | }
83 | throw new InvalidArgumentException('Failed to build TypoScript');
84 | }
85 |
86 | protected function getExpressionMatcherVariables(
87 | SiteInterface $site,
88 | ServerRequestInterface $request,
89 | TypoScriptFrontendController $controller
90 | ): array {
91 | $pageInformation = $request->getAttribute('frontend.page.information');
92 | $topDownRootLine = $pageInformation->getRootLine();
93 | $localRootline = $pageInformation->getLocalRootLine();
94 | ksort($topDownRootLine);
95 | return [
96 | 'request' => $request,
97 | 'pageId' => $pageInformation->getId(),
98 | 'page' => $pageInformation->getPageRecord(),
99 | 'fullRootLine' => $topDownRootLine,
100 | 'localRootLine' => $localRootline,
101 | 'site' => $site,
102 | 'siteLanguage' => $request->getAttribute('language'),
103 | 'tsfe' => $controller,
104 | ];
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/Resources/Private/Language/locallang_db.xlf:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Case-insensitive pattern to match OpenID Connect role names ("*" matches every character, "|" to separate expressions)
7 |
8 |
9 | OpenID Connect Identifier
10 |
11 |
12 | Authentication service priority: This defines the order of the OIDC authentication service in relation to other authentication services. Higher number wins.
13 |
14 |
15 | Authentication service Quality: This is used by TYPO3 if two authentication services have the same priority. Higher number wins.
16 |
17 |
18 | Route for retrieving the authentication URL of the Identity Provider
19 |
20 |
21 | Enable PKCE: Enable PKCE flow. Code challenge and code verifier will be sent along.
22 |
23 |
24 | Frontend Authentication: Enable OpenID Connect authentication for the frontend.
25 |
26 |
27 | Enable username/password authentication: Enable authentication with username/password via OpenID Connect. e.g. via felogin
28 |
29 |
30 | Frontend User Must Exist: If ticked, only Frontend Users who are present locally in TYPO3 will be able to authenticate with OpenID Connect. You may need to watch logs to find users who could not authenticate.
31 |
32 |
33 | OAuth Provider Factory: Fully qualified class name (empty for generic provider).
34 |
35 |
36 | Authorize request language parameter name
37 |
38 |
39 | Client Key
40 |
41 |
42 | Client Scopes:
43 |
44 |
45 | Client Scope Separator (empty = ' ' [space]):
46 |
47 |
48 | Client Secret:
49 |
50 |
51 | Disable CSRF attack mitigation: CAUTION! This is a security protection which checks the return state with the expected value. Disable this protection at your own risk.
52 |
53 |
54 | Endpoint URI for authorization
55 |
56 |
57 | Endpoint URI for logout
58 |
59 |
60 | Endpoint URI for revoking the token
61 |
62 |
63 | Endpoint URI for retrieving a token
64 |
65 |
66 | Endpoint URI for fetching user information
67 |
68 |
69 | Redirect URI: The authentication server callback will point to this URI.
70 |
71 |
72 | Use Request Path Authentication: When ticked, this value will use Request Path Authentication instead of standard Password Grant.
73 |
74 |
75 | Re-enable Frontend Users: If ticked, will automatically re-enable Frontend users marked as "disabled" upon successful authentication.
76 |
77 |
78 | Revoke TYPO3's access token at the end of the login process
79 |
80 |
81 | Undelete Frontend Users: If ticked, will automatically restore Frontend users marked as "deleted" upon successful authentication.
82 |
83 |
84 | Default user group(s) (comma-separated list of UIDs)
85 |
86 |
87 | Storage Pid: Comma-separated list of page UIDs where fe_users are located. The first UID is used to store new users.
88 |
89 |
90 | OIDC Login
91 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/.phpstorm.meta.php:
--------------------------------------------------------------------------------
1 | \TYPO3\CMS\Core\Context\DateTimeAspect::class,
23 | 'visibility' => \TYPO3\CMS\Core\Context\VisibilityAspect::class,
24 | 'backend.user' => \TYPO3\CMS\Core\Context\UserAspect::class,
25 | 'frontend.user' => \TYPO3\CMS\Core\Context\UserAspect::class,
26 | 'workspace' => \TYPO3\CMS\Core\Context\WorkspaceAspect::class,
27 | 'language' => \TYPO3\CMS\Core\Context\LanguageAspect::class,
28 | 'typoscript' => \TYPO3\CMS\Core\Context\TypoScriptAspect::class,
29 | ]));
30 | expectedArguments(
31 | \TYPO3\CMS\Core\Context\DateTimeAspect::get(),
32 | 0,
33 | 'timestamp',
34 | 'iso',
35 | 'timezone',
36 | 'full',
37 | 'accessTime'
38 | );
39 | expectedArguments(
40 | \TYPO3\CMS\Core\Context\VisibilityAspect::get(),
41 | 0,
42 | 'includeHiddenPages',
43 | 'includeHiddenContent',
44 | 'includeDeletedRecords'
45 | );
46 | expectedArguments(
47 | \TYPO3\CMS\Core\Context\UserAspect::get(),
48 | 0,
49 | 'id',
50 | 'username',
51 | 'isLoggedIn',
52 | 'isAdmin',
53 | 'groupIds',
54 | 'groupNames'
55 | );
56 | expectedArguments(
57 | \TYPO3\CMS\Core\Context\WorkspaceAspect::get(),
58 | 0,
59 | 'id',
60 | 'isLive',
61 | 'isOffline'
62 | );
63 | expectedArguments(
64 | \TYPO3\CMS\Core\Context\LanguageAspect::get(),
65 | 0,
66 | 'id',
67 | 'contentId',
68 | 'fallbackChain',
69 | 'overlayType',
70 | 'legacyLanguageMode',
71 | 'legacyOverlayType'
72 | );
73 | expectedArguments(
74 | \TYPO3\CMS\Core\Context\TypoScriptAspect::get(),
75 | 0,
76 | 'forcedTemplateParsing'
77 | );
78 |
79 | expectedArguments(
80 | \Psr\Http\Message\ServerRequestInterface::getAttribute(),
81 | 0,
82 | 'frontend.user',
83 | 'normalizedParams',
84 | 'site',
85 | 'language',
86 | 'routing',
87 | 'module',
88 | 'moduleData',
89 | 'frontend.controller',
90 | 'frontend.typoscript',
91 | );
92 | override(\Psr\Http\Message\ServerRequestInterface::getAttribute(), map([
93 | 'frontend.user' => \TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication::class,
94 | 'normalizedParams' => \TYPO3\CMS\Core\Http\NormalizedParams::class,
95 | 'site' => \TYPO3\CMS\Core\Site\Entity\SiteInterface::class,
96 | 'language' => \TYPO3\CMS\Core\Site\Entity\SiteLanguage::class,
97 | 'routing' => '\TYPO3\CMS\Core\Routing\SiteRouteResult|\TYPO3\CMS\Core\Routing\PageArguments',
98 | 'module' => \TYPO3\CMS\Backend\Module\ModuleInterface::class,
99 | 'moduleData' => \TYPO3\CMS\Backend\Module\ModuleData::class,
100 | 'frontend.controller' => \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class,
101 | 'frontend.typoscript' => \TYPO3\CMS\Core\TypoScript\FrontendTypoScript::class,
102 | ]));
103 |
104 | expectedArguments(
105 | \TYPO3\CMS\Core\Http\ServerRequest::getAttribute(),
106 | 0,
107 | 'frontend.user',
108 | 'normalizedParams',
109 | 'site',
110 | 'language',
111 | 'routing',
112 | 'module',
113 | 'moduleData'
114 | );
115 | override(\TYPO3\CMS\Core\Http\ServerRequest::getAttribute(), map([
116 | 'frontend.user' => \TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication::class,
117 | 'normalizedParams' => \TYPO3\CMS\Core\Http\NormalizedParams::class,
118 | 'site' => \TYPO3\CMS\Core\Site\Entity\SiteInterface::class,
119 | 'language' => \TYPO3\CMS\Core\Site\Entity\SiteLanguage::class,
120 | 'routing' => '\TYPO3\CMS\Core\Routing\SiteRouteResult|\TYPO3\CMS\Core\Routing\PageArguments',
121 | 'module' => \TYPO3\CMS\Backend\Module\ModuleInterface::class,
122 | 'moduleData' => \TYPO3\CMS\Backend\Module\ModuleData::class,
123 | ]));
124 |
125 | override(\TYPO3\CMS\Core\Routing\SiteMatcher::matchRequest(), type(
126 | \TYPO3\CMS\Core\Routing\SiteRouteResult::class,
127 | \TYPO3\CMS\Core\Routing\RouteResultInterface::class,
128 | )
129 | );
130 |
131 | override(\TYPO3\CMS\Core\Routing\PageRouter::matchRequest(), type(
132 | \TYPO3\CMS\Core\Routing\PageArguments::class,
133 | \TYPO3\CMS\Core\Routing\RouteResultInterface::class,
134 | ));
135 |
136 | override(\Psr\Container\ContainerInterface::get(0), map([
137 | '' => '@',
138 | ]));
139 |
140 | override(\Psr\EventDispatcher\EventDispatcherInterface::dispatch(0), map([
141 | '' => '@',
142 | ]));
143 |
144 | override(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(0), map([
145 | '' => '@'
146 | ]));
147 | }
148 |
--------------------------------------------------------------------------------
/Build/docker-compose.yml:
--------------------------------------------------------------------------------
1 | name: t3ext-oidc
2 | services:
3 | v12:
4 | build:
5 | context: typo3
6 | additional_contexts:
7 | - certs=./certs
8 | - oidc=..
9 | - typo3-version=./typo3/typo3-v12
10 | networks:
11 | default:
12 | aliases:
13 | - v12.t3ext-oidc.test
14 | depends_on:
15 | db-v12:
16 | condition: service_healthy
17 | env_file:
18 | - typo3/oidc.env
19 | environment:
20 | - SERVER_NAME=v12.t3ext-oidc.test
21 | - TYPO3_CONTEXT=Development
22 |
23 | - TYPO3_DB_HOST=db-v12
24 | - TYPO3_DB_PORT=3306
25 | - TYPO3_DB_USERNAME=app
26 | - TYPO3_DB_PASSWORD=app
27 | - TYPO3_DB_DBNAME=app
28 |
29 | - TYPO3_OIDC_OIDC_REDIRECT_URI=https://v12.t3ext-oidc.test/login/redirect
30 | healthcheck:
31 | test: ["CMD", "curl", "-f", "https://v12.t3ext-oidc.test/"]
32 | interval: 3s
33 |
34 | db-v12:
35 | image: mariadb:10.11.10
36 | environment:
37 | MARIADB_ROOT_PASSWORD: root
38 | MARIADB_USER: app
39 | MARIADB_PASSWORD: app
40 | MARIADB_DATABASE: app
41 | healthcheck:
42 | test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
43 | start_period: 10s
44 | interval: 3s
45 | timeout: 5s
46 | retries: 3
47 |
48 | v13:
49 | build:
50 | context: typo3
51 | additional_contexts:
52 | - certs=./certs
53 | - oidc=..
54 | - typo3-version=./typo3/typo3-v13
55 | networks:
56 | default:
57 | aliases:
58 | - v13.t3ext-oidc.test
59 | depends_on:
60 | db-v13:
61 | condition: service_healthy
62 | env_file:
63 | - typo3/oidc.env
64 | environment:
65 | - SERVER_NAME=v13.t3ext-oidc.test
66 | - TYPO3_CONTEXT=Development
67 |
68 | - TYPO3_DB_HOST=db-v13
69 | - TYPO3_DB_PORT=3306
70 | - TYPO3_DB_USERNAME=app
71 | - TYPO3_DB_PASSWORD=app
72 | - TYPO3_DB_DBNAME=app
73 |
74 | - TYPO3_OIDC_OIDC_REDIRECT_URI=https://v13.t3ext-oidc.test/login/redirect
75 | healthcheck:
76 | test: ["CMD", "curl", "-f", "https://v13.t3ext-oidc.test/"]
77 | interval: 3s
78 |
79 | db-v13:
80 | image: mariadb:10.11.10
81 | environment:
82 | MARIADB_ROOT_PASSWORD: root
83 | MARIADB_USER: app
84 | MARIADB_PASSWORD: app
85 | MARIADB_DATABASE: app
86 | healthcheck:
87 | test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
88 | start_period: 10s
89 | interval: 3s
90 | timeout: 5s
91 | retries: 3
92 |
93 | oidc-server-mock:
94 | platform: linux/amd64
95 | container_name: oidc-server-mock
96 | image: ghcr.io/soluto/oidc-server-mock:0.12.1
97 | networks:
98 | default:
99 | aliases:
100 | - oidc.t3ext-oidc.test
101 | healthcheck:
102 | test: ["CMD", "curl", "-f", "http://localhost/"]
103 | environment:
104 | ASPNETCORE_HTTP_PORTS: 80
105 | ASPNETCORE_URLS: http://+:80
106 | ASPNETCORE_ENVIRONMENT: Development
107 | SERVER_OPTIONS_INLINE: |
108 | {
109 | "AccessTokenJwtType": "JWT",
110 | "Discovery": {
111 | "ShowKeySet": true
112 | },
113 | "Authentication": {
114 | "CookieSameSiteMode": "Lax",
115 | "CheckSessionCookieSameSiteMode": "Lax"
116 | }
117 | }
118 | LOGIN_OPTIONS_INLINE: |
119 | {
120 | "AllowRememberLogin": false
121 | }
122 | LOGOUT_OPTIONS_INLINE: |
123 | {
124 | "AutomaticRedirectAfterSignOut": true
125 | }
126 | API_SCOPES_INLINE: |
127 | - Name: some-app-scope-1
128 | - Name: some-app-scope-2
129 | API_RESOURCES_INLINE: |
130 | - Name: some-app
131 | Scopes:
132 | - some-app-scope-1
133 | - some-app-scope-2
134 | USERS_CONFIGURATION_INLINE: |
135 | [
136 | {
137 | "SubjectId":"1",
138 | "Username":"User1",
139 | "Password":"pwd",
140 | "Claims": [
141 | {
142 | "Type": "name",
143 | "Value": "Sam Tailor",
144 | "ValueType": "string"
145 | },
146 | {
147 | "Type": "email",
148 | "Value": "sam.tailor@gmail.com",
149 | "ValueType": "string"
150 | },
151 | {
152 | "Type": "some-api-resource-claim",
153 | "Value": "Sam's Api Resource Custom Claim",
154 | "ValueType": "string"
155 | },
156 | {
157 | "Type": "some-api-scope-claim",
158 | "Value": "Sam's Api Scope Custom Claim",
159 | "ValueType": "string"
160 | },
161 | {
162 | "Type": "some-identity-resource-claim",
163 | "Value": "Sam's Identity Resource Custom Claim",
164 | "ValueType": "string"
165 | }
166 | ]
167 | }
168 | ]
169 | CLIENTS_CONFIGURATION_PATH: /tmp/config/clients-config.json
170 | ASPNET_SERVICES_OPTIONS_INLINE: |
171 | {
172 | "ForwardedHeadersOptions": {
173 | "ForwardedHeaders" : "All"
174 | }
175 | }
176 | volumes:
177 | - ./oidc-server-mock:/tmp/config:ro
178 |
179 | playwright:
180 | build:
181 | context: playwright
182 | environment:
183 | - DISPLAY=vnc:1
184 | working_dir: /e2e
185 | depends_on:
186 | v12:
187 | condition: service_healthy
188 | v13:
189 | condition: service_healthy
190 | oidc-server-mock:
191 | condition: service_healthy
192 | vnc:
193 | condition: service_healthy
194 |
195 | vnc:
196 | image: consol/ubuntu-xfce-vnc
197 | environment:
198 | - VNC_PW=password
199 | command: /bin/bash -c "xhost + && tail -f /dev/null"
200 | healthcheck:
201 | test: bash -c 'echo > /dev/tcp/localhost/5901'
202 | start_period: 10s
203 | interval: 3s
204 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # OpenID Connect for TYPO3 frontend login
2 |
3 | This extension lets you authenticate frontend users against an OpenID Connect
4 | provider.
5 |
6 | Examples of such identity provider software or services are:
7 |
8 | - Microsoft EntraID
9 | - Google
10 | - GitHub
11 | - ID Austria
12 | - WSO2 Identity Server
13 | - Keycloak
14 | - Authentik
15 |
16 | ## Direct OIDC Login
17 |
18 | If OpenID Connect is your only means of frontend login, you can use the included
19 | "OIDC Login" plugin. Add it to your login page, where you would normally add the
20 | felogin box. After adding the OIDC Login plugin, requests to the login page will
21 | immediately be redirected to the identity provider.
22 |
23 | After the login process, the user will be redirected:
24 |
25 | - The OIDC Login supports the same `redirect_url` parameter as the felogin box
26 | - If no parameter is set, OIDC Login will redirect the user to the page
27 | configured at `plugin.tx_oidc_login.defaultRedirectPid`.
28 | - If that configuration is not set either, the user will be redirected to '/'.
29 |
30 | ## PKCE (Proof of Key for Code Exchange)
31 |
32 | If your OIDC Login supports _Proof of Key for Code Exchange_ you can enable it
33 | by checking `enableCodeVerifier` in the extension configuration. A shared secret
34 | will be sent along preventing _Authorization Code Interception Attacks_. See
35 | https://tools.ietf.org/html/rfc7636 for details.
36 |
37 | ## Configuration
38 |
39 | ### Mapping Frontend User Fields
40 |
41 | - Configuration is done through TypoScript within
42 | `plugin.tx_oidc.mapping.fe_users`
43 | - OIDC attributes will be recognized by the specific characters `<>`:
44 |
45 | ```
46 | email =
47 | ```
48 |
49 | - You may combine multiple markers as well, e.g.,
50 |
51 | ```
52 | name = ,
53 | ```
54 |
55 | - Support for [stdWrap](https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Functions/Stdwrap.html) in
56 | field definition, e.g.,
57 |
58 | ```
59 | name =
60 | name.wrap = |-OIDC
61 | ```
62 |
63 | - Support for [TypoScript "split"](https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Functions/Stdwrap.html#data)
64 | (`//`). This will check multiple field names and return the first one yielding
65 | some non-empty value. E.g.,
66 |
67 | ```
68 | username = // // //
69 | ```
70 |
71 | ### Mapping Frontend User Groups
72 |
73 | - Create your groups within TYPO3
74 | - Use the additional pattern to relate it to roles within OpenID Connect
75 | - Local TYPO3 groups (not related to some role) will be kept upon authenticating
76 | - Default TYPO3 group(s) as configured in Extension Manager will always be added
77 |
78 | ### OIDC Login
79 |
80 | - `plugin.tx_oidc_login.defaultRedirectPid` UID of the page that users will be
81 | redirected to, if no `redirect_url` parameter is set.
82 |
83 | ## Logging
84 |
85 | This extension makes use of the Logging system introduced in TYPO3 CMS 6.0. It
86 | is far more flexible than the old one writing to the "sys_log" table. Technical
87 | details may be found in the [TYPO3 Core API](https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Logging/Index.html#logging).
88 |
89 | As an administrator, what you should know is that the TYPO3 Logger forwards log
90 | records to "Writers", which persist the log record.
91 |
92 | By default, with a vanilla TYPO3 installation, messages are written to the
93 | default log file (`var/log/typo3_*.log`).
94 |
95 |
96 | ### Dedicated Log File for OpenID Connect
97 |
98 | If you want to redirect every logging information from this extension to
99 | `var/log/oidc.log` and send log entries with level "WARNING" or above to the
100 | system log, you may add following configuration to
101 | `typo3conf/AdditionalConfiguration.php`:
102 |
103 | ```
104 | $GLOBALS['TYPO3_CONF_VARS']['LOG']['Causal']['Oidc']['writerConfiguration'] = [
105 | \TYPO3\CMS\Core\Log\LogLevel::DEBUG => [
106 | \TYPO3\CMS\Core\Log\Writer\FileWriter::class => [
107 | 'logFileInfix' => 'oidc'
108 | ],
109 | ],
110 |
111 | // Configuration for WARNING severity, including all
112 | // levels with higher severity (ERROR, CRITICAL, EMERGENCY)
113 | \TYPO3\CMS\Core\Log\LogLevel::WARNING => [
114 | \TYPO3\CMS\Core\Log\Writer\SyslogWriter::class => [],
115 | ],
116 | ];
117 | ```
118 |
119 | **Hint:** Be sure to read
120 | [Configuration of the Logging system](https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Logging/Configuration/Index.html#logging-configuration)
121 | to fine-tune your configuration on any production website.
122 |
123 |
124 | ## Using additional identity provider packages
125 |
126 | The underlying PHP library for OAuth2 can be extended for specific
127 | identity providers by adding additional packages.
128 |
129 | Example: For Microsoft EntraID (Azure) the package is [thenetworg/oauth2-azure](https://packagist.org/packages/thenetworg/oauth2-azure)
130 |
131 | In order to use these kinds of packages, one needs to implement a custom
132 | `OAuth2ProviderFactory`, which takes care of initializing the specific provider.
133 |
134 | Here is an example for the aforementioned Azure package:
135 |
136 | ```php
137 | $settings['oidcClientKey'],
155 | 'redirectUri' => $settings['oidcRedirectUri'],
156 | 'urlAuthorize' => $settings['oidcEndpointAuthorize'],
157 | 'urlAccessToken' => $settings['oidcEndpointToken'],
158 | 'urlResourceOwnerDetails' => $settings['oidcEndpointUserInfo'],
159 | 'scopes' => GeneralUtility::trimExplode(',', $settings['oidcClientScopes'], true),
160 | 'defaultEndPointVersion' => Azure::ENDPOINT_VERSION_2_0,
161 | 'tenant' => getenv('AZURE_OAUTH_CLIENT_TENANT'),
162 | ];
163 | if ($settings['oidcClientSecret']) {
164 | $options['clientSecret'] = $settings['oidcClientSecret'];
165 | } else {
166 | // https://learn.microsoft.com/en-us/entra/identity-platform/certificate-credentials
167 | // PEM certificate (newline potentially encoded as '\n'
168 | $options['clientCertificatePrivateKey'] = getenv('AZURE_OAUTH_CLIENT_CERTIFICATE');
169 | // SHA-1 thumbprint of the X.509 certificate's DER encoding.
170 | $options['clientCertificateThumbprint'] = getenv('AZURE_OAUTH_CLIENT_CERTIFICATE_THUMBPRINT');
171 | }
172 | return new Azure($options);
173 | }
174 | }
175 | ```
176 |
177 | ## Run acceptance tests
178 | The `Build` folder contains a docker compose test environment for this oidc extension. It contains:
179 | * TYPO3 v12 instance with ext-oidc installed
180 | * TYPO3 v13 instance with ext-oidc installed
181 | * mock oidc server
182 | * Playwright test runner to run acceptance tests
183 | * VNC Server to watch the playwright tests
184 |
185 | To build the test environment and run the playwright tests run the following command:
186 | ```bash
187 | cd Build
188 | docker compose up --build --exit-code-from playwright && echo "Success" || echo "Fail"
189 | ```
190 |
191 | ## Credits
192 |
193 | This TYPO3 extension is created and maintained by:
194 | - Xavier Perseguers (https://www.causal.ch/)
195 | - Markus Klein (https://reelworx.at/)
196 |
197 | A big "Thanks" goes out to all contributors.
198 |
199 |
--------------------------------------------------------------------------------
/Resources/Private/Language/de.locallang_db.xlf:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Case-insensitive pattern to match OpenID Connect role names ("*" matches every character, "|" to separate expressions)
7 | Groß-/Kleinschreibung-unempfindliches Muster zum Abgleichen von OpenID Connect-Rollennamen ("*" passt zu jedem Zeichen, "|" zu getrennten Ausdrücken)
8 |
9 |
10 | OpenID Connect Identifier
11 | OpenID Connect Identifier
12 |
13 |
14 | Authentication service priority: This defines the order of the OIDC authentication service in relation to other authentication services. Higher number wins.
15 | Authentifizierungs-Service Priorität: Definiert die Reihenfolge des OIDC Authentifizierungs-Service in Bezug auf andere Authentifizierungs-Services. Höhere Zahl gewinnt.
16 |
17 |
18 | Authentication service Quality: This is used by TYPO3 if two authentication services have the same priority. Higher number wins.
19 | Authentifizierungs-Service Qualität: TYPO3 nutzt diesen Wert, wenn zwei Authentifizierungs-Services die gleiche Priorität besitzen. Höhere Zahl gewinnt.
20 |
21 |
22 | Route for retrieving the authentication URL of the Identity Provider
23 | Route um die Authentifzierungs-URL des Identitäts-Anbieters zu erhalten
24 |
25 |
26 | Enable PKCE: Enable PKCE flow. Code challenge and code verifier will be sent along.
27 | PKCE aktivieren: Aktiviert den PKCE-Fluss. Code-Challenge und Code-Verifier werden mitgeschickt.
28 |
29 |
30 | Frontend Authentication: Enable OpenID Connect authentication for the frontend.
31 | Frontend-Authentifizierung: Aktivieren Sie die OpenID Connect-Authentifizierung für das Frontend.
32 |
33 |
34 | Enable username/password authentication: Enable authentication with username/password via OpenID Connect. e.g. via felogin
35 | Authentifizierung mittels Benutzername/Passwort aktivieren: Aktiviere Authentifizierung mittels Benutzername/Passwort über OpenID Connect. z.B. über felogin
36 |
37 |
38 | Frontend User Must Exist: If ticked, only Frontend Users who are present locally in TYPO3 will be able to authenticate with OpenID Connect. You may need to watch logs to find users who could not authenticate.
39 | Frontend-Benutzer muss vorhanden sein: Wenn dieses Häkchen gesetzt ist, können sich nur Frontend User, die lokal in TYPO3 vorhanden sind, mit OpenID Connect authentifizieren. Möglicherweise müssen Sie die Logs beobachten, um Benutzer zu finden, die sich nicht authentifizieren konnten.
40 |
41 |
42 | OAuth Provider Factory: Fully qualified class name (empty for generic provider).
43 | OAuth Provider Factory: Voll qualifizierter Klassenname (leer für generic provider)
44 |
45 |
46 | Authorize request language parameter name
47 | Name des Sprachparameters für die Autorisierungsanfrage
48 |
49 |
50 | Client Key
51 | Client ID
52 |
53 |
54 | Client Scopes:
55 | Client Scopes:
56 |
57 |
58 | Client Secret:
59 | Client-Secret:
60 |
61 |
62 | Disable CSRF attack mitigation: CAUTION! This is a security protection which checks the return state with the expected value. Disable this protection at your own risk.
63 | Deaktivieren Sie die Abschwächung von CSRF-Angriffen: ACHTUNG! Dies ist ein Sicherheitsschutz, der den Rückgabewert mit dem erwarteten Wert abgleicht. Deaktivieren Sie diesen Schutz auf Ihr eigenes Risiko.
64 |
65 |
66 | Endpoint URI for authorization
67 | Endpunkt-URI für Autorisierung
68 |
69 |
70 | Endpoint URI for logout
71 | Endpunkt-URI für Logout
72 |
73 |
74 | Endpoint URI for revoking the token
75 | Endpunkt-URI für das Widerrufen des Tokens
76 |
77 |
78 | Endpoint URI for retrieving a token
79 | Endpunkt-URI zum Abrufen eines Tokens
80 |
81 |
82 | Endpoint URI for fetching user information
83 | Endpunkt-URI für das Abrufen von Benutzerinformationen
84 |
85 |
86 | Redirect URI: The authentication server callback will point to this URI.
87 | Redirect URI: Der Callback des Authentifizierungsservers wird auf diese URI verweisen.
88 |
89 |
90 | Use Request Path Authentication: When ticked, this value will use Request Path Authentication instead of standard Password Grant.
91 | Anfragepfad-Authentifizierung verwenden: Wenn dieser Wert angekreuzt ist, wird die Request Path Authentication anstelle der standardmäßigen Password Grant verwendet.
92 |
93 |
94 | Re-enable Frontend Users: If ticked, will automatically re-enable Frontend users marked as "disabled" upon successful authentication.
95 | Frontend-Benutzer wieder aktivieren: Wenn angekreuzt, werden als "deaktiviert" markierte Frontend-Benutzer nach erfolgreicher Authentifizierung automatisch wieder aktiviert.
96 |
97 |
98 | Revoke TYPO3's access token at the end of the login process
99 | Zugriffstoken von TYPO3 am Ende des Anmeldevorgangs widerrufen
100 |
101 |
102 | Undelete Frontend Users: If ticked, will automatically restore Frontend users marked as "deleted" upon successful authentication.
103 | Frontend-Benutzer wiederherstellen: Wenn angekreuzt, werden als "gelöscht" markierte Frontend-Benutzer nach erfolgreicher Authentifizierung automatisch wiederhergestellt.
104 |
105 |
106 | Default user group(s) (comma-separated list of UIDs)
107 | Standard-Benutzergruppen (komma-separierte Liste von UIDs)
108 |
109 |
110 | Storage Pid: Comma-separated list of page UIDs where fe_users are located. The first UID is used to store new users.
111 | Ablage Pid: Komma-separierte Liste der Seiten UIDs, wo fe_users gespeichert werden. Die erste UID wird zur Speicherung neuer Benutzer verwendet.
112 |
113 |
114 | OIDC Login
115 | OIDC-Anmeldung
116 |
117 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/Classes/Service/OpenIdConnectService.php:
--------------------------------------------------------------------------------
1 | getAttribute('language');
34 | return $language && $request->getUri()->getPath() === $this->getAuthenticationUrlRoutePath($language);
35 | }
36 |
37 | public function getAuthenticationRequestUrl(): ?UriInterface
38 | {
39 | $request = $GLOBALS['TYPO3_REQUEST'] ?? null;
40 | if ($request) {
41 | $loginUrl = GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
42 | $redirectUrl = $request->getParsedBody()['redirect_url'] ?? $request->getQueryParams()['redirect_url'] ?? '';
43 |
44 | $query = GeneralUtility::implodeArrayForUrl('', [
45 | 'login_url' => $loginUrl,
46 | 'redirect_url' => $redirectUrl,
47 | 'validation_hash' => $this->calculateUrlHash($loginUrl . $redirectUrl),
48 | ]);
49 |
50 | $language = $request->getAttribute('language', $request->getAttribute('site')->getDefaultLanguage());
51 | return $language->getBase()
52 | ->withPath($this->getAuthenticationUrlRoutePath($language))
53 | ->withQuery($query);
54 | }
55 | return null;
56 | }
57 |
58 | /**
59 | * Generate an authentication context for a given frontend request
60 | * The login URL has to be provided as login_url query parameter in the
61 | * given request.
62 | * A redirect URL may be provided either as part of the login URL or as
63 | * a separate redirect_url query parameter. If the login URL contains a
64 | * redirect URL already, the separate redirect_url query parameter will
65 | * not get evaluated.
66 | * If the login URL does not contain a redirect_url query parameter and
67 | * a separate redirect_url is provided within the requet, the redirect
68 | * URL will be added to the login URL. There will be no cHash though.
69 | *
70 | * The login URL and the optional redirect URL need to be signed with a
71 | * validation hash, provided as the validation_hash parameter of the
72 | * given request.
73 | */
74 | public function generateAuthenticationContext(ServerRequestInterface $request, array $authorizationUrlOptions = []): AuthenticationContext
75 | {
76 | if (!$this->config->oidcClientKey
77 | || !$this->config->oidcClientSecret
78 | || !$this->config->endpointAuthorize
79 | || !$this->config->endpointToken
80 | ) {
81 | throw new InvalidArgumentException('Missing extension configuration', 1715775147);
82 | }
83 |
84 | $loginUrl = $request->getQueryParams()['login_url'] ?? '';
85 | if (!GeneralUtility::isValidUrl($loginUrl)) {
86 | throw new InvalidArgumentException('Missing or invalid login_url: ' . $loginUrl, 1759845557572);
87 | }
88 | $redirectUrl = $request->getQueryParams()['redirect_url'] ?? '';
89 | $hash = $request->getQueryParams()['validation_hash'] ?? '';
90 |
91 | if ($this->calculateUrlHash($loginUrl . $redirectUrl) !== $hash) {
92 | throw new InvalidArgumentException('Invalid query string', 1719003567);
93 | }
94 |
95 | // Add logintype to login URL
96 | $loginUrlParams = ['logintype' => 'login'];
97 | if ($redirectUrl != '' && !str_contains($loginUrl, 'redirect_url=')) {
98 | $loginUrlParams['redirect_url'] = $redirectUrl;
99 | }
100 | $loginUrl = \GuzzleHttp\Psr7\Uri::withQueryValues(new Uri($loginUrl), $loginUrlParams)->__toString();
101 |
102 | $authContext = $this->buildAuthenticationContext($request, $authorizationUrlOptions, $loginUrl);
103 | $this->logger->debug('Generated new Authentication Context', ['authContext' => $authContext]);
104 |
105 | return $authContext;
106 | }
107 |
108 | public function buildAuthenticationContext(
109 | ServerRequestInterface $request,
110 | array $authorizationUrlOptions = [],
111 | string $loginUrl = '',
112 | ): AuthenticationContext {
113 | $requestId = $this->getUniqueId();
114 | $codeVerifier = null;
115 | if ($this->config->enableCodeVerifier) {
116 | $codeVerifier = $this->generateCodeVerifier();
117 | $codeChallenge = $this->convertVerifierToChallenge($codeVerifier);
118 | $authorizationUrlOptions = array_merge($authorizationUrlOptions, $this->getCodeChallengeOptions($codeChallenge));
119 | }
120 |
121 | $authorizationUrl = $this->OAuthService->getAuthorizationUrl($request, $authorizationUrlOptions);
122 | $state = $this->OAuthService->getState();
123 |
124 | $normalizedParams = $request->getAttribute('normalizedParams');
125 | $isHttps = $normalizedParams instanceof NormalizedParams && $normalizedParams->isHttps();
126 |
127 | return new AuthenticationContext(
128 | $state,
129 | $loginUrl,
130 | $authorizationUrl,
131 | $requestId,
132 | $isHttps,
133 | $codeVerifier
134 | );
135 | }
136 |
137 | public function getAuthorizationRedirect(AuthenticationContext $authContext)
138 | {
139 | $url = new Uri($authContext->authorizationUrl);
140 | $cookie = $this->authenticationContextService->getCookieForAuthenticationContext($authContext);
141 | return GeneralUtility::makeInstance(RedirectResponse::class, $url)
142 | ->withAddedHeader('Set-Cookie', (string)$cookie);
143 | }
144 |
145 | public function getFinalLoginUrl(AuthenticationContext $authenticationContext, string $code): UriInterface
146 | {
147 | $loginUrl = new Uri($authenticationContext->loginUrl);
148 | return \GuzzleHttp\Psr7\Uri::withQueryValue($loginUrl, 'tx_oidc[code]', $code);
149 | }
150 |
151 | /**
152 | * Returns a unique ID for the current processed request.
153 | *
154 | * This is supposed to be independent of the actual web server (Nginx or Apache) and
155 | * the way PHP was built and unique enough for our use case, as opposed to using:
156 | *
157 | * - zend_thread_id() which requires PHP to be built with Zend Thread Safety - ZTS - support and debug mode
158 | * - apache_getenv('UNIQUE_ID') which requires Apache as web server and mod_unique_id
159 | *
160 | * @return string
161 | */
162 | protected function getUniqueId(): string
163 | {
164 | return sprintf('%08x', abs(crc32($_SERVER['REMOTE_ADDR'] . $_SERVER['REQUEST_TIME'] . $_SERVER['REMOTE_PORT'])));
165 | }
166 |
167 | protected function generateCodeVerifier(): string
168 | {
169 | return bin2hex(random_bytes(64));
170 | }
171 |
172 | protected function convertVerifierToChallenge($codeVerifier): string
173 | {
174 | return rtrim(strtr(base64_encode(hash('sha256', $codeVerifier, true)), '+/', '-_'), '=');
175 | }
176 |
177 | protected function getCodeChallengeOptions($codeChallenge): array
178 | {
179 | return [
180 | 'code_challenge' => $codeChallenge,
181 | 'code_challenge_method' => 'S256',
182 | ];
183 | }
184 |
185 | protected function getAuthenticationUrlRoutePath(SiteLanguage $language): string
186 | {
187 | return $language->getBase()->getPath() . $this->config->authenticationUrlRoute;
188 | }
189 |
190 | protected function calculateUrlHash(string $value): string
191 | {
192 | if (class_exists(\TYPO3\CMS\Core\Crypto\HashService::class)) {
193 | // TYPO3 v13
194 | $calculatedHash = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Crypto\HashService::class)->hmac($value, 'oidc');
195 | } else {
196 | // TYPO3 v12
197 | $calculatedHash = GeneralUtility::hmac($value, 'oidc');
198 | }
199 | return $calculatedHash;
200 | }
201 | }
202 |
--------------------------------------------------------------------------------
/Classes/Service/OAuthService.php:
--------------------------------------------------------------------------------
1 | eventDispatcher->dispatch(new GetAuthorizationUrlEvent($request, $this->settings, $options));
61 | $options = $event->options;
62 | return $this->getProvider()->getAuthorizationUrl($options);
63 | }
64 |
65 | /**
66 | * Returns the state generated for us.
67 | *
68 | * @return string
69 | * @see getAuthorizationUrl()
70 | */
71 | public function getState(): string
72 | {
73 | return $this->getProvider()->getState();
74 | }
75 |
76 | /**
77 | * Returns an AccessToken using either authorization code grant or resource owner password
78 | * credentials grant.
79 | *
80 | * @param string $codeOrUsername Either a code or the username (if password is provided)
81 | * @param string|null $password Optional parameter if authenticating with authorization code grant
82 | * @param string|null $codeVerifier Code verifier for PKCE
83 | * @return AccessToken
84 | * @throws IdentityProviderException
85 | */
86 | public function getAccessToken(
87 | string $codeOrUsername,
88 | #[\SensitiveParameter]
89 | ?string $password = null,
90 | #[\SensitiveParameter]
91 | ?string $codeVerifier = null
92 | ): AccessToken {
93 | if ($password === null) {
94 | $options = [
95 | 'code' => $codeOrUsername,
96 | ];
97 | if ($codeVerifier !== null) {
98 | $options['code_verifier'] = $codeVerifier;
99 | }
100 | $grant = new AuthorizationCode();
101 | } else {
102 | $options = [
103 | 'username' => $codeOrUsername,
104 | 'password' => $password,
105 | ];
106 | $grant = new Password();
107 | }
108 | return $this->getProvider()->getAccessToken($grant, $options);
109 | }
110 |
111 | /**
112 | * @throws IdentityProviderException
113 | */
114 | public function getAccessTokenForClient(): AccessTokenInterface
115 | {
116 | return $this->getProvider()->getAccessToken(new ClientCredentials());
117 | }
118 |
119 | /**
120 | * Returns an AccessToken using request path authentication.
121 | *
122 | * This non-standard behaviour is described on
123 | * https://docs.wso2.com/display/IS530/Try+Password+Grant
124 | *
125 | * @param string $username
126 | * @param string $password
127 | * @return AccessToken|null
128 | * @throws IdentityProviderException
129 | */
130 | public function getAccessTokenWithRequestPathAuthentication(string $username, #[\SensitiveParameter] string $password): ?AccessToken
131 | {
132 | $url = $this->settings->endpointAuthorize . '?' . http_build_query([
133 | 'response_type' => 'code',
134 | 'client_id' => $this->settings->oidcClientKey,
135 | 'scope' => $this->settings->oidcClientScopes,
136 | 'redirect_uri' => $this->getRedirectUrl(),
137 | ]);
138 |
139 | $result = GeneralUtility::makeInstance(RequestFactory::class)->request(
140 | 'GET',
141 | $url,
142 | [
143 | RequestOptions::AUTH => [$username, $password],
144 | RequestOptions::ALLOW_REDIRECTS => false,
145 | ]
146 | );
147 |
148 | if ($result->getStatusCode() < 300 || $result->getStatusCode() >= 400) {
149 | throw new RuntimeException('Request failed', 1510049345);
150 | }
151 |
152 | if ($result->getHeader('Location')) {
153 | $targetUrl = $result->getHeader('Location')[0];
154 | $query = parse_url($targetUrl, PHP_URL_QUERY);
155 | parse_str($query, $queryParams);
156 | if (isset($queryParams['code'])) {
157 | return $this->getAccessToken($queryParams['code']);
158 | }
159 | }
160 |
161 | return null;
162 | }
163 |
164 | /**
165 | * Returns the resource owner.
166 | *
167 | * @param AccessToken $token
168 | * @return ResourceOwnerInterface
169 | * @throws IdentityProviderException May be thrown by provider
170 | */
171 | public function getResourceOwner(AccessToken $token): ResourceOwnerInterface
172 | {
173 | return $this->getProvider()->getResourceOwner($token);
174 | }
175 |
176 | /**
177 | * Revokes the access token.
178 | *
179 | * @param AccessToken $token
180 | * @return bool
181 | * @throws IdentityProviderException
182 | */
183 | public function revokeToken(AccessToken $token): bool
184 | {
185 | if (!$this->settings->endpointRevoke) {
186 | return false;
187 | }
188 |
189 | $provider = $this->getProvider();
190 | $request = $provider->getRequest(
191 | AbstractProvider::METHOD_POST,
192 | $this->settings->endpointRevoke,
193 | [
194 | 'headers' => [
195 | 'Authorization' => 'Basic ' . base64_encode($this->settings->oidcClientKey . ':' . $this->settings->oidcClientSecret),
196 | 'Content-Type' => 'application/x-www-form-urlencoded',
197 | ],
198 | 'body' => 'token=' . $token->getToken(),
199 | ]
200 | );
201 |
202 | $response = $provider->getParsedResponse($request);
203 | // TODO error handling?
204 |
205 | return true;
206 | }
207 |
208 | protected function getProvider(): AbstractProvider
209 | {
210 | if ($this->provider === null) {
211 | if (!is_a($this->settings->oauthProviderFactory, OAuthProviderFactoryInterface::class, true)) {
212 | throw new RuntimeException('OAuth provider factory class must implement the OAuthProviderFactoryInterface', 1652689564769);
213 | }
214 |
215 | $settings = $this->settings;
216 | $settings->oidcRedirectUri = $this->getRedirectUrl();
217 |
218 | $factory = GeneralUtility::makeInstance($this->settings->oauthProviderFactory);
219 | $this->provider = $factory->create($settings);
220 | }
221 |
222 | return $this->provider;
223 | }
224 |
225 | public function getFreshAccessToken(string $serializedToken): ?AccessToken
226 | {
227 | $options = json_decode($serializedToken, true);
228 | if (empty($serializedToken) || empty($options)) {
229 | // Invalid token
230 | return null;
231 | }
232 | $accessToken = new AccessToken($options);
233 |
234 | if (!$accessToken->hasExpired()) {
235 | return $accessToken;
236 | }
237 |
238 | try {
239 | $newAccessToken = $this->getProvider()->getAccessToken(new RefreshToken(), [
240 | 'refresh_token' => $accessToken->getRefreshToken(),
241 | ]);
242 | return $newAccessToken;
243 | } catch (IdentityProviderException $e) {
244 | // TODO: log problem
245 | return null;
246 | }
247 |
248 | return $accessToken;
249 | }
250 |
251 | protected function getRedirectUrl(): string
252 | {
253 | return $this->settings->oidcRedirectUri ?: GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
254 | }
255 | }
256 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------