Giter Club home page Giter Club logo

auth0-php's Introduction

auth0-php

PHP SDK for Auth0 Authentication and Management APIs.

Package Build Coverage License

๐Ÿ“š Documentation - ๐Ÿš€ Getting Started - ๐Ÿ’ป API Reference ๐Ÿ’ฌ Feedback

Documentation

  • Stateful Applications
    • Quickstart โ€” add login, logout and user information to a PHP application using Auth0.
    • Sample Application โ€” a sample PHP web application integrated with Auth0.
  • Stateless Applications
    • Quickstart โ€” add access token handling and route authorization to a backend PHP application using Auth0.
    • Sample Application โ€” a sample PHP backend application integrated with Auth0.
  • Examples โ€” code samples for common scenarios.
  • Docs site โ€” explore our docs site and learn more about Auth0.

Getting Started

Requirements

PHP 8.0 or above. Your application will also need PSR-17 (HTTP factory) and PSR-18 (HTTP client) compatible libraries installed.

This library follows the PHP release support schedule. We do not support PHP versions that have reached end of life and no longer receive security updates.

Installation

Add the dependency to your application with Composer:

composer require auth0/auth0-php

Configure Auth0

Create a Regular Web Application in the Auth0 Dashboard. Verify that the "Token Endpoint Authentication Method" is set to POST.

Next, configure the callback and logout URLs for your application under the "Application URIs" section of the "Settings" page:

  • Allowed Callback URLs: The URL of your application where Auth0 will redirect to during authentication, e.g., http://localhost:3000/callback.
  • Allowed Logout URLs: The URL of your application where Auth0 will redirect to after user logout, e.g., http://localhost:3000/login.

Note the Domain, Client ID, and Client Secret. These values will be used later.

Add login to your application

Create a SdkConfiguration instance configured with your Auth0 domain and Auth0 application client ID and secret. Generate a sufficiently long, random string for your cookieSecret using openssl rand -hex 32. Create a new Auth0 instance and pass your configuration to it.

use Auth0\SDK\Auth0;
use Auth0\SDK\Configuration\SdkConfiguration;

$configuration = new SdkConfiguration(
    domain: 'Your Auth0 domain',
    clientId: 'Your Auth0 application client ID',
    clientSecret: 'Your Auth0 application client secret',
    cookieSecret: 'Your generated string',
);

$auth0 = new Auth0($configuration);

Use getCredentials() to check if a user is signed in. Redirect guests to sign in using the Auth0 login page with login():

$session = $auth0->getCredentials();

if (null === $session || $session->accessTokenExpired) {
    header('Location: ' . $auth0->login());
    exit;
}

Complete the authentication and obtain the tokens by calling exchange():

if (null !== $auth0->getExchangeParameters()) {
    $auth0->exchange();
}

Use getUser() to retrieve information about our authenticated user:

print_r($auth0->getUser());

That's it! You have authenticated the user with Auth0. More examples can be found in EXAMPLES.md.

API Reference

Feedback

Contributing

We appreciate feedback and contribution to this repo! Before you get started, please see the following:

Raise an issue

To provide feedback or report a bug, please raise an issue on our issue tracker.

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.


Auth0 Logo

Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?

This project is licensed under the MIT license. See the LICENSE file for more info.

auth0-php's People

Contributors

abbaspour avatar annyv2 avatar b-galati avatar cocojoe avatar crecket avatar damieng avatar darkyen avatar deboorn avatar evansims avatar frederikprijck avatar glena avatar hrajchert avatar jimmyjames avatar joshcanhelp avatar jrfnl avatar jspetrak avatar kler avatar lbalmaceda avatar mgonto avatar ntotten avatar nyholm avatar pinodex avatar remuslazar avatar ring avatar robinvdvleuten avatar sepiariver avatar siacomuzzi avatar udf2457 avatar vmartynets avatar widcket avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.