├── .gitignore ├── tests ├── bootstrap.php ├── WorkOS │ └── WorkOSServiceProviderTest.php └── LaravelTestCase.php ├── .github ├── CODEOWNERS └── workflows │ └── ci.yml ├── lib ├── Version.php └── WorkOSServiceProvider.php ├── phpunit.xml ├── config └── workos.php ├── LICENSE ├── composer.json ├── bin └── restore-cache-and-update-deps └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .phpunit.result.cache 2 | 3 | composer.lock 4 | vendor/ 5 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tests 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /config/workos.php: -------------------------------------------------------------------------------- 1 | env("WORKOS_API_KEY"), 6 | 7 | // WorkOS Client ID 8 | "client_id" => env("WORKOS_CLIENT_ID"), 9 | 10 | // WorkOS base API URL 11 | "api_base_url" => null 12 | ]; 13 | -------------------------------------------------------------------------------- /tests/WorkOS/WorkOSServiceProviderTest.php: -------------------------------------------------------------------------------- 1 | app = $this->setupApplication(); 12 | } 13 | 14 | public function testRegisterWorkOSServiceProviderYieldsExpectedConfig() 15 | { 16 | $this->app["config"]->set("workos.api_key", "pk_secretsauce"); 17 | $this->app["config"]->set("workos.client_id", "client_pizza"); 18 | $this->app["config"]->set("workos.api_base_url", "https://workos-hop.com/"); 19 | $this->setupProvider($this->app); 20 | 21 | $this->assertEquals("pk_secretsauce", \WorkOS\WorkOS::getApiKey()); 22 | $this->assertEquals("client_pizza", \WorkOS\WorkOS::getClientId()); 23 | $this->assertEquals("https://workos-hop.com/", \WorkOS\WorkOS::getApiBaseUrl()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/LaravelTestCase.php: -------------------------------------------------------------------------------- 1 | setBasePath(sys_get_temp_dir()); 22 | $app->instance("config", new Repository()); 23 | 24 | return $app; 25 | } 26 | 27 | /** 28 | * Setup WorkOS Service Providers 29 | */ 30 | protected function setupProvider($app) 31 | { 32 | $provider = new WorkOSServiceProvider($app); 33 | $app->register($provider); 34 | $provider->boot(); 35 | 36 | return $provider; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 WorkOS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/WorkOSServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->runningInConsole()) { 18 | $this->publishes( 19 | [__DIR__."/../config/workos.php" => config_path("workos.php")] 20 | ); 21 | } 22 | } 23 | 24 | /** 25 | * Register the ServiceProvider as well as setup WorkOS. 26 | */ 27 | public function register() 28 | { 29 | $this->mergeConfigFrom(__DIR__."/../config/workos.php", "workos"); 30 | 31 | $config = $this->app["config"]->get("workos"); 32 | \WorkOS\WorkOS::setApiKey($config["api_key"]); 33 | \WorkOS\WorkOS::setClientId($config["client_id"]); 34 | \WorkOS\WorkOS::setIdentifier(\WorkOS\Laravel\Version::SDK_IDENTIFIER); 35 | \WorkOS\WorkOS::setVersion(\WorkOS\Laravel\Version::SDK_VERSION); 36 | 37 | if ($config["api_base_url"]) { 38 | \WorkOS\WorkOS::setApiBaseUrl($config["api_base_url"]); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workos/workos-php-laravel", 3 | "description": "WorkOS PHP Library for Laravel", 4 | "keywords": [ 5 | "laravel", 6 | "laravel 10", 7 | "laravel 11", 8 | "laravel 12", 9 | "workos", 10 | "sdk", 11 | "sso" 12 | ], 13 | "license": "MIT", 14 | "authors": [ 15 | { 16 | "name": "WorkOS", 17 | "email": "support@workos.com" 18 | } 19 | ], 20 | "require": { 21 | "php": ">=8.1.0", 22 | "workos/workos-php": "^v4.29.0" 23 | }, 24 | "require-dev": { 25 | "friendsofphp/php-cs-fixer": "^2.15 || ^3.6", 26 | "phpunit/phpunit": "^5.7 || ^10.1" 27 | }, 28 | "suggest": { 29 | "laravel/framework": "For testing" 30 | }, 31 | "autoload": { 32 | "psr-4": { 33 | "WorkOS\\Laravel\\": "lib/" 34 | } 35 | }, 36 | "autoload-dev": { 37 | "psr-4": { 38 | "WORKOS\\Laravel\\": [ 39 | "tests/", 40 | "tests/WorkOS" 41 | ] 42 | } 43 | }, 44 | "extra": { 45 | "laravel": { 46 | "providers": [ 47 | "WorkOS\\Laravel\\WorkOSServiceProvider" 48 | ] 49 | } 50 | }, 51 | "scripts": { 52 | "clean": "rm -rf composer.lock vendor/", 53 | "format": "php vendor/bin/php-cs-fixer fix -v --using-cache=no .", 54 | "format-check": "php vendor/bin/php-cs-fixer fix -v --dry-run --using-cache=no .", 55 | "test": "php vendor/bin/phpunit tests" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'main' 7 | pull_request: {} 8 | 9 | defaults: 10 | run: 11 | shell: bash 12 | 13 | jobs: 14 | test: 15 | name: Test PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }} 16 | runs-on: ubuntu-latest 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | php: ['8.1', '8.2', '8.3', '8.4'] 21 | laravel: ['10.*', '11.*', '12.*'] 22 | exclude: 23 | - php: '8.1' 24 | laravel: '11.*' 25 | - php: '8.1' 26 | laravel: '12.*' 27 | steps: 28 | - uses: actions/checkout@v4 29 | - name: Setup PHP 30 | uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0 31 | with: 32 | php-version: ${{ matrix.php }} 33 | extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv 34 | tools: composer 35 | coverage: none 36 | 37 | - name: Run composer install 38 | run: | 39 | composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update 40 | composer update --no-interaction --no-suggest --prefer-dist 41 | 42 | - name: Lint and formatting 43 | run: | 44 | composer run-script format-check 45 | 46 | - name: Run tests 47 | run: | 48 | composer run-script test 49 | -------------------------------------------------------------------------------- /bin/restore-cache-and-update-deps: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | KEY="composer-laravel-${1}-$(checksum composer.json)" 4 | 5 | echo "Get that cache" 6 | cache restore $KEY 7 | 8 | echo -n "Setting desired Laravel version to " 9 | case ${1} in 10 | "10") 11 | echo "10" 12 | laravel_version="^10.0.0" 13 | echo "install composer" 14 | if [[ ! `command -v composer 2>/dev/null` ]] 15 | then 16 | php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 17 | php composer-setup.php 18 | php -r "unlink('composer-setup.php');" 19 | php composer.phar require laravel/framework=${laravel_version} 20 | php composer.phar update --no-scripts 21 | else 22 | composer u 23 | fi 24 | ;; 25 | "11") 26 | echo "11" 27 | laravel_version="^11.0.0" 28 | echo "install composer" 29 | if [[ ! `command -v composer 2>/dev/null` ]] 30 | then 31 | php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 32 | php composer-setup.php 33 | php -r "unlink('composer-setup.php');" 34 | php composer.phar require laravel/framework=${laravel_version} 35 | php composer.phar update --no-scripts 36 | else 37 | composer u 38 | fi 39 | ;; 40 | "12") 41 | echo "12" 42 | laravel_version="^12.0.0" 43 | echo "install composer" 44 | if [[ ! `command -v composer 2>/dev/null` ]] 45 | then 46 | php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 47 | php composer-setup.php 48 | php -r "unlink('composer-setup.php');" 49 | php composer.phar require laravel/framework=${laravel_version} 50 | php composer.phar update --no-scripts 51 | else 52 | composer u 53 | fi 54 | ;; 55 | 56 | *) 57 | printf "\nError: Specify 10, 11, or 12 for Laravel version\n" 58 | exit 1 59 | ;; 60 | esac 61 | 62 | echo "Attempt to store cache in case of an initial miss" 63 | cache store $KEY ./vendor 64 | 65 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WorkOS PHP Laravel Library 2 | 3 | The WorkOS library for Laravel provides convenient access to the WorkOS API from applications written in Laravel. 4 | 5 | ## Documentation 6 | 7 | See the [API Reference](https://workos.com/docs/reference/client-libraries) for Laravel usage examples. 8 | 9 | ## Installation 10 | 11 | To install via composer, run the following: 12 | 13 | ```bash 14 | composer require workos/workos-php-laravel 15 | ``` 16 | 17 | ## Configuration 18 | 19 | Create a WorkOS configuration file by running the following: 20 | 21 | ```bash 22 | php artisan vendor:publish --provider="WorkOS\Laravel\WorkOSServiceProvider" 23 | ``` 24 | 25 | The package will need to be configured with your [api key](https://dashboard.workos.com/api-keys) and [project id](https://dashboard.workos.com/sso/configuration). 26 | By default, the package will look for a `WORKOS_API_KEY` and `WORKOS_CLIENT_ID` environment variable. 27 | 28 | ## SDK Versioning 29 | 30 | For our SDKs WorkOS follows a Semantic Versioning ([SemVer](https://semver.org/)) process where all releases will have a version X.Y.Z (like 1.0.0) pattern wherein Z would be a bug fix (e.g., 1.0.1), Y would be a minor release (1.1.0) and X would be a major release (2.0.0). We permit any breaking changes to only be released in major versions and strongly recommend reading changelogs before making any major version upgrades. 31 | 32 | ## Beta Releases 33 | 34 | WorkOS has features in Beta that can be accessed via Beta releases. We would love for you to try these 35 | and share feedback with us before these features reach general availability (GA). To install a Beta version, 36 | please follow the [installation steps](#installation) above using the Beta release version. 37 | 38 | > Note: there can be breaking changes between Beta versions. Therefore, we recommend pinning the package version to a 39 | > specific version. This way you can install the same version each time without breaking changes unless you are 40 | > intentionally looking for the latest Beta version. 41 | 42 | We highly recommend keeping an eye on when the Beta feature you are interested in goes from Beta to stable so that you 43 | can move to using the stable version. 44 | 45 | ## More Information 46 | 47 | * [Single Sign-On Guide](https://workos.com/docs/sso/guide) 48 | * [Directory Sync Guide](https://workos.com/docs/directory-sync/guide) 49 | * [Admin Portal Guide](https://workos.com/docs/admin-portal/guide) 50 | * [Magic Link Guide](https://workos.com/docs/magic-link/guide) 51 | --------------------------------------------------------------------------------