Git Product home page Git Product logo

yii2-auth0's Introduction

anli\auth0

Yii2 Auth0

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist anli/yii2-auth0 "*"

or add

"anli/yii2-auth0": "*"

to the require section of your composer.json file.

Run migration with:

php yii migrate/up --migrationPath=@vendor/anli/yii2-auth0/migrations

Configuration

Update the modules section with:

'auth0' => array_merge([
    'class' => 'anli\auth0\Module',
    'adminEmails' => ['[email protected]'],
], require(__DIR__ . '/auth0-local.php')),

Create a new file in config/auth0-local.php:

<?php
if (YII_ENV_DEV) {
    return [
        'serviceId' => '',
        'domain' => '',
        'clientId' => '',
        'clientSecret' => '',
        'redirectUrl' => '',
        'apiTokens' => [
            'usersRead' => '',
            'usersUpdate' => '',
        ]
    ];
}

return [
    'serviceId' => '',
    'domain' => '',
    'clientId' => '',
    'clientSecret' => '',
    'redirectUrl' => '',
    'apiTokens' => [
        'usersRead' => '',
        'usersUpdate' => '',
    ]
];

Add to your .gitignore file:

/config/auth0-local.php

Login to auth0 and update the Allowed Callback Urls in your setting page.

Update the components section in the config with:

'user' => [
    'identityClass' => 'anli\auth0\models\User',
    'loginUrl' => ['auth0/user/login'],
],
'tenant' => [
    'class' => 'anli\auth0\components\Tenant',
],

Usage

Update your url section for your login button to [/auth0/user/login].

Update your url section for your logout button to [/auth0/user/logout].

To show the login user, use:

Html::encode(Yii::$app->user->identity->username);

To show the login tenant, use:

Html::encode(Yii::$app->tenant->identity->name);

To auto update the tenant_id, add to the behaviors section of your model with:

use anli\auth0\behaviors\TenantBehavior;
...
'tenant' => [
    'class' => TenantBehavior::className(),
],

FAQs

If you encounter the following error

\JWT not found

Change the firebase/php-jwt version to v2.2.0:

cd @vendor/firebase/php-jwt
git checkout v2.2.0

Update the @vendor/composer/autoload_classmap.php with:

'BeforeValidException' => $vendorDir . '/firebase/php-jwt/Exceptions/BeforeValidException.php',
'JWT' => $vendorDir . '/firebase/php-jwt/Authentication/JWT.php',

If you encounter the following error:

Cannot handle token prior to 2015-08-05T10:42:34+0200

And your system time forward a few minutes.

If you encounter the following error:

cURL error 60: SSL certificate problem: self signed certificate in certificate chain

Download CA to;

C:\xampp\php\ca\cacert.pem

and update C:\xampp\php\php.ini with

curl.cainfo=C:\xampp\php\ca\cacert.pem

Restart your apache2 server.

yii2-auth0's People

Contributors

anli avatar seowzl39 avatar felli avatar olitguru avatar

Watchers

James Cloos avatar  avatar

Forkers

thyseus

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.