Skip to Content
SDKsPHP

PHP SDK (auris/sdk)

auris/sdk v0.1.0

auris/sdk provides an OAuth Authorization Code flow with PKCE, token exchange, refresh and user validation. It uses PHP built-ins rather than external runtime packages.

Requirements

The package requires PHP 7.4 or later and the extensions listed in its Composer manifest. The positional arguments below also work on PHP 7.4; named arguments require PHP 8. Start a PHP session before using the default SessionTokenStore.

composer require auris/sdk

Register a public application and its exact callback URL in Auris. Use HTTPS in production. The current token-exchange implementation does not send the configured clientSecret; do not treat that field as proof of confidential-client authentication.

Configuration

Create a shared bootstrap.php. Supply the environment variables from your application configuration; no real credentials are included here. AURIS_TENANT is the realm of the tenant your application belongs to: getUser() refuses to authenticate anyone without it, because any person can create their own tenant and obtain a valid token through your application’s login.

<?php declare(strict_types=1); require __DIR__ . '/vendor/autoload.php'; use Auris\AurisClient; use Auris\AurisConfig; session_start(); $domain = getenv('AURIS_DOMAIN'); $clientId = getenv('AURIS_CLIENT_ID'); $redirectUri = getenv('AURIS_REDIRECT_URI'); $tenant = getenv('AURIS_TENANT'); if (!$domain || !$clientId || !$redirectUri || !$tenant) { throw new RuntimeException('Auris application configuration is required'); } // AURIS_DOMAIN includes https:// and has no trailing slash. // The sixth positional argument is the token store; the tenant is the seventh. $auris = new AurisClient(new AurisConfig($domain, $clientId, $redirectUri, '', 'openid email profile', null, $tenant));

Use secure, HTTP-only session cookies with an appropriate SameSite policy in your deployment. Do not expose bearer or refresh tokens to browser scripts or logs.

Login

<?php // login.php require __DIR__ . '/bootstrap.php'; header('Location: ' . $auris->getLoginUrl()); exit;

getLoginUrl() generates PKCE and state values, stores them through the configured TokenStore, and returns the hosted authorization URL. Start one login attempt per session at a time.

Callback

<?php // callback.php require __DIR__ . '/bootstrap.php'; try { $tokens = $auris->handleCallback($_GET['code'] ?? '', $_GET['state'] ?? ''); if ($tokens->accessToken === '') { throw new RuntimeException('No access token returned'); } $user = $auris->getUser($tokens->accessToken); session_regenerate_id(true); $_SESSION['auris_access_token'] = $tokens->accessToken; $_SESSION['auris_refresh_token'] = $tokens->refreshToken; header('Location: /account.php'); exit; } catch (Throwable $error) { http_response_code(400); echo 'Sign-in failed. Start a new login attempt.'; }

handleCallback(code, state) checks the stored state and exchanges the authorization code. It returns a TokenResult; your application must store the returned tokens. The SDK’s default store holds PKCE/state values, not an automatically managed authenticated session.

Validate the user

<?php // account.php require __DIR__ . '/bootstrap.php'; $token = $_SESSION['auris_access_token'] ?? ''; if ($token === '' || $auris->isTokenExpired($token)) { header('Location: /login.php'); exit; } try { $user = $auris->getUser($token); echo htmlspecialchars($user->firstName ?? $user->userId, ENT_QUOTES, 'UTF-8'); } catch (Throwable $error) { unset($_SESSION['auris_access_token'], $_SESSION['auris_refresh_token']); http_response_code(401); echo 'Your session could not be validated. Sign in again.'; }

getUser(accessToken) calls Auris token validation bound to your tenant: the request carries strictTenant, and the tenant named in the answer is compared with AurisConfig::$tenant. A valid token of any other tenant throws an AurisException with error code tenant_mismatch (tenant_required when no tenant is configured), and role names are never read before the tenant matched. isTokenExpired(accessToken) only decodes the expiry claim; it does not verify a signature and is not an authorization decision. Check action/resource permissions before returning protected business data.

Token management

MethodContract
getLoginUrl(options = [])Returns the hosted authorization URL and stores PKCE/state
handleCallback(code, state)Returns a TokenResult from code exchange
refreshToken(refreshToken)Requires an explicit refresh token and returns replacement tokens
isTokenExpired(accessToken)Local expiry inspection only
getUser(accessToken)Validates the access token through the Auris API for the configured tenant and returns AurisUser; throws for another tenant
logout(accessToken)Calls the logout endpoint; clear your application’s session separately

TokenResult contains accessToken, nullable refreshToken, tokenType, expiresIn and nullable scope. It does not provide an idToken or getUser() method. AurisClient does not provide isAuthenticated() or getAccessToken(); those are responsibilities of your session layer.

When refreshing, replace the stored access token and any rotated refresh token atomically. Submit logout through a CSRF-protected application POST, call logout($token), then clear the local session. Do not implement a state-changing logout link as an unprotected GET.

Webhooks

Event-subscription deliveries are signed with HMAC-SHA256 over <X-Auris-Timestamp>.<body>, keyed with the whole signing secret (the whsec_ prefix is part of the key). WebhooksHelper::verifyTimestampedSignature($payload, $signature, $timestamp, $secret) verifies that scheme and rejects timestamps more than 5 minutes from now (replay protection). WebhooksHelper::verifySignature($payload, $signature, $secret) checks a signature over the body only, which is the scheme of log-stream WEBHOOK deliveries; those carry no timestamp, so a captured delivery can be replayed.

Test before rollout

Test a valid callback, wrong state, expired or reused authorization code, a missing browser session, refresh failure and a rejected validation response. Confirm the exact API contract of the SDK version you install. This guide describes the repository implementation; the examples were reviewed against its method signatures and do not establish a live tenant acceptance test.

For a standalone API verification exercise, use the Node.js signed-token example. To review your callback, session and tenant boundaries, request an Auris integration demo .