More clarity on how to create a custom authenticator

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
redsquirrel
Registered User
Posts: 40
Joined: Wed Aug 20, 2014 3:54 am

More clarity on how to create a custom authenticator

Post by redsquirrel »

I'm following this tutorial but there are a lot of files it talks about that I can't seem to find, and it's unclear what the format/syntax of things is suppose to be.

https://area51.phpbb.com/docs/dev/3.2.x ... -providers

I cannot find confg/auth.yml. I also cannot find config/services.yml

Am I suppose to create these files?
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: More clarity on how to create a custom authenticator

Post by david63 »

redsquirrel wrote: Sun Oct 09, 2022 2:53 am I cannot find confg/auth.yml. I also cannot find config/services.yml

Am I suppose to create these files?
Yes
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
redsquirrel
Registered User
Posts: 40
Joined: Wed Aug 20, 2014 3:54 am

Re: More clarity on how to create a custom authenticator

Post by redsquirrel »

Where do I put these files? The tutorial is really not clear?

So I copied phpbb/auth/provider/db.php to phpbb/auth/provider/custom.php and also changed class name to custom in custom.php. At this point it's going to be the same as using db but I just want to get the files down path before I start coding it.

From here I'm a bit lost. so where do I put services.yml? And what is the proper format? Is this right? And what about "adding an entry to config/auth.yml" what is the format of that?

Code: Select all

services:
    auth.provider.custom:
        class: acme\demo\auth\provider\custom
        arguments:
            - '@dbal.conn'
        tags:
            - { name: auth.provider.custom }

I was confused about the template file too but just realized I don't need that unless I want to be able to set config parameters, so I will deal with that once I get my custom provider to show up in the list.

So really it's the auth.yml and services.yml file I need to figure out. Where exactly does it go?

Is there a more in depth tutorial on this, I feel like this one only really skims the surface and seems to assume existing knowledge. I'd like to know what the various parameters do as well like what does "- '@dbal.conn'" mean as it may or may not apply to my custom one. I assume it's a way to pass on information.
User avatar
GanstaZ
Registered User
Posts: 1187
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: More clarity on how to create a custom authenticator

Post by GanstaZ »

Is best to start with basics & only after dive into unknown abyss.
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
redsquirrel
Registered User
Posts: 40
Joined: Wed Aug 20, 2014 3:54 am

Re: More clarity on how to create a custom authenticator

Post by redsquirrel »

Ok so I think I was putting it in the wrong folder, so it should go in ext/myname/customauthname

Still unclear on lot of stuff, like for example, the service file. What is acme\demo\auth\provider\custom? Am I suppose to change that to the path of the extension? What about the arguments part what is that for? I find a lot of these details are not really explained well. Is there a more detailed tutorial that goes over all of this?

Failing this I think I'm just going to edit the sources directly, but trying to avoid that if I can so that upgrades are simpler.
redsquirrel
Registered User
Posts: 40
Joined: Wed Aug 20, 2014 3:54 am

Re: More clarity on how to create a custom authenticator

Post by redsquirrel »

Getting a little closer. Just found out I also need a composer.json file. I got it to the point where it shows up as an extension and I can enable it but as soon as I load the admin page to pick the authenticator I get an error that the class can't be found. I assume this might have to do with my class naming. How would I go about fixing this?

Here is what my files look like:

ext/vendor/customauth/composer.json:

Code: Select all

{
    "name": "vendor/customauth",
    "type": "phpbb-extension",
    "description": "Vendor Custom Authenticator",
    "homepage": " ",
    "version": "1.0.0",
    "time": "2022-12-13",
    "keywords": ["phpbb", "extension", "vendor", "customauth"],
    "license": "GPL-2.0-only",
    "authors": [
        {
            "name": "Red Squirrel",
            "email": "",
            "homepage": "",
            "role": "Lead Developer"
        }
    ],
    "require": {
        "php": ">=5.4.0",
        "composer/installers": "~1.0"
    },
    "require-dev": {
        "phpbb/epv": "dev-master"
    },
    "extra": {
        "display-name": "Custom Authenticator",
        "soft-require": {
            "phpbb/phpbb": "~3.2"
        }
    }
}

ext/vendor/customauth/config/services.yml:

Code: Select all

         
services:
    auth.provider.customauth:
        class: vendor\auth\provider\customauth
        arguments:
            - '@dbal.conn'
        tags:
            - { name: auth.provider }



ext/vendor/customauth/customauth.php:

Code: Select all


namespace phpbb\auth\provider;

use phpbb\captcha\factory;
use phpbb\captcha\plugins\captcha_abstract;
use phpbb\config\config;
use phpbb\db\driver\driver_interface;
use phpbb\passwords\manager;
use phpbb\request\request_interface;
use phpbb\user;

/**
 * Database authentication provider for phpBB3
 * This is for authentication via the integrated user table
 */
class customauth extends base

(snip)
(above file is just a copy of db.php with my own class name which I'll modify once I get this working)


I'm guessing I have something wrong in my naming convention somewhere but not sure what, can someone point out what it is?

This is the error I get when loading the admin page to pick an authenticator:

Code: Select all

Fatal error: Uncaught Error: Class 'vendor\auth\provider\customauth' not found in /network/appdev/dev/vendor.ca/src/cache/production/container_dbdbe80dc7030ae9bd39ee30cca82130.php:986
 Stack trace: 
 #0 /network/appdev/dev/vendor.ca/src/vendor/symfony/dependency-injection/Container.php(306): 
 phpbb_cache_container->getAuth_Provider_customauthService() 
 #1 /network/appdev/dev/vendor.ca/src/phpbb/di/service_collection.php(57): 
 Symfony\Component\DependencyInjection\Container->get() 
 #2 /network/appdev/dev/vendor.ca/src/phpbb/di/service_collection_iterator.php(44):
  phpbb\di\service_collection->offsetGet() 
  #3 /network/appdev/dev/vendor.ca/src/includes/acp/acp_board.php(649): phpbb\di\service_collection_iterator->current() 
  #4 /network/appdev/dev/vendor.ca/src/includes/functions_module.php(676): acp_board->main()
   #5 /network/appdev/dev/vendor.ca/src/adm/index.php(81): p_master->load_active() 
  #6 {main} thrown in /network/appdev/dev/vendor.ca/src/cache/production/container_dbdbe80dc7030ae9bd39ee30cca82130.php on line 986
(this error was all 1 line I reformatted it to make it easier to read)


For sake of this post, my site name (and folder I put extension in) is called "vendor" and the extension name is called "customauth"


I also wonder if this has to do with the arguments. What does "@dbal.conn" refer to exactly and how would I name the rest of the arguments and where would that info get filled in? Like what is the context of those names and where do they come from? I tried to put something else in there to see what happens but got other errors so I presume those names have to be something specific and I probably need more of them to fill in the class constructor.
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28654
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: More clarity on how to create a custom authenticator

Post by Paul »

The tutorial you are following expects that you follow the previous steps as well (see https://area51.phpbb.com/docs/dev/3.2.x ... index.html) or at least the first two. I suggest that you read those at least, as it should answer some of the questions you ask.

Regarding your error, the name space does not match the class you defined in your config.
redsquirrel
Registered User
Posts: 40
Joined: Wed Aug 20, 2014 3:54 am

Re: More clarity on how to create a custom authenticator

Post by redsquirrel »

I think what I need is an example of an actual authenticator, is there one that someone can link me to? Even if the extention just has a user/pass hard coded into it that lets you login with test/test or something that way I can see the structure of the files better and the namespace names etc. I'm getting hung up on that stuff more than anything. I read the link provided as well but still can't seem to get it working.

EDIT: Getting somewhere!

I have to create a folder in my extension's folder called auth, and then in that folder one called provider, then put my class file there. I was putting it in the root of the extension folder instead.

Still unsure about lot of stuff like passing arguments etc to the custom class, but think I'll call it quits for tonight.
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28654
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: More clarity on how to create a custom authenticator

Post by Paul »

Unfortently I don't have the time to create a full example. What you can try is using the extension skeleton creator to create a skeleton extension. See https://www.phpbb.com/customise/db/offi ... _skeleton/

In general, extensions are always completely on their own. All files of your extension, from config to php files, are in the ext/vendor/name directory. There are no files outside of your extension directory.
In the config/ directory you define what services there are. Here you will need to provide your provider.
There is no direct list of services you can inject I think. However, if you look into the config/ directory in your phpBB installation you find configuration files from phpBB with all services defined.
redsquirrel
Registered User
Posts: 40
Joined: Wed Aug 20, 2014 3:54 am

Re: More clarity on how to create a custom authenticator

Post by redsquirrel »

Yeah guess I'll just have to keep tinkering around. I at least got it to the point where it shows up now so I feel the hardest part is done. I ended up finding an authenticator extension that is designed to let you login with social media, so I was able to look at the file structure and the various files to see what the syntax is like.
redsquirrel
Registered User
Posts: 40
Joined: Wed Aug 20, 2014 3:54 am

Re: More clarity on how to create a custom authenticator

Post by redsquirrel »

Getting somewhere. I successfully copied the built in db authenticator as my own extension and confirmed that it works by making it load a specific user if I type specific credentials, as a test. (ex: login as a and b and it loads the admin user - obviously wont be that way in prod haha) This will allow me to then base my code off of that one. In case someone finds this and wants to do the same, the services.yml file has to be as follows:

Code: Select all

         
services:
     auth.provider.[extname]:
        class: [vendor]\[extname]\auth\provider\[extname]
        arguments:
            - '@captcha.factory'
            - '@config'
            - '@dbal.conn'
            - '@passwords.manager'
            - '@request'
            - '@user'
            - '%core.root_path%'
            - '%core.php_ext%'
        tags:
            - { name: auth.provider }
And the actual php class file has to be in the auth/provider folder within your extensions folder. NOT in the root. (that was my original issue)

From this point on I should be able to do everything else I need from a coding perspective. The hard part was figuring out the file structure and the config files etc.
Post Reply

Return to “Extension Writers Discussion”