Docs

Auth0-PHP

The Auth0 PHP SDK provides you with methods for accessing Auth0's Authentication and Management API endpoints.

The Auth0-PHP repository is hosted on GitHub. We appreciate all contributions, including bug reports, enhancement proposals, and pull requests.

Requirements

Installation

Auth0-PHP can be installed one of two ways:

  1. With Composer
  2. Manually

Install With Composer

We recommend installing the SDK with Composer. If you already have Composer installed globally, run the following:

Otherwise, download Composer locally and run:

This will create composer.json and composer.lock files in the directory where the command was run, along with a vendor folder containing this SDK and its dependencies.

Finally, include the Composer autoload file in your project to use the SDK:

Install Manually

If your project does not use Composer or you want to maintain a connection to the Git repo, Auth0-PHP can be installed manually. This process still requires Composer to download dependencies, but the process does not use Composer to manage the package.

First, navigate to the directory that contains the Auth0-PHP library and clone the Github repo:

Download Composer and install the dependencies:

Finally, require the Auth0-PHP autoloader and you're ready to use the SDK:

Getting Started

To use the Auth0 Authentication and Management APIs, you'll need a free Auth0 account and an Application:

  1. Go to auth0.com/signup and create your account.
  2. Once you are in the dashboard, go to Applications, then Create Application.
  3. Give your Application a name, select Regular Web Application, then Create
  4. Click the Settings tab for the required credentials used below. More information about these settings is here.

The examples in this documentation use environment variables to store and load sensitive Auth0 credentials, eliminating the need for you to hardcode them into your application.

The easiest way to use environment variables in your project is to use a library like PHP Dotenv along with a local .env file. Create a .env file (make sure this is not accessible publicly and is excluded from version control) and add the following values:

The AUTH0_REDIRECT_URI value above is a URL for your application that will handle the callback from Auth0. This is used for both successful logins as well as errors. The processing that happens at this URL is covered later in this documentation.

In your application (below the Composer autoload require), add:

You can now use the environment variables to instantiate the necessary Auth0-PHP classes:

You are now ready to use Auth0-PHP. Use one of the articles below to add authentication to your existing app or one of our quickstarts to build a test application from scratch:

Read more