Forum

Thread tagged as: Problem

Problem with the auth plugin example

Hi, hope I'm not being a silly billy here...

I've tried the auth plugin example as here https://docs.grabaperch.com/api/auth/ (just copied the code).

I'm getting this 500:

[Sat Feb 11 18:15:24.053810 2017] [:error] [pid 2751] [client 127.0.0.1:52366] /home/dave/sites/site1/perch/addons/plugins/auth/my_system/auth.php

[Sat Feb 11 18:15:24.094460 2017] [:error] [pid 2751] [client 127.0.0.1:52366] PHP Fatal error:  Uncaught Error: Class 'my_system_auth_plugin' not found in /home/dave/sites/site1/perch/core/lib/PerchUsers.class.php:27\nStack trace:\n#0 /home/dave/sites/site1/perch/core/inc/auth.php(17): PerchUsers->get_current_user()\n#1 /home/dave/sites/site1/perch/core/index.php(14): include('/home/dave/site...')\n#2 /home/dave/sites/site1/perch/index.php(3): include('/home/dave/site...')\n#3 {main}\n  thrown in /home/dave/sites/site1/perch/core/lib/PerchUsers.class.php on line 27

I believe I've faithfully copied the example. As far as I can tell from the code, perch/core/inc/auth.php and perch/core/lib/PerchUsers.class.php look in difference places for the plugin class -one with addons in the path and other not -so I've put the my_system/auth.php in both places to see if that helps but it didn't.

Thanks for any thoughts

Dave C

Dave C 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Does your app include an autoloader?

Dave C

Dave C 0 points

Drew McLellan said:

Does your app include an autoloader?

I'm afraid I don't know what that is, so I suppose not.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is your class declared as my_system_auth_plugin ?

Dave C

Dave C 0 points

Yes. At present I have two of the same file, both with that class declaration, copied from the example, one in /home/dave/sites/site1/perch/addons/plugins/auth/my_system/auth.php and one in /home/dave/sites/site1/perch/plugins/auth/my_system/auth.php

I've tried one and then the other and both.

What I've done (just for now) is paste that class into the top of /home/dave/sites/site1/perch/core/lib/PerchUsers.class.php, which gives me the expected result in that no login is required. (Although the class is printed at the top of the admin page).

Drew McLellan

Drew McLellan 2638 points
Perch Support

Easier, and leaving you with support, would be to just add it to your config.php file.

require(__DIR__. '/../addons/plugins/auth/my_system/auth.php');
Dave C

Dave C 0 points

OK thanks. I've deleted auth folder from /home/dave/sites/site1/perch/plugins. (Had that there just to try it). Also deleted the class my_system_auth_plugin from /home/dave/sites/site1/perch/core/lib/PerchUsers.class.php.

So I have /home/dave/sites/site1/perch/addons/plugins/auth/my_system containing auth.php containing the example code with a class of my_system_auth_plugin, and the last two lines of config.php are:

define('PERCH_AUTH_PLUGIN', 'my_system');
require(__DIR__. '/../addons/plugins/auth/my_system/auth.php');

The 500 I'm getting logs as:

[Sun Feb 12 15:30:25.427135 2017] [:error] [pid 4010] [client 127.0.0.1:41266] PHP Warning: require(/home/dave/sites/site1/perch/plugins/auth/my_system/auth.php): failed to open stream: No such file or directory in /home/dave/sites/site1/perch/core/lib/PerchUsers.class.php on line 24 [Sun Feb 12 15:30:25.512821 2017] [:error] [pid 4010] [client 127.0.0.1:41266] PHP Fatal error: require(): Failed opening required '/home/dave/sites/site1/perch/plugins/auth/my_system/auth.php' (include_path='.:/usr/share/php') in /home/dave/sites/site1/perch/core/lib/PerchUsers.class.php on line 24

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show us your auth.php file?

Dave C

Dave C 0 points

Sure: /home/dave/sites/site1/perch/addons/plugins/auth/my_system/auth.php

class my_system_auth_plugin extends PerchAPI_AuthPlugin
{
    public function log_user_in($username, $password)
    {
        //make request to check username and password
        return [
            'email' => 'admin@example.com',
            'role'  => 'admin',
        ];
    }

    public function resume_session()
    {
        //make request to check username and password
        return [
            'email' => 'admin@example.com',
            'role'  => 'admin',
        ];
    }

    public function log_user_out()
    {
        return true;
    }
}
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can I see your diagnostics report?

Dave C

Dave C 0 points

Sure, I'm working with another dev (who bought the licence) and not sure if I should show the domain, so have hidden:

Perch Runway: 2.8.34
Production mode: Production (100)
Installed apps: content (2.8.34), assets (2.8.34), categories (2.8.34)
DB driver: PDO
DB tables: perch2_backup_plans (0), perch2_backup_resources (0), perch2_backup_runs (0), perch2_categories (0), perch2_category_counts (0), perch2_category_sets (0), perch2_collection_index (0), perch2_collection_items (0), perch2_collection_revisions (0), perch2_collections (0), perch2_content_index (97), perch2_content_items (28), perch2_content_regions (14), perch2_navigation (0), perch2_navigation_pages (0), perch2_page_routes (0), perch2_page_templates (5), perch2_pages (11), perch2_resource_log (0), perch2_resource_tags (0), perch2_resources (0), perch2_resources_to_tags (0), perch2_settings (12), perch2_user_passwords (0), perch2_user_privileges (26), perch2_user_role_privileges (16), perch2_user_roles (2), perch2_users (1), site12backup_plans (0), site12backup_resources (0), site12backup_runs (0), site12categories (0), site12category_counts (0), site12category_sets (0), site12collection_index (0), site12collection_items (0), site12collection_revisions (0), site12collections (0), site12content_index (0), site12navigation (0), site12navigation_pages (0), site12page_routes (0), site12resource_log (0), site12resource_tags (0), site12resources (0), site12resources_to_tags (0), site12user_passwords (0), site12user_role_privileges (0)
Users: 1
PHPMailer: 5.2.21
App runtimes:

<?php
    $apps_list = array(
        'content', 
        'categories',
    );

Editor plug-ins: markitup
H1: 2250eb232e8332249ee4f6308f49b409
L1: e569285320f7a45ea61289d279766883
F1: 6a33f95eca3667f9e0c39bf5ca2980fe
headerColour: rgb(54,54,54)
content_singlePageEdit: 1
helpURL:
siteURL: /
hideBranding: 0
content_collapseList: 1
lang: en-gb
update_2.8.34: done
headerScheme: dark
update_runway_2.8.34: done
latest_version: 2.8.15
on_sale_version: 2.8.34
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_SITEPATH: /home/dave/sites/site1
PERCH_SCHEDULE_SECRET: BC75hTvxDOCl8j08
PERCH_DB_USERNAME: root
PERCH_DB_SERVER: localhost
PERCH_DB_DATABASE: site1
PERCH_DB_PREFIX: perch2_
PERCH_EMAIL_FROM: *********
PERCH_EMAIL_FROM_NAME: Dave C
PERCH_LOGINPATH: /perch
PERCH_PATH: /home/dave/sites/site1/perch
PERCH_CORE: /home/dave/sites/site1/perch/core
PERCH_RESFILEPATH: /home/dave/sites/site1/perch/resources
PERCH_RESPATH: /perch/resources
PERCH_HTML5: 1
PERCH_TZ: UTC
PERCH_RUNWAY: 1
PERCH_ERROR_MODE: DIE
PERCH_DATE_LONG: %d %B %Y
PERCH_DATE_SHORT: %d %b %Y
PERCH_TIME_SHORT: %H:%M
PERCH_TIME_LONG: %H:%M:%S
PERCH_RUNWAY_ROUTED:
PERCH_STRONG_PASSWORDS:
PERCH_DEBUG:
PERCH_PREVIEW_ARG: preview
PERCH_TEMPLATE_PATH: /home/dave/sites/site1/perch/templates
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
PERCH_PRODUCTION_MODE: 100
PERCH_RWD:
PERCH_HTML_ENTITIES:
PERCH_SSL:
PERCH_STRIPSLASHES:
PERCH_PROGRESSIVE_FLUSH: 1
PERCH_PARANOID:
PERCH_FORCE_SECURE_COOKIES:
PERCH_PASSWORD_MIN_LENGTH: 6
PERCH_MAX_FAILED_LOGINS: 10
PERCH_AUTH_LOCKOUT_DURATION: 1 HOUR
PERCH_VERIFY_UPLOADS:
PERCH_AUTH_PLUGIN:
PERCH_DB_CHARSET: utf8
PERCH_DB_PORT:
PERCH_DB_SOCKET:
PERCH_SESSION_TIMEOUT_MINS: 20

Hosting settings

PHP: 7.0.13-0ubuntu0.16.04.1
Zend: 3.0.0
OS: Linux
SAPI: apache2handler
Safe mode: not detected
MySQL client: mysqlnd 5.0.12-dev - 20150407 - $Id: 241ae00989d1995ffcbbf63d579943635faf9972 $
MySQL server: 5.7.17-0ubuntu0.16.04.1
Free disk space: 59.77 GB
Extensions: Core, date, libxml, openssl, pcre, zlib, filter, hash, Reflection, SPL, session, standard, apache2handler, mysqlnd, PDO, calendar, ctype, exif, fileinfo, ftp, gettext, iconv, imagick, json, mysqli, pdo_mysql, Phar, posix, readline, shmop, sockets, sysvmsg, sysvsem, sysvshm, tokenizer, Zend OPcache
GD: No
ImageMagick: Yes
PHP max upload size: 2M
PHP max form post size: 8M
PHP memory limit: 128M
Total max uploadable file size: 2M
Resource folder writeable: Yes
Session timeout: 24 minutes
Native JSON: Yes
Filter functions: Yes
Transliteration functions: No
HTTP_HOST: dev.****
HTTP_USER_AGENT: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:51.0) Gecko/20100101 Firefox/51.0
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_LANGUAGE: en-US,en;q=0.5
HTTP_ACCEPT_ENCODING: gzip, deflate
HTTP_REFERER: https://dev.****/perch/core/settings/diagnostics/
HTTP_COOKIE: cmsa=1; PHPSESSID=egpjfa1i9g517n8os5k5mhsvu2
HTTP_CONNECTION: keep-alive
HTTP_UPGRADE_INSECURE_REQUESTS: 1
PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SERVER_SIGNATURE: <address>Apache/2.4.18 (Ubuntu) Server at dev.**** Port 80</address>
SERVER_SOFTWARE: Apache/2.4.18 (Ubuntu)
SERVER_NAME: dev.****
SERVER_ADDR: 127.0.0.1
SERVER_PORT: 80
REMOTE_ADDR: 127.0.0.1
DOCUMENT_ROOT: /home/dave/sites/site1
REQUEST_SCHEME: http
CONTEXT_DOCUMENT_ROOT: /home/dave/sites/site1
SERVER_ADMIN: webmaster@localhost
SCRIPT_FILENAME: /home/dave/sites/site1/perch/core/settings/diagnostics/index.php
REMOTE_PORT: 38100
GATEWAY_INTERFACE: CGI/1.1
SERVER_PROTOCOL: HTTP/1.1
REQUEST_METHOD: GET
QUERY_STRING: extended
REQUEST_URI: /perch/core/settings/diagnostics/?extended
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
PHP_SELF: /perch/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1486993044.463
REQUEST_TIME: 1486993044

On the off chance it's somehow related: if I move a file about.html in site root to about/index.php, I can't view the About page by browsing 'about/' -I have to go to 'about/index.php'. (I'm new to all this :)

Drew McLellan

Drew McLellan 2638 points
Perch Support

It might be worth checking with your colleague - I can't see why that class would not be available if the require doesn't fail.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Wait, that's not the whole of your auth.pho file is it? It has a <?php tag too, right?

Dave C

Dave C 0 points

Drew McLellan said:

Wait, that's not the whole of your auth.pho file is it? It has a <?php tag too, right?

Um, it didn't exactly have one. I feel like a real silly billy. (massive PHP noob error)

Thank you very much for your help :)