OCS Authentication plugin - only LDAP? [SOLVED]

Are there any other authentication source plugins for OCS? If not, I’m going to need to implement a custom plugin.

I read in the docs that I’d have to extend the parent class in classes/plugins/AuthPlugin.inc.php file (https://pkp.sfu.ca/files/docs/quickreference/quickreference.pdf). Do you have any example of how I should do it?

I copied the ldap plugin folder /plugins/auth/ldap to /plugins/auth/custom and changed the authentication method to return always true. I tested it, but it doesn’t work. What am I missing?

The full code of CustomAuthPlugin.inc.php:

    <?php
    import('classes.plugins.AuthPlugin');

    class CustomAuthPlugin extends AuthPlugin {
    	/**
    	 * Called as a plugin is registered to the registry
    	 * @param $category String Name of category plugin was registered to
    	 * @return boolean True iff plugin initialized successfully; if false,
    	 * 	the plugin will not be registered.
    	 */
    	function register($category, $path) {
    		$success = parent::register($category, $path);
    		$this->addLocaleData();
    		return $success;
    	}

    	/**
    	 * Return the name of this plugin.
    	 * @return string
    	 */
    	function getName() {
    		return 'custom';
    	}

    	/**
    	 * Return the localized name of this plugin.
    	 * @return string
    	 */
    	function getDisplayName() {
    		return __('plugins.auth.custom.displayName');
    	}

    	/**
    	 * Return the localized description of this plugin.
    	 * @return string
    	 */
    	function getDescription() {
    		return __('plugins.auth.custom.description');
    	}


    	//
    	// Core Plugin Functions
    	// (Must be implemented by every authentication plugin)
    	//

    	/**
    	 * Returns an instance of the authentication plugin
    	 * @param $settings array settings specific to this instance.
    	 * @param $authId int identifier for this instance
    	 * @return CustomAuthPlugin
    	 */
    	function &getInstance($settings, $authId) {
    		$returner = new CustomAuthPlugin($settings, $authId);
    		return $returner;
    	}

    	/**
    	 * Authenticate a username and password.
    	 * @param $username string
    	 * @param $password string
    	 * @return boolean true if authentication is successful
    	 */
    	function authenticate($username, $password) {
                    return true; // Testing
    	}

    }

    ?>

It worked now! I think the problem was that I set this custom plugin as default authentication source.

I understood how to import users using XML plugin. I also have to register users as they are created in my backend server.
Can someone please show an example of registering an user using OCS API (or something like that)? Is sending a HTTP POST request to /ocs/index.php/ITS/ITS/user/createAccount with user data a good solution?

Hi @Guilherme_Passero,

I’m afraid you’re wandering in uncharted territory – we’ve never worked much with the authentication plugin category, especially with OCS, so you may encounter undiscovered bugs or incompletely fleshed out ideas.

OCS doesn’t have an API per se, but posting to createAccount is not a bad idea. If you want to create a user from within OCS’s PHP code, then using the DAO per usual is the best way.

Regards,
Alec Smecher
Public Knowledge Project Team

Understood. I’ll work on that tomorrow and let you know how it goes :smiley:

I had to make some changes in createAccount to accept authId and it worked.

Thanks for the help.