Skip to main content

Laravel

The yorauth/laravel-sdk package wraps the YorAuth PHP SDK with a Laravel service provider, facade, middleware, OIDC controllers, and a webhook system. Supports Laravel 10, 11, and 12.

The Laravel SDK is currently in development. This documentation describes the intended API and developer experience. The package is not yet published to Packagist.

Key Features

  • Auto-discovered service provider with config publishing
  • YorAuth facade proxying all PHP SDK resources
  • OIDC Authorization Code + PKCE flow with auto-registered routes
  • Multi-context OIDC for applications with multiple auth panels
  • Webhook endpoint with signature verification and typed Laravel events
  • Middleware for authentication and permission checks
  • Artisan commands for connection testing and listener scaffolding

Installation

bash
composer require yorauth/laravel-sdk

The service provider is auto-discovered. Publish the config file:

bash
php artisan vendor:publish --tag=yorauth-config

Add the required environment variables:

dotenv
YORAUTH_APPLICATION_ID=your-application-uuid
YORAUTH_API_KEY=ya_live_abc123...
YORAUTH_BASE_URL=https://api.yorauth.dev

Usage

Facade

php
use YorAuth\Laravel\Facades\YorAuth;

$login = YorAuth::auth()->login('jane@example.com', 'secret');
YorAuth::setToken($login['data']['access_token']);

Dependency Injection

php
use YorAuth\Sdk\YorAuth;

class UserController extends Controller
{
    public function __construct(private YorAuth $yorauth) {}

    public function show(string $userId)
    {
        return $this->yorauth->users()->getProfile($userId);
    }
}

SDK Resources

The facade exposes all resources from the PHP SDK:

MethodResourceDescription
auth()AuthResourceRegistration, login (with CAPTCHA/remember-me options), logout, token refresh, password reset, email verification, magic links, MFA verification, CAPTCHA status
users()UserResourceProfile management, password change, account deletion, GDPR data export, consent withdrawal
roles()RoleResourceRole CRUD, user-role assignments, user permission lookups
permissions()PermissionsResourceSingle and bulk permission checks
sessions()SessionResourceList, revoke individual or all sessions
mfa()MfaResourceTOTP setup/confirm/disable, backup codes, MFA status
oidc()OidcResourceOIDC client management, discovery, JWKS, authorize, token, client credentials, device authorization, logout URL
passkeys()PasskeyResourceWebAuthn/passkey authentication ceremonies and credential management
saml()SamlResourceSAML SSO initiation and connection listing
userAttributes()UserAttributeResourceUser attribute get/set/delete for ABAC
teams()TeamResourceTeam CRUD, member management, team role assignments
webhooks()WebhookResourceWebhook configuration and delivery history
apiKeys()ApiKeyResourceAPI key management
auditLogs()AuditLogResourceAudit log viewing with filters

Authentication

Login with Options

The login() method accepts an optional third parameter for CAPTCHA tokens and remember-me:

php
$login = YorAuth::auth()->login($email, $password, [
    'captcha_token' => $captchaResponse,
    'remember_me' => true,
]);

CAPTCHA Status

Check whether CAPTCHA is enabled for your application:

php
$status = YorAuth::auth()->getCaptchaStatus();
// $status['data']['enabled'], $status['data']['provider'], $status['data']['site_key']

Passkeys (WebAuthn)

Passwordless authentication using platform authenticators and security keys.

php
// Authentication ceremony (public, no JWT required)
$options = YorAuth::passkeys()->authenticateOptions();
$result  = YorAuth::passkeys()->authenticateVerify($credential);

// Credential registration (JWT required, user ownership)
$options = YorAuth::passkeys()->registerOptions($userId);
$result  = YorAuth::passkeys()->registerVerify($userId, $credential);

// Credential management
$passkeys = YorAuth::passkeys()->list($userId);
YorAuth::passkeys()->update($userId, $credentialId, ['name' => 'My Laptop']);
YorAuth::passkeys()->delete($userId, $credentialId);

SAML SSO

Initiate enterprise SAML single sign-on flows.

php
$redirect = YorAuth::saml()->initiate([
    'connection_id' => $connectionId,
    'relay_state' => '/dashboard',
]);

$connections = YorAuth::saml()->getConnections();

User Attributes (ABAC)

Manage custom key-value attributes on users for Attribute-Based Access Control.

php
$attrs = YorAuth::userAttributes()->get($userId);

YorAuth::userAttributes()->set($userId, [
    'department' => 'engineering',
    'clearance_level' => 'secret',
]);

YorAuth::userAttributes()->delete($userId, 'clearance_level');

OIDC Grant Types

Client Credentials (RFC 6749 Section 4.4)

Service-to-service authentication without user context:

php
$tokens = YorAuth::oidc()->clientCredentialsToken($clientId, $clientSecret);
$tokens = YorAuth::oidc()->clientCredentialsToken($clientId, $clientSecret, 'scope1 scope2');

Device Authorization (RFC 8628)

For devices that cannot display a browser (TVs, CLIs, IoT):

php
// Step 1: Request device and user codes
$device = YorAuth::oidc()->deviceAuthorize([
    'client_id' => $clientId,
    'scope' => 'openid profile',
]);
// Display $device['user_code'] and $device['verification_uri'] to user

// Step 2: Poll for token (in a loop with $device['interval'] seconds between calls)
$tokens = YorAuth::oidc()->deviceCodeToken($device['device_code'], $clientId);

RP-Initiated Logout

Build a logout URL for ending the user's OIDC session:

php
$logoutUrl = YorAuth::oidc()->buildLogoutUrl($idTokenHint, '/logged-out');
return redirect()->away($logoutUrl);

Permanently delete a user's account and all associated data (irreversible):

php
YorAuth::users()->withdrawConsent($userId);

OIDC Routes

When YORAUTH_OIDC_CLIENT_ID is set, routes are auto-registered:

  • GET /auth/yorauth/redirect -- Redirects to YorAuth for login
  • GET /auth/yorauth/callback -- Handles the OIDC callback
  • POST /auth/yorauth/logout -- Logs out and invalidates session

Multi-Context OIDC

For applications with multiple auth panels (e.g., customer + staff), define contexts in config/yorauth.php. Context routes are auto-registered as /auth/yorauth/{context}/redirect, /auth/yorauth/{context}/callback, and /auth/yorauth/{context}/logout.

Middleware

AliasClassDescription
yorauth.authenticatedRequireAuthenticatedVerifies user is authenticated via YorAuth OIDC (401 on failure)
yorauth.permissionRequirePermissionChecks YorAuth permissions (401/403 on failure)
yorauth.verify-webhookVerifyWebhookSignatureVerifies webhook payload signatures

Webhooks

When YORAUTH_WEBHOOK_SECRET is set, the SDK auto-registers a POST endpoint at /yorauth/webhook (configurable) with signature verification.

Listener Classes

Create listeners with artisan and register them in config:

bash
php artisan make:yorauth-listener SyncUsersListener
php
// config/yorauth.php
'webhook' => [
    'secret' => env('YORAUTH_WEBHOOK_SECRET'),
    'listeners' => [
        \App\Listeners\YorAuth\SyncUsersListener::class,
    ],
],

Typed Laravel Events

The SDK dispatches typed events for all 23 webhook event types:

EventClass
user.createdUserCreated
user.loginUserLogin
user.updatedUserUpdated
user.deletedUserDeleted
role.assignedRoleAssigned
role.removedRoleRemoved
role.createdRoleCreated
role.updatedRoleUpdated
role.deletedRoleDeleted
permission.grantedPermissionGranted
permission.revokedPermissionRevoked
connection.createdConnectionCreated
connection.refreshedConnectionRefreshed
connection.failedConnectionFailed
connection.revokedConnectionRevoked
consent.grantedConsentGranted
mfa.enabledMfaEnabled
mfa.disabledMfaDisabled
policy.createdPolicyCreated
policy.updatedPolicyUpdated
policy.deletedPolicyDeleted
attribute.setAttributeSet
attribute.deletedAttributeDeleted

All event classes are in the YorAuth\Laravel\Events namespace and contain a WebhookPayload $payload property.

A generic YorAuthWebhookReceived event is also dispatched for every webhook, regardless of type.

Artisan Commands

  • php artisan yorauth:test-connection -- Verify API connectivity and configuration
  • php artisan make:yorauth-listener {name} -- Scaffold a webhook event listener class

Further Reading