SSO with PHPBB3 and Auth0

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The current feature release of phpBB 3 is 3.3/Proteus.
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.

If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
Post Reply
hardyid
Registered User
Posts: 1
Joined: Tue Apr 20, 2021 3:09 pm

SSO with PHPBB3 and Auth0

Post by hardyid »

I try to combine my phpp 3 (version 3.3) with my Auth0. According to the tutorial from https://area51.phpbb.com/docs/dev/3.3.x ... -providers I have created a new provider a4 under public_html/phpBB3/phpbb/auth/provider/oauth/service

Code: Select all

<?php
/**
 *
 * This file is part of the phpBB Forum Software package.
 *
 * @copyright (c) phpBB Limited <https://www.phpbb.com>
 * @license GNU General Public License, version 2 (GPL-2.0)
 *
 * For full copyright and license information, please see
 * the docs/CREDITS.txt file.
 *
 */

namespace phpbb\auth\provider\oauth\service;

/**
 * Auhto OAuth service
 */
class auth0 extends base
{
    /** @var \phpbb\config\config */
    protected $config;

    /** @var \phpbb\request\request_interface */
    protected $request;

    /**
     * Constructor.
     *
     * @param \phpbb\config\config              $config     Config object
     * @param \phpbb\request\request_interface  $request    Request object
     */
    public function __construct(\phpbb\config\config $config, \phpbb\request\request_interface $request)
    {
        $this->config   = $config;
        $this->request  = $request;
    }

    /**
     * {@inheritdoc}
     */
    public function get_service_credentials()
    {
        return [
            'key'       => $this->config['auth_oauth_auth0_key'],
            'secret'    => $this->config['auth_oauth_auth0_secret'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function perform_auth_login()
    {
        if (!($this->service_provider instanceof \OAuth\OAuth2\Service\auth0))
        {
            throw new exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE');
        }

        try
        {
            // This was a callback request, get the token
            $this->service_provider->requestAccessToken($this->request->variable('code', ''));
        }
        catch (\OAuth\Common\Http\Exception\TokenResponseException $e)
        {
            throw new exception('AUTH_PROVIDER_OAUTH_ERROR_REQUEST');
        }

        try
        {
            // Send a request with it
            $result = (array) json_decode($this->service_provider->request('user/info'), true);
        }
        catch (\OAuth\Common\Exception\Exception $e)
        {
            throw new exception('AUTH_PROVIDER_OAUTH_ERROR_REQUEST');
        }

        // Return the unique identifier returned from auth0
        return $result['data']['login'];
    }

    /**
     * {@inheritdoc}
     */
    public function perform_token_auth()
    {
        if (!($this->service_provider instanceof \OAuth\OAuth2\Service\auth0))
        {
            throw new exception('AUTH_PROVIDER_OAUTH_ERROR_INVALID_SERVICE_TYPE');
        }

        try
        {
            // Send a request with it
            $result = (array) json_decode($this->service_provider->request('user/info'), true);
        }
        catch (\OAuth\Common\Exception\Exception $e)
        {
            throw new exception('AUTH_PROVIDER_OAUTH_ERROR_REQUEST');
        }

        // Return the unique identifier
        return $result['data']['login'];
    }
}
After that, I add the service under
/public_html/phpBB3/config/default/container/services_auth.yml

Code: Select all

 auth.provider.oauth.service.auth0:
        class: phpbb\auth\provider\oauth\service\auth0
        arguments:
            - '@config'
            - '@request'
        tags:
            - { name: auth.provider.oauth.service }    
But I cannot see the new provider in ACP.

Any idea?
Last edited by hardyid on Mon Apr 26, 2021 7:02 pm, edited 1 time in total.

User avatar
3Di
Registered User
Posts: 908
Joined: Tue Nov 01, 2005 9:50 pm
Location: Milano 🇮🇹 Frankfurt 🇩🇪
Contact:

Re: SSO with PHPBB3 and Auth0

Post by 3Di »

Hi, your best bet is to ask there at the main site, in the Extension Writers forum:
https://www.phpbb.com/community/viewforum.php?f=461
In any case and regardless, Auth0 is not currently included in the Services in the lusitanian library. ;)
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades

Post Reply