Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bearbytestudio's avatar

WorkOS integration

Had anyone extended the WorkOS integration beyond the basic scaffold that the new WorkOS integration that Laravel provides? How did you fetch user roles and permissions etc?

Separately, has anyone successfully integrated WorkOS with Wordpress? And how?

Thanks!!

0 likes
1 reply
LaryAI's avatar
Level 58

To extend the WorkOS integration in a Laravel application beyond the basic scaffold, you can follow these steps to fetch user roles and permissions:

  1. Set Up WorkOS SDK: Ensure you have the WorkOS SDK installed and configured in your Laravel application. You can do this via Composer:

    composer require workos/workos-php
    
  2. Configure WorkOS: Set up your environment variables in the .env file with your WorkOS API key and other necessary configurations:

    WORKOS_API_KEY=your_api_key
    WORKOS_CLIENT_ID=your_client_id
    
  3. Fetch User Roles and Permissions: You can use the WorkOS SDK to fetch user roles and permissions. Here’s a basic example of how you might do this:

    use WorkOS\WorkOS;
    use WorkOS\SSO;
    
    WorkOS::setApiKey(env('WORKOS_API_KEY'));
    
    $sso = new SSO();
    
    // Assuming you have a user ID or email to fetch roles and permissions
    $userId = 'user_id_or_email';
    
    // Fetch user details
    $user = $sso->getUser($userId);
    
    // Access roles and permissions
    $roles = $user->roles;
    $permissions = $user->permissions;
    
    // Example output
    foreach ($roles as $role) {
        echo "Role: " . $role->name . "\n";
    }
    
    foreach ($permissions as $permission) {
        echo "Permission: " . $permission->name . "\n";
    }
    
  4. Integrate with Laravel: You can create a service class or a controller to handle the fetching of roles and permissions, and then use this in your application wherever needed.

Regarding the integration of WorkOS with WordPress, the process would be different as WordPress is not a PHP framework like Laravel. However, you can achieve this by:

  1. Using a Custom Plugin: Create a custom WordPress plugin that uses the WorkOS PHP SDK to handle authentication and fetch user roles and permissions.

  2. WordPress Hooks: Utilize WordPress hooks and filters to integrate WorkOS authentication into the WordPress login process.

  3. REST API: If your WordPress site uses a REST API, you can create endpoints that interact with WorkOS to manage user roles and permissions.

Unfortunately, there isn't a direct, out-of-the-box solution for WordPress as there is for Laravel, so custom development will be necessary.

If you need more specific guidance on any of these steps, feel free to ask!

Please or to participate in this conversation.