Creating and Packaging a Custom Authentication Type

Permalink
Hi all,

I've been looking at adding a new authentication type but there doesn't appear to be much in the way of documentation, in particular packaging. I've followed the advice in the following post to make a copy of one already existing in the core and tried to package that but I get an error 'Class \Concrete\Authentication\Facebook2\Controller does not exist'.

I don't understand why the above error is referring to the core path unless the install process is meant to copy the files from the package to the above location?

https://www.concrete5.org/community/forums/5-7-discussion/need-help-...

Can someone shed some light on this please?

So the package I created is named 'my_demo_facebook' and beneath this folder I created the following folders to contain the copy of the core facebook method.

packages > my_demo_facebook > authentication > facebook2

Therefore the facebook2 folder contains controller.php, form.php, hook.php and type_form.php copied across as is from 'concrete/authentication/facebook'.

The root of my package folder 'my_demo_facebook' contains a controller.php and icon.png.

Here's how my package controller looks:

<?php
namespace Concrete\Package\MyDemoFacebook;
defined('C5_EXECUTE') or die('Access Denied.');
use \Concrete\Core\Package\Package;
use \Concrete\Core\Authentication\AuthenticationType;
class Controller extends Package
{
    protected $pkgHandle = 'my_demo_facebook';
    protected $appVersionRequired = '5.7.5.8';
    protected $pkgVersion = '0.0006';
    public function getPackageDescription()
    {
        return t('Package to extend Authentication Types, adds the Facebook2 Authentication Type, brought to you by Us Inc.');
    }
    public function getPackageName()


I had to add 'add' to the following line which appears in the package controller above, otherwise it would throw an exception about an open parenthesis. This still isn't right but it does at least make an entry into the MySQL 'authenticationtypes' table. It doesn't seem right because it sets 'authTypeIsEnabled' and 'authTypeDisplayOrder' to '1'. I think this should be '0' and the row count of the 'authenticationtypes' table prior to committing the new auth type, respectively. Not sure if pkgID is meant to be anything other than '0' as all the other auth types are set to this in the MySQL table.

\Concrete\Core\Authentication\AuthenticationType::add('facebook2', 'Facebook2', $pkg);

1 Attachment

 
rgudinho replied on at Permalink Reply
rgudinho
Man it's been a while since this was posted and no one seems to care to reply back, I am running into the same issues as you did and so far I was able to put my custom Auth Type into the list, you're right, I got that "missing controller" message and it was indeed looking for files in the concrete/authentication folder, instead of in your custom package, the workaround for me was to set the pkg id manually in that record you found in the AuthenticationTypes table, so it was not meant to be 0 for this particular scenario.

Have you made any progress on this?
markbennett replied on at Permalink Reply
This may be a different version of C5, but I had the same problem for a while. Looks like you're passing the package reference as the third parameter to AuthenticationType::add, but it should be fourth - the third is the display order. So my package install function looks like this:

public function install()
{
    $pkg = parent::install();
    $type = AuthenticationType::add('aws_cognito', 'AWS Cognito', 1, $pkg);
    $type->enable();
}


and now it works just fine.
BacLuc replied on at Permalink Best Answer Reply
In the hope that someone might find it useful:
I made a custom AuthenticationType for an Application in a package:
https://github.com/BacLuc/bacluc_oauth_authtype/...