auth0 / auth0-php
PHP SDK for Auth0 Authentication and Management APIs.
Requires
Requires (Dev)
- ergebnis/composer-normalize: ^2
- friendsofphp/php-cs-fixer: ^3
- mockery/mockery: ^1
- pestphp/pest: ^2
- phpstan/phpstan: ^1
- phpstan/phpstan-strict-rules: ^1
- psr-mock/http: ^1
- rector/rector: 0.17.6
- spatie/ray: ^1
- symfony/cache: ^4 || ^5 || ^6
- symfony/event-dispatcher: ^4 || ^5 || ^6
- vimeo/psalm: ^5
- wikimedia/composer-merge-plugin: ^2
Suggests
- psr/cache-implementation: (PSR-6 Cache) Improve performance by avoiding making redundant network requests.
- psr/event-dispatcher-implementation: (PSR-14 Event Dispatcher) Observe and react to events when they occur.
- dev-main
- 8.11.1
- 8.11.0
- 8.10.0
- 8.9.3
- 8.9.1
- 8.9.0
- 8.8.0
- 8.7.1
- 8.7.0
- 8.6.0
- 8.5.0
- 8.4.0
- 8.3.8
- 8.3.7
- 8.3.6
- 8.3.5
- 8.3.4
- 8.3.3
- 8.3.2
- 8.3.1
- 8.3.0
- 8.2.1
- 8.2.0
- 8.1.0
- 8.0.6
- 8.0.5
- 8.0.4
- 8.0.3
- 8.0.2
- 8.0.1
- 8.0.0
- 8.0.0-BETA3
- 8.0.0-BETA2
- 8.0.0-BETA1
- 7.x-dev
- 7.9.2
- 7.9.1
- 7.9.0
- 7.8.0
- 7.7.0
- 7.6.2
- 7.6.1
- 7.6.0
- 7.5.0
- 7.4.0
- 7.3.0
- 7.2.0
- 7.1.0
- 7.0.0
- 6.0.0-alpha.2
- 6.0.0-alpha.1
- 5.7.0
- 5.6.0
- 5.5.1
- 5.5.0
- 5.4.0
- 5.3.2
- 5.3.1
- 5.3.0
- 5.2.0
- 5.1.1
- 5.1.0
- 5.0.6
- 5.0.5
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.0.13
- 4.0.12
- 4.0.11
- 4.0.10
- 4.0.9
- 4.0.8
- 4.0.7
- 4.0.6
- 4.0.5
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.7
- 3.3.6
- 3.3.5
- 3.3.4
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.1
- 3.0.0
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.0
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.6.8
- 0.6.7
- 0.6.6
- 0.6.5
- 0.6.4
- 0.6.3
- dev-release/8.12.0
- dev-feature/support-for-cyok
- dev-feature/adding_client_credentials
- dev-Add-Revrsing-Labs
This package is auto-updated.
Last update: 2024-11-05 13:14:57 UTC
README
PHP SDK for Auth0 Authentication and Management APIs.
📚 Documentation - 🚀 Getting Started - 💻 API Reference 💬 Feedback
Documentation
We also have tailored SDKs for Laravel, Symfony, and WordPress. If you are using one of these frameworks, use the tailored SDK for the best integration experience.
- Quickstarts
- Application using Sessions (Stateful) — Demonstrates a traditional web application that uses sessions and supports logging in, logging out, and querying user profiles. The completed source code is also available.
- API using Access Tokens (Stateless) — Demonstrates a backend API that authorizes endpoints using access tokens provided by a frontend client and returns JSON. The completed source code is also available.
- PHP Examples — Code samples for common scenarios.
- Documentation Hub — Learn more about integrating Auth0 with your application.
Getting Started
Requirements
- PHP 8.1+
- Composer
- PHP Extensions:
- Dependencies:
Please review our support policy for details on our PHP version support.
Installation
Ensure you have the necessary dependencies installed, then add the SDK to your application using Composer:
composer require auth0/auth0-php --no-dev
Configure Auth0
Create a Regular Web Application in the Auth0 Dashboard. Verify that the "Token Endpoint Authentication Method" is set to POST
.
Next, configure the callback and logout URLs for your application under the "Application URIs" section of the "Settings" page:
- Allowed Callback URLs: The URL of your application where Auth0 will redirect to during authentication, e.g.,
http://localhost:3000/callback
. - Allowed Logout URLs: The URL of your application where Auth0 will redirect to after user logout, e.g.,
http://localhost:3000/login
.
Note the Domain, Client ID, and Client Secret. These values will be used later.
Add login to your application
Create a SdkConfiguration
instance configured with your Auth0 domain and Auth0 application client ID and secret. Generate a sufficiently long, random string for your cookieSecret
using openssl rand -hex 32
. Create a new Auth0
instance and pass your configuration to it.
use Auth0\SDK\Auth0; use Auth0\SDK\Configuration\SdkConfiguration; $configuration = new SdkConfiguration( domain: 'Your Auth0 domain', clientId: 'Your Auth0 application client ID', clientSecret: 'Your Auth0 application client secret', cookieSecret: 'Your generated string', ); $auth0 = new Auth0($configuration);
Use the getCredentials()
method to check if a user is authenticated.
// getCredentials() returns null if the user is not authenticated. $session = $auth0->getCredentials(); if (null === $session || $session->accessTokenExpired) { // Redirect to Auth0 to authenticate the user. header('Location: ' . $auth0->login()); exit; }
Complete the authentication flow and obtain the tokens by calling exchange()
:
if (null !== $auth0->getExchangeParameters()) { $auth0->exchange(); }
Finally, you can use getCredentials()?->user
to retrieve information about our authenticated user:
print_r($auth0->getCredentials()?->user);
That's it! You have successfully authenticated your first user with Auth0! From here, you may want to try following along with one of our quickstarts or browse through our examples for additional insight and guidance.
If you have questions, the Auth0 Community is a fantastic resource to ask questions and get help.
Input from Untrusted Sources
If your application accepts input from untrusted sources (such as query parameters from HTTP requests) please ensure you are following best practices for data validation and sanitization. It is your application's responsibility to ensure any data provided to the SDK is valid and safe. For more information, see the OWASP Data Validation Cheat Sheet.
API Reference
Support Policy
Our support lifecycle mirrors the PHP release support schedule.
We drop support for PHP versions when they reach end-of-life and cease receiving security fixes from the PHP Foundation. Please ensure your environment remains up to date so you can continue receiving updates for PHP and this SDK.
Feedback
Contributing
We appreciate feedback and contribution to this repo! Before you get started, please see the following:
Raise an issue
To provide feedback or report a bug, please raise an issue on our issue tracker.
Vulnerability Reporting
Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
Auth0 is an easy-to-implement, adaptable authentication and authorization platform.
To learn more, check out "Why Auth0?"
This project is licensed under the MIT license. See the LICENSE file for more info.