Auth0 enables you to rapidly integrate authentication and authorization for your applications, so you can focus on your core business. (Learn more)
Our PHP SDK provides a straight-forward and rigorously tested interface for accessing Auth0's Authentication and Management API endpoints through modern releases of PHP.
This is one of many libraries we offer supporting numerous platforms.
- Documentation
- Quickstarts
The recommended way to install the SDK is through Composer:
$ composer require auth0/auth0-php
Guidance on setting up Composer and alternative installation methods can be found in our documentation.
To get started, you'll need to create a free Auth0 account and register an Application.
Begin by instantiating the SDK and passing the relevant details from your Application's settings page:
use Auth0\SDK\Auth0;
$auth0 = new Auth0([
// The values below are found on the Application settings tab.
'domain' => '{YOUR_TENANT}.auth0.com',
'client_id' => '{YOUR_APPLICATION_CLIENT_ID}',
'client_secret' => '{YOUR_APPLICATION_CLIENT_SECRET}',
// This is your application URL that will be used to process the login.
// Save this URL in the "Allowed Callback URLs" field on the Application settings tab
'redirect_uri' => 'https://{YOUR_APPLICATION_CALLBACK_URL}',
]);
Note: In a production application you should never hardcode these values. Consider using environment variables to store and pass these values to your application, as suggested in our documentation.
Using the SDK, making requests to Auth0's endpoints couldn't be simpler. For example, signing users in using Auth0's Universal Login and retrieving user details can be done in a few lines of code:
// Do we have an authenticated session available?
if ($userinfo = $auth0->getUser()) {
// Output the authenticated user
var_dump($userinfo);
exit;
}
// No session was available, so redirect to Universal Login page
$auth0->login();
Further examples of how you can use the Authentication API Client can be found on our documentation site.
This SDK also offers an interface for Auth0's Management API which, in order to access, requires an Access Token that is issued specifically for your tenant's Management API by specifying the corresponding Audience.
The process for retrieving such an Access Token is described in our documentation.
use Auth0\SDK\API\Management;
$mgmt_api = new Management('{{YOUR_ACCESS_TOKEN}}', 'https://{{YOUR_TENANT}}.auth0.com');
The SDK provides convenient interfaces to the Management API's endpoints. For example, to search for users:
$results = $mgmt_api->users()->getAll([
'q' => 'josh'
]);
if (! empty($results)) {
echo '<h2>User Search</h2>';
foreach ($results as $datum) {
printf(
'<p><strong>%s</strong> <%s> - %s</p>',
!empty($datum['nickname']) ? $datum['nickname'] : 'No nickname',
!empty($datum['email']) ? $datum['email'] : 'No email',
$datum['user_id']
);
}
}
At the moment the best way to see what endpoints are covered is to read through the \Auth0\SDK\API\Management
class, available here.
We appreciate your feedback and contributions to the project! Before you get started, please review the following:
- Auth0's general contribution guidelines
- Auth0's code of conduct guidelines
- The Auth0 PHP SDK contribution guide
- The Auth0 Community is a valuable resource for asking questions and finding answers, staffed by the Auth0 team and a community of enthusiastic developers
- For code-level support (such as feature requests and bug reports) we encourage you to open issues here on our repo
- For customers on paid plans, our support center is available for opening tickets with our knowledgeable support specialists
Further details about our support solutions are available on our website.
Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
Auth0 helps you to:
- Add authentication with multiple authentication sources, either social like Google, Facebook, Microsoft, LinkedIn, GitHub, Twitter, Box, Salesforce (amongst others), or enterprise identity systems like Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider.
- Add authentication through more traditional username/password databases.
- Add support for passwordless and multi-factor authentication.
- Add support for linking different user accounts with the same user.
- Analytics of how, when and where users are logging in.
- Pull data from other sources and add it to the user profile, through JavaScript rules.
The Auth0 PHP SDK is open source software licensed under the MIT license. See the LICENSE file for more info.