Skip to content

auth0/auth0-PHP

Repository files navigation

Build Status Total Downloads Latest Stable Version PHP Support Code Coverage License FOSSA

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

Installation

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.

Getting Started

To get started, you'll need to create a free Auth0 account and register an Application.

Authentication API Client

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.

Management API Client

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> &lt;%s&gt; - %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.

Contributing

We appreciate your feedback and contributions to the project! Before you get started, please review the following:

Support + Feedback

  • 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.

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.

What is Auth0?

Auth0 helps you to:

Why Auth0?

License

The Auth0 PHP SDK is open source software licensed under the MIT license. See the LICENSE file for more info.

FOSSA Status