Auth0\SDK\Auth0
, Auth0\SDK\API\Authentication
and Auth0\SDK\API\Management
, each offering interfaces for different functionality across Auth0’s APIs. If you’re building a stateful web application that needs to keep track of users’ sessions, the base Auth0
class is what you’ll be working with the most. It provides methods for handling common authentication and session handling tasks such as logging in and out, retrieving user credentials, checking of an available session, and callback handling. These tasks are explained below.
For additional information on these capabilities and more, please see the documentation page for the Authentication API.
Prerequisites
The documentation below assumes that you followed the steps in the Auth0-PHP, and continue off from the code provided there.Logging In
The default login process in the PHP SDK uses an Authentication Code grant combined with Auth0’s Page. In short, that process is:- A user requesting access is redirected to the Universal Login Page.
- The user authenticates using one of many possible connections: social (Google, X, Facebook), database (email and password), passwordless (email, SMS), or enterprise (ActiveDirectory, ADFS, Office 365).
- The user is redirected or posted back to your application’s callback URL with
code
andstate
values if successful or anerror
anderror_description
if not. - If the authentication was successful, the
state
value is validated. - If the
state
is valid, thecode
value is exchanged with Auth0 for an ID Token and/or an Access Token. - The identity from the ID token can be used to create an account, to start an application-specific session, or to persist as the user session.
- Call
Auth0\SDK\Auth0::login()
when users need to login (for example: click a link, visit walled content, etc.) - Call
Auth0\SDK\Auth0::exchange()
when users are redirected to your callback URL. - Call
Auth0\SDK\Auth0::getCredentials()
when you need to check if a user is logged in and retrieve user information.
- Immediately redirect you to an Auth0 login page for your tenant.
- After successfully logging in using any connection, redirect you back to your app.
- Display a simple page showing ‘Authenticated!’.