Search by

tualo / oauth2

tualo

OAuth 2.0 and OpenID Connect authorization server for Tualo Office

Package info

github.com/tualo/oauth2

pkg:composer/tualo/oauth2

Statistics

Installs: 15

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.8 2026-11-23 07:27 UTC

This package is auto-updated.

Last update: 2026-11-23 07:27:57 UTC


README

Authorization server package for Tualo Office. The package is based on the Tualo package blueprint and uses League OAuth 2.0 Server plus its OpenID Connect extension for protocol handling.

The PSR-7 dependency supports both Guzzle PSR-7 2.7+ and 3.2+ so that this package can be installed alongside packages using Guzzle HTTP 8.3.1+.

Agreed first release

  • Authorization Code grant with PKCE for user authorization
  • Client Credentials grant for service-to-service access
  • OpenID Connect ID tokens and user information for user sign-in
  • Signed JWT access tokens and a public JWKS endpoint
  • Tualo's existing user session for end-user authentication
  • OAuth clients managed in a Tualo administration interface
  • Private signing keys configured as PEM files outside the web root

The package will not implement OAuth/OIDC cryptography or grant processing itself. Client secrets and signing keys must never be exposed in API responses, logs, source control, or the administration UI after creation.

Package layout

  • src/Routes/ contains thin protocol endpoint adapters.
  • src/Services/ contains authorization-server setup and Tualo integration.
  • src/Repositories/ contains OAuth entity persistence.
  • src/Entities/ contains OAuth/OIDC entities and claims.
  • src/Commands/ contains schema and package installation tasks.
  • src/js/ contains the Tualo administration interface.
  • docs/ARCHITECTURE.md records the agreed protocol and integration boundaries.

Development status

The package contains League-compatible OAuth entities and repositories, the authorization-server factory, the stable OIDC subject mapping, and session-database tables for clients, codes, and tokens. The authorization entry point validates requests, requires PKCE with S256, binds requests to the Tualo login session, and starts the separate consent flow. Refresh tokens are issued only for offline_access and are rotated on use.

The schema is installed into Tualo's session database with install-oauth2. OAuth repositories and environment settings use that same session database (Session::$db), not the tenant database returned by Session::getDB(). Consent handling, the token/JWKS/UserInfo routes, and the client administration interface are still required before the package can be used as a running authorization server.

The authorization-server factory reads issuer_url, auth_token_ttl, access_token_ttl, refresh_token_ttl, and device_code_ttl through Setup::env(). Durations use PHP's ISO-8601 DateInterval format; defaults are PT5M, PT15M, P30D, and PT10M, respectively.

Configure the signing key

oauth2.private_key_path must be an absolute filesystem path to a readable PEM-encoded RSA private key on the machine/container running PHP. It is not a URL and must not include the file:// prefix. Store it outside the web document root and outside the repository; the OAuth server adds the file:// prefix itself when loading the key. For example, if the document root is /var/www/tualo/server, use a path such as /etc/tualo/oauth2/private.key, not a path below /var/www/tualo/server.

Create a key on the server, restrict access, and grant read permission to the PHP/web-server user:

sudo install -d -o root -g www-data -m 0750 /etc/tualo/oauth2
sudo openssl genpkey -algorithm RSA \
  -pkeyopt rsa_keygen_bits:4096 \
  -out /etc/tualo/oauth2/private.key
sudo chown root:www-data /etc/tualo/oauth2/private.key
sudo chmod 0640 /etc/tualo/oauth2/private.key
sudo -u www-data openssl pkey \
  -in /etc/tualo/oauth2/private.key -check -noout

Replace www-data with the actual group and user used by PHP-FPM/the web server. The final validation command should succeed when run as that user. Keep a protected backup of the key: replacing it invalidates signatures from the old key unless key rotation is configured.

Generate a new Defuse encryption key using the application's Composer autoload (run this from the application directory that contains vendor/):

php -r 'require "vendor/autoload.php"; echo \Defuse\Crypto\Key::createNewRandomKey()->saveToAsciiSafeString(), PHP_EOL;'

Copy the generated value into the application's .htconfig under the [oauth2] section, along with the private key path:

[oauth2]
private_key_path=/etc/tualo/oauth2/private.key
encryption_key=PASTE_THE_GENERATED_VALUE_HERE

The text above is an instruction, not a usable encryption key: do not leave PASTE_THE_GENERATED_VALUE_HERE or DEFUSE_ASCII_SAFE_KEY in the configuration. Keep the generated key secret and backed up securely; losing or changing it invalidates encrypted authorization data such as pending codes and tokens.

If the PEM private key is not encrypted, omit private_key_passphrase entirely. In .htconfig, null is read as the literal string "null" and will be treated as an actual passphrase. If the PEM is encrypted, set private_key_passphrase to its real passphrase. Neither the encryption key nor the passphrase belongs in source control or in a publicly served configuration file. A missing, unreadable, invalid, or web-root-resident private key prevents the authorization server from starting.

Testing the authorization login

Use the example script with an existing client whose redirect URI is registered. It creates a PKCE S256 request and opens it in the default browser so the Tualo login session and notification-based continuation are tested in that browser:

OAUTH2_ISSUER_URL="https://auth.example.test" \
OAUTH2_CLIENT_ID="your-client-id" \
OAUTH2_REDIRECT_URI="http://127.0.0.1:8912/callback" \
./tools/authorize-example.sh

The script requires openssl and php. Set OPEN_BROWSER=0 to print the URL without opening a browser. When the redirect URI points to the loopback interface (http://127.0.0.1, http://localhost), the script serves the callback itself with php -S, waits for the authorization code issued after consent (timeout via OAUTH2_CALLBACK_TIMEOUT, default 300 seconds), verifies the state, and prints the code together with a ready-to-use curl command for the token exchange. The loopback redirect URI must be registered for the client. For non-loopback redirect URIs the script only opens the authorization request and prints the code_verifier for a manual token exchange.

Clients without a reachable callback URL

For clients that cannot receive a redirect (firewall, NAT, no listener) the server supports the Device Authorization Grant (RFC 8628) and, as a fallback, a manual code-display page (<issuer>/oauth2/manual-code registered as the client's redirect URI). Test the device flow with:

OAUTH2_ISSUER_URL="https://auth.example.test" \
OAUTH2_CLIENT_ID="your-client-id" \
./tools/device-example.sh

The script requests a device code, opens the verification page in the browser, and polls the token endpoint until the request is approved, denied, or expired. The client must have the grant type urn:ietf:params:oauth:grant-type:device_code registered. Set OAUTH2_SCOPE to override the requested scopes and OAUTH2_INSECURE=1 for self-signed test certificates. See docs/ARCHITECTURE.md for the protocol details.