Sample Project

Before you start

This guide walks you through setting up authentication and authorization in your PHP apps with Auth0. If you are new to Auth0 we suggest you check our Overview. For a complete picture of authentication and authorization for regular web apps, check our Single Sign-On for Regular Web Apps documentation.

Get Your Application Keys

You will need some details about this application to communicate with Auth0. You can get them from the Application Settings in the Auth0 dashboard.

You need the following information:

Client ID

Domain

If you download the sample from the top of this page, these details are filled out for you. If you have more than one application in your account, the sample comes with the values for your Default App.

Configure Callback URLs

A callback URL is a URL in your application where Auth0 redirects the user after they have authenticated.

You need to whitelist the callback URL for your app in the Allowed Callback URLs field in your Application Settings. If you do not set any callback URL, your users will see a mismatch error when they log in.

If you are following along with the sample project you downloaded from the top of this page, Callback URL should be set to
http://localhost:3000/.

Add the Dependencies

To install dependencies, run the following

composer require auth0/auth0-php:"~5.0"

Did it help?/

This sample uses Composer, a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs. Then, it installs them in your project.

To learn about all the available properties from the user's profile, read the user profile documentation.

Some of the user profile properties depend on the social provider you use.

Optional: Configure session data

By default, the SDK stores user information in the PHP session and discards the access and ID Tokens.

To keep the tokens, to the SDK configuration, pass the following:

'persist_access_token' => true

'persist_id_token' => true

To disable the session, pass 'store' => false to the SDK configuration.

Instead of using the PHP session to store information, you can use Laravel, Zend, Symfony or similar techniques. To do that, create a class that implements the get, set and delete methods and pass it to the SDK.