├── .github ├── CODEOWNERS └── workflows │ └── ci.yml ├── .gitignore ├── LICENSE ├── README.md ├── bin └── restore-cache-and-update-deps ├── composer.json ├── config └── workos.php ├── lib ├── Version.php └── WorkOSServiceProvider.php ├── phpunit.xml └── tests ├── LaravelTestCase.php ├── WorkOS └── WorkOSServiceProviderTest.php └── bootstrap.php /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # See GitHub's docs for more details: 2 | # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners 3 | 4 | * @workos/php 5 | -------------------------------------------------------------------------------- /.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'] 21 | laravel: ['7.*', '8.*', '9.*', '10.*'] 22 | steps: 23 | - uses: actions/checkout@v4 24 | - name: Setup PHP 25 | uses: shivammathur/setup-php@9e72090525849c5e82e596468b86eb55e9cc5401 # v2.32.0 26 | with: 27 | php-version: ${{ matrix.php }} 28 | extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv 29 | tools: composer 30 | coverage: none 31 | 32 | - name: Run composer install 33 | run: | 34 | composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update 35 | composer update --no-interaction --no-suggest --prefer-dist 36 | 37 | - name: Lint and formatting 38 | run: | 39 | composer run-script format-check 40 | 41 | - name: Run tests 42 | run: | 43 | composer run-script test 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .phpunit.result.cache 2 | 3 | composer.lock 4 | vendor/ 5 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | For Laravel 5.0-5.4, add the WorkOS ServiceProvider in your `config/app.php`: 18 | 19 | ```php 20 | "providers" => array( 21 | // ... 22 | WorkOS\Laravel\WorkOSServiceProvider::class 23 | ) 24 | ``` 25 | 26 | For Laravel 5.5 and up, 6.x and 7.x... you're all set! 27 | 28 | ## Configuration 29 | 30 | Create a WorkOS configuration file by running the following: 31 | 32 | ```bash 33 | php artisan vendor:publish --provider="WorkOS\Laravel\WorkOSServiceProvider" 34 | ``` 35 | 36 | 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). 37 | By default, the package will look for a `WORKOS_API_KEY` and `WORKOS_CLIENT_ID` environment variable. 38 | 39 | ## SDK Versioning 40 | 41 | 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. 42 | 43 | ## Beta Releases 44 | 45 | WorkOS has features in Beta that can be accessed via Beta releases. We would love for you to try these 46 | and share feedback with us before these features reach general availability (GA). To install a Beta version, 47 | please follow the [installation steps](#installation) above using the Beta release version. 48 | 49 | > Note: there can be breaking changes between Beta versions. Therefore, we recommend pinning the package version to a 50 | > specific version. This way you can install the same version each time without breaking changes unless you are 51 | > intentionally looking for the latest Beta version. 52 | 53 | We highly recommend keeping an eye on when the Beta feature you are interested in goes from Beta to stable so that you 54 | can move to using the stable version. 55 | 56 | ## More Information 57 | 58 | * [Single Sign-On Guide](https://workos.com/docs/sso/guide) 59 | * [Directory Sync Guide](https://workos.com/docs/directory-sync/guide) 60 | * [Admin Portal Guide](https://workos.com/docs/admin-portal/guide) 61 | * [Magic Link Guide](https://workos.com/docs/magic-link/guide) 62 | -------------------------------------------------------------------------------- /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 | "5") 11 | echo "5...ish" 12 | laravel_version="^5.8" 13 | echo "Install desired Laravel version then update everything" 14 | composer require laravel/framework=${laravel_version} 15 | composer u 16 | ;; 17 | 18 | "6") 19 | echo "6...ish" 20 | laravel_version="^6.18" 21 | echo "Install desired Laravel version then update everything" 22 | composer require laravel/framework=${laravel_version} 23 | composer u 24 | ;; 25 | 26 | "7") 27 | echo "7...ish" 28 | laravel_version="^7.5" 29 | echo "Install desired Laravel version then update everything" 30 | composer require laravel/framework=${laravel_version} 31 | composer u 32 | ;; 33 | 34 | "8") 35 | echo "8" 36 | laravel_version="^8.76.2" 37 | echo "Install desired Laravel version then update everything" 38 | composer require laravel/framework=${laravel_version} 39 | composer u 40 | ;; 41 | 42 | "9") 43 | echo "9" 44 | laravel_version="^9.52.7" 45 | echo "install composer" 46 | if [[ ! `command -v composer 2>/dev/null` ]] 47 | then 48 | php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 49 | php composer-setup.php 50 | php -r "unlink('composer-setup.php');" 51 | php composer.phar require laravel/framework=${laravel_version} 52 | php composer.phar update --no-scripts 53 | else 54 | composer u 55 | fi 56 | ;; 57 | 58 | "10") 59 | echo "10" 60 | laravel_version="^10.0.0" 61 | echo "install composer" 62 | if [[ ! `command -v composer 2>/dev/null` ]] 63 | then 64 | php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 65 | php composer-setup.php 66 | php -r "unlink('composer-setup.php');" 67 | php composer.phar require laravel/framework=${laravel_version} 68 | php composer.phar update --no-scripts 69 | else 70 | composer u 71 | fi 72 | ;; 73 | 74 | *) 75 | printf "\nError: Specify either 5, 6, 7, 8, 9, or 10 for Laravel version\n" 76 | exit 1 77 | ;; 78 | esac 79 | 80 | echo "Attempt to store cache in case of an initial miss" 81 | cache store $KEY ./vendor 82 | 83 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workos/workos-php-laravel", 3 | "description": "WorkOS PHP Library for Laravel", 4 | "keywords": [ 5 | "laravel", 6 | "laravel 5", 7 | "laravel 6", 8 | "laravel 7", 9 | "laravel 8", 10 | "laravel 9", 11 | "laravel 10", 12 | "workos", 13 | "sdk", 14 | "sso" 15 | ], 16 | "license": "MIT", 17 | "authors": [ 18 | { 19 | "name": "WorkOS", 20 | "email": "support@workos.com" 21 | } 22 | ], 23 | "require": { 24 | "php": ">=5.6.0", 25 | "workos/workos-php": "^v4.24.0" 26 | }, 27 | "require-dev": { 28 | "friendsofphp/php-cs-fixer": "^2.15 || ^3.6", 29 | "phpunit/phpunit": "^5.7 || ^10.1" 30 | }, 31 | "suggest": { 32 | "laravel/framework": "For testing" 33 | }, 34 | "autoload": { 35 | "psr-4": { 36 | "WorkOS\\Laravel\\": "lib/" 37 | } 38 | }, 39 | "autoload-dev": { 40 | "psr-4": { 41 | "WORKOS\\Laravel\\": [ 42 | "tests/", 43 | "tests/WorkOS" 44 | ] 45 | } 46 | }, 47 | "extra": { 48 | "laravel": { 49 | "providers": [ 50 | "WorkOS\\Laravel\\WorkOSServiceProvider" 51 | ] 52 | } 53 | }, 54 | "scripts": { 55 | "clean": "rm -rf composer.lock vendor/", 56 | "format": "php vendor/bin/php-cs-fixer fix -v --using-cache=no .", 57 | "format-check": "php vendor/bin/php-cs-fixer fix -v --dry-run --using-cache=no .", 58 | "test": "php vendor/bin/phpunit tests" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/Version.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 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tests 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/bootstrap.php: -------------------------------------------------------------------------------- 1 |