Download the PHP package seablast/auth without Composer

On this page you can find all versions of the php package seablast/auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package auth

Seablast Auth

A no-password authentication and authorization extension for Seablast for PHP apps. This extension facilitates secure user verification and efficient access control.

Optionally, Seablast Auth has a lightweight integration with Google and Facebook to support social authentication, allowing seamless sign-in through various social media platforms. Integrable via Composer, it activates only when required, equipping your app with essential security features effortlessly. If your Seablast-based application necessitates user authentication or resource authorization, incorporating Seablast Auth will equip it with these capabilities instantly. (For applications that do not require these features, Seablast Auth can simply be omitted to maintain a lighter application footprint.)

Note: Ensure that your PHP and MySQL timezones are properly set, as the code uses CURRENT_TIMESTAMP for time-related operations. (It would be possible to use purely SQL statements with INTERVAL but at a cost of not caching the SQL responses.)

User management

Usage

When just getting the identity of a logged-in user is needed:

To create the expected database table structure, just add the seablast/auth migration path to your phinx.php configuration, e.g.

Following tables will be created (prefixed as set in your app), so avoid conflict with the naming of tables by your app:

Group membership validity

GroupManager::addUserToGroup() accepts an optional DateTimeInterface $validTo argument. A null value creates an unlimited membership. group_activation_tokens.valid_for_days can likewise be null for unlimited membership, or a positive number of 24-hour periods starting when the token is activated.

Membership expiration is evaluated using the start of the current hour. A valid_to value within the current hour therefore remains effective until the next whole hour, while a value exactly on an hour boundary expires at that boundary. The activation token's own valid_from and valid_to window remains exact.

Authentication time limits

Seablast starts the PHP session before the authentication models run. A successful email-token or social login therefore adds a newly generated token to the existing $_SESSION['sbSessionToken'] and stores only its hash in session_user; Seablast Auth does not create the PHP session cookie itself.

Limit Duration Behavior
PHP session cookie 3 hours (10,800 seconds) by default This is an absolute lifetime from when the cookie is issued, not an inactivity timeout. SB_SESSION_SET_COOKIE_PARAMS_LIFETIME controls it; ordinary requests reapply the cookie parameters but do not refresh the expiration time of an existing cookie (TODO: consider session_regenerate_id()).
Session authentication token Approximately 1 day of inactivity (nominally 86,400 seconds and effectively up to just under 25 hours) The unhashed token exists only in the PHP session, while its hash is stored in session_user. Validation uses an hourly boundary, and activity refreshes the database timestamp after more than 5 minutes.
Remember Me 30 days (2,592,000 seconds) Over HTTPS, a successful email-token or social login creates this cookie when enabled. A successful automatic login rotates the token and restarts the 30-day period.
Login-email resend cooldown 120 seconds Repeated requests for the same email address are suppressed during this period.

With the Seablast defaults, SB_SESSION_SET_COOKIE_LIFETIME is 48 hours and makes session.gc_maxlifetime twice that value (96 hours). It does not make the browser cookie last 48 hours because the more specific SB_SESSION_SET_COOKIE_PARAMS_LIFETIME takes precedence and sets the cookie lifetime to 3 hours. The server-side PHP session data and the database token may therefore remain after the browser has stopped sending the cookie.

Once the PHP session cookie expires, isAuthenticated() cannot access $_SESSION['sbSessionToken'], regardless of whether its hash in session_user is still within the 1-day validity window. The bundled UserModel can then use a valid sbRememberMe cookie to populate the new PHP session with a new authentication token and redirect the user back to the requested URL. isAuthenticated() does not perform this automatic login itself. Without a valid Remember Me cookie, the user must log in again.

Suppressed login-email requests return the same generic confirmation as accepted requests so that the response does not reveal internal request state. The cooldown is a per-address safeguard only; consuming applications should add per-IP and global rate limiting at the application, reverse-proxy, or edge layer.

Cookies

IdentityManager expects cookie scope being set already by:

Note: sbRememberMe cookie is created/read only if the web is accessed over HTTPS and if allowed by AuthApp:FLAG_REMEMBER_ME_COOKIE (allowed by default). The cookie is set with HttpOnly, Secure, and SameSite=Lax. Bundled models inject the flag into IdentityManager; direct IdentityManager users can call setRememberMeCookieEnabled(false).

Routing

/user is the default route (which can be changed by AuthConstant::USER_ROUTE) to the user log-in/log-out page, but if you want to customize it, configure path to your own template within your app's conf/app.conf.php like this:

Email login links carry the originally requested app-relative path and query string in a URL-encoded returnUrl parameter. After a successful one-time-token login, UserModel redirects back to that same-app target. Missing or invalid return targets fall back to the configured user route; external return URLs are never accepted.

Successful login either reloads the current page or goes to a social login success page:

Note 1: Seablast::v0.2.5 and newer use the default settings in the conf/app.conf.php, so Seablast Auth configuration is loaded automatically.

send-auth-token.js (since Seablast::v0.2.10) expects the route /api/social-login as configured in app.conf.php and provider either facebook or google.

These arguments window.sendAuthToken(token, apiRoute, errorLogger); are processed since Seablast::v0.2.13.

Note 2: const API_BASE = ''; const flags = []; MUST be defined in JavaScript as the default /user expects these two variables.

View

\Seablast\Auth\UserModel returns arguments ($configuration, $csrfToken, $message, $showLogin, $showLogout) for the user.latte template:

Note 1: user.latte uses inherite.latte for all the latte parts, so either you may use it or include user-control.latte or create app version of any of the latte parts.

Note 2: vendor/seablast is accessible for Seablast apps, so the web browser assets (such as send-auth-token.js) used by plugins MUST be put into assets folder of the Seablast library.

Social login

The presence of configuration strings FACEBOOK_APP_ID with FACEBOOK_APP_SECRET, or GOOGLE_CLIENT_ID, enables login by these platforms respectively. Facebook access tokens are validated through debug_token for the configured app before the email is trusted.

Note 1: social login can be deactivated in an app by ->deactivate(AuthConstant::FLAG_USE_SOCIAL_LOGIN) in the configuration.

Note 2: send-auth-token.js is expected in seablast directory, which needs at least Seablast v0.2.10. (These arguments window.sendAuthToken(token, apiRoute, errorLogger); are processed since Seablast::v0.2.13.)

Note 3: The new Google Identity Services no longer opens a traditional pop-up account chooser; instead, it displays the One Tap UI.

MailOut::send() method is a generic mail sender built on top of Symfony Mailer

In order to send emails, the SeablastConstant::USER_MAIL_ENABLED flag MUST be activated.

Local login-email testing with Mailpit

Raw email login tokens are intentionally neither exposed in Tracy dumps nor stored in recoverable form in the database, where only their hashes are kept. For local development, use Mailpit to capture the outgoing email and retrieve its one-time login link. By default, Mailpit accepts SMTP connections on port 1025 and provides its web interface at http://localhost:8025/.

Enable local email delivery in your application's conf/app.conf.local.php:

The default SMTP host is already localhost. Start Mailpit, request a login email, then open its web interface and follow the captured login link. Keep this mail-catching configuration local; do not use it in production.

Cloudflare Turnstile

To prevent spam caused by misuse of the login and registration functionality, the bundled login/registration form supports Cloudflare's Managed Turnstile widget. Configure the following values in the consuming application's private configuration:

Import Seablast\Auth\AuthConstant. Both keys must be nonempty to enable protection; missing either key preserves the existing behavior. With protection enabled, an empty hostname list rejects all requests. List exact frontend hostnames without schemes, ports or paths, and configure the widget's allowed domains in Cloudflare as well. Use a deployment-specific list: production must not include localhost or 127.0.0.1. Keep the secret out of source control, HTML and logs. The public site key belongs to the consuming application, not this library's defaults.

Verification runs after email and CSRF validation, before registration, token creation or mail delivery. Cloudflare must return boolean success, action login_email, and an allowed hostname. Network failures also reject the request. The existing 120-second email resend limit remains in effect. Email-link login, Remember Me and social login are unaffected. Direct calls to IdentityManager::login() are not protected by this gate.

Custom forms must load https://challenges.cloudflare.com/turnstile/v0/api.js, include <div class="cf-turnstile" data-sitekey="YOUR_PUBLIC_SITE_KEY" data-action="login_email"></div> inside the form and submit cf-turnstile-response along with email and CSRF to UserModel. Custom handlers must apply equivalent verification before their own side effects. If CSP is enabled, allow https://challenges.cloudflare.com in script-src and frame-src. The bundled native form reloads after submission; custom Ajax forms must reset their widget after each attempt, since tokens are single-use and expire after five minutes.

Before production rollout, test one real successful submission on an allowed hostname, then replay the same token and confirm no second email or registration occurs. See Cloudflare validation documentation.

Turnstile failures are logged through Tracy at DEBUG level with the prefix Turnstile verification rejected:. Reasons distinguish missing/invalid input, an empty hostname allowlist, HTTP status, invalid JSON, rejected verification (with recognized Cloudflare error codes), action/hostname mismatch and transport errors. Use the application's configured Tracy logger destination (normally debug.log with Tracy's file logger). Tokens, secret keys, raw responses and exception messages are never logged.

Testing

Run .\vendor\bin\phpunit on Windows for essential PHPUnit tests. From Git Bash, ./test.sh also prepares the testing database migration before running PHPUnit.

TODO


All versions of auth with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2 <8.6
guzzlehttp/guzzle Version 6.5.8 || ^7.8
nette/utils Version ^3.2.10 || ^4.0.5 || ^4.1.0
robmorgan/phinx Version ^0.12.13 || ^0.13.4 || ^0.14.0 || ^0.15.5 || ^0.16.5
seablast/interfaces Version ^0.1.1
symfony/mailer Version ^4.4.49 || ^5 || ^6 || ^7 || ^8
symfony/security-csrf Version ^4.4.37 || ^5 || ^6 || ^7 || ^8
tracy/tracy Version ^2.9.8 || ^2.10.9 || ^2.11.0
webmozart/assert Version ^1.10.0 || ^2.1.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package seablast/auth contains the following files

Loading the files please wait ...