auth0/auth0-PHP

Name: auth0-PHP

Owner: Auth0

Description: Auth0-PHP SDK

Created: 2013-10-18 16:51:11.0

Updated: 2018-01-11 08:18:14.0

Pushed: 2017-12-28 11:11:37.0

Homepage: null

Size: 559

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Auth0 PHP SDK

Latest Stable Version Build Status Code Climate Test Coverage Dependencies HHVM Status License Total Downloads

Installation

Installing via composer

mposer require auth0/auth0-php

Check our docs page to get a complete guide on how to install it in an existing project or download a pre configured seedproject:

If you find something wrong in our docs, PR are welcome in our docs repo: https://github.com/auth0/docs

Getting started
Decoding and verifying tokens
S256 tokens
Auth0\SDK\JWTVerifier;

ifier = new JWTVerifier([
'valid_audiences' => [$client_id],
'client_secret' => $client_secret


oded = $verifier->verifyAndDecode($jwt);

S256 tokens
ifier = new JWTVerifier([
'supported_algs' => ['RS256'],
'valid_audiences' => [$client_id],
'authorized_iss' => ["https://$domain/"] // the issues will look like https://your_account[.region].auth0.com/ (being region an optional segment only present for eu and au accounts.


oded = $verifier->verifyAndDecode($jwt);

Accepted params:

Oauth2 authentication
ire __DIR__ . '/vendor/autoload.php';

Auth0\SDK\Auth0;

ain        = 'YOUR_NAMESPACE';
ent_id     = 'YOUR_CLIENT_ID';
ent_secret = 'YOUR_CLIENT_SECRET';
irect_uri  = 'http://YOUR_APP/callback';

h0 = new Auth0([
omain' => $domain,
lient_id' => $client_id,
lient_secret' => $client_secret,
edirect_uri' => $redirect_uri,
udience' => 'urn:test:api',
ersist_id_token' => true,
ersist_access_token' => true,
ersist_refresh_token' => true,


rInfo = $auth0->getUser();

!$userInfo) {
$auth0->login();


dump($profile);

For more info, check the quickstart docs for Regular webapp and Web API.

Calling the management API
ire __DIR__ . '/vendor/autoload.php';

Auth0\SDK\API\Management;

en = "eyJhbGciO....eyJhdWQiOiI....1ZVDisdL...";
ain = "account.auth0.com";

h0Api = new Management($token, $domain);

rsList = $auth0Api->users->search([ "q" => "email@test.com" ]);

dump($usersList);
Calling the Authentication API
ire __DIR__ . '/vendor/autoload.php';

Auth0\SDK\API\Authentication;

ain = "account.auth0.com";
ent_id = '...';
ent_secret = '...'; // This is optional, only needed for code exchange and impersonation api

h0Api = new Authentication($domain, $client_id, $client_secret);

etting an access token with client credentials grant
ess_token = $auth0Api->client_credentials([
    'audience' => 'urn:test:api',
    'scope' => 'do:something read:somethingelse',
]);

etting an access token with password realm grant
ess_token = $auth0Api->login([
    'username' => 'someone@example.com',
    'password' => 'shh',
    'realm' => 'Username-Password-Authentication',
]);
Troubleshoot

I am getting curl error 60: SSL certificate problem: self signed certificate in certificate chain on Windows

This is a common issue with latest PHP versions under windows (related to a incompatibility between windows and openssl CAs database).

I am not using composer, my host does not allow using Composer

This package uses composer for mantianing dependencies. However, if you cannot use composer on your server. Please follow the following steps and upload these dependencies manually.

News
NOTICE Backward compatibility breaks
4.0 3.2 3.x

$auth0Api = new \Auth0\SDK\Auth0Api($token, $domain, $guzzleOptions); / $guzzleOptions is optional /

$usersList = $auth0Api->users->search([ “q” => “email@test.com” ]);

 2.2
w the SDK fetches the user using the `tokeninfo` endpoint to be fully compliant with the openid spec
w the SDK supports RS256 codes, it will decode using the `.well-known/jwks.json` endpoint to fetch the public key

 2.x

ssion storage now returns null (and null is expected by the sdk) if there is no info stored (this change was made since false is a valid value to be stored in session).
zzle 6.1 required

 1.x

w, all the SDK is under the namespace `\Auth0\SDK`
e exceptions were moved to the namespace `\Auth0\SDK\Exceptions`

New features

e Auth0 class, now provides two methods to access the user metadata, `getUserMetadata` and `getAppMetadata`. For more info, check the [API v2 changes](https://auth0.com/docs/apiv2Changes)
e Auth0 class, now provides a way to update the UserMetadata with the method `updateUserMetadata`. Internally, it uses the [update user endpoint](https://auth0.com/docs/apiv2#!/users/patch_users_by_id), check the method documentation for more info.
e new service `\Auth0\SDK\API\ApiUsers` provides an easy way to consume the API v2 Users endpoints.
simple API client (`\Auth0\SDK\API\ApiClient`) is also available to use.
JWT generator and decoder is also available (`\Auth0\SDK\Auth0JWT`)
w provides an interface for the [Authentication API](https://auth0.com/docs/auth-api).

Note:*** API V2 restrict the access to the endpoints via scopes. By default, the user token has granted certain scopes that let update the user metadata but not the root attributes nor app_metadata. To update this information and access another endpoints, you need an special token with this scopes granted. For more information about scopes, check [the API v2 docs](https://auth0.com/docs/apiv2Changes#6).

xamples

k the [basic-oauth](https://github.com/auth0/auth0-PHP/tree/master/examples/basic-oauth) example to see a quick demo on how the sdk works.
just need to create a `.env` file with the following information:

AUTH0_CLIENT_SECRET=YOUR_APP_SECRET AUTH0_CLIENT_ID=YOU_APP_CLIENT AUTH0_DOMAIN=YOUR_DOMAIN.auth0.com AUTH0_CALLBACK_URL=http://localhost:3000/index.php AUTH0_APPTOKEN=A_VALID_APPTOKEN_WITH_CREATE_USER_SCOPE

will get your app client and secret from your Auth0 app you had created.
auth0 domain, is the one you pick when you created your auth0 account.
need to set this callback url in your app allowed callbacks.
app token is used in the 'create user' page and needs `create:users` scope. To create one, you need to use the token generator in the [API V2 documentation page](https://auth0.com/docs/apiv2)

un the example, you need composer (the PHP package manager) installed (you can find more info about composer [here](https://getcomposer.org/doc/00-intro.md)) and run the following commands on the same folder than the code.

$ composer install $ php -S localhost:3000

igration guide

from 1.x

f you use Guzzle (or some other dependency does), you will need to update it to work with Guzzle 6.1.

from 0.6.6

irst is important to read the [API v2 changes document](https://auth0.com/docs/apiv2Changes) to catch up the latest changes to the API.
pdate your composer.json file.
hange the version "auth0/auth0-php": "~1.0"
dd the new dependency "firebase/php-jwt" : "dev-master"
ow the SDK is PSR-4 compliant so you will need to change the namespaces (sorry **:(** ) to `\Auth0\SDK`
he method `getUserInfo` is deprecated and candidate to be removed on the next release. User `getUser` instead. `getUser` returns an User object compliant with API v2 which is a `stdClass` (check the schema [here](https://auth0.com/docs/apiv2#!/users/get_users_by_id))

evelop

_.env_ format

OBAL_CLIENT_ID
OBAL_CLIENT_SECRET
MAIN

Install dependencies
 SDK uses [Composer](http://getcomposer.org/doc/01-basic-usage.md) to manage its dependencies.

onfigure example

nstall dependencies
tart your web server on `examples/{example-name}` folder.
reate an OpenID Connect Application on Auth0.
onfigure the callback url to point `{your-base-url}\callback.php`.
pen `examples/{example-name}/config.php` and replace all placeholder parameters.
n your browser, open the Auth0 example project. Make sure `index.php` is being loaded.

hat is Auth0?

0 helps you to:

d authentication with [multiple authentication sources](https://docs.auth0.com/identityproviders), either social like **Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, amont others**, or enterprise identity systems like **Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider**.
d authentication through more traditional **[username/password databases](https://docs.auth0.com/mysql-connection-tutorial)**.
d support for **[linking different user accounts](https://docs.auth0.com/link-accounts)** with the same user.
pport for generating signed [Json Web Tokens](https://docs.auth0.com/jwt) to call your APIs and **flow the user identity** securely.
alytics of how, when and where users are logging in.
ll data from other sources and add it to the user profile, through [JavaScript rules](https://docs.auth0.com/rules).

reate a free account in Auth0

o to [Auth0](https://auth0.com) and click Sign Up.
se Google, GitHub or Microsoft Account to login.

ssue Reporting

ou have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues.

uthor

h0](auth0.com)

icense

 project is licensed under the MIT license. See the [LICENSE](LICENSE.txt) file for more info.

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.