Jump to content

Authenticating against IPB member table


Recommended Posts

Posted

Some years ago, I built a bespoke CMS for the website associated with our community that authenticated its logins against the v3 IPB member database. This enabled me to leverage IPB's user management features, which were applicable to the CMS too (user roles and permissions, etc). This broke completely with the introduction of v4, and I've been holding off upgrading until I can figure out how to make it work again in a dev environment. Sadly, I'm having no luck whatsoever!

I've been trying to grok the information provided in the Developer Documentation, but my PHP skills are rusty, and none too advanced these days, so I thought I'd ask for some guidance here. Also, most of the approaches in the docs are about providing alternative login methods for the forums themselves, which is not what I'm trying to do. I merely need to authenticate a user's credentials against those stored in the database, and then let the CMS do the rest. I thought I might have hit upon a usable solution with the SSO approach detailed in the documentation:

However, upon successfully acquiring the logged-in user's details, I attempt to store them in the session that gets created for the CMS, but it doesn't persist, and it seems that I end up with two different session IDs. I'm assuming that the following code intialises an IPB session that subsequently clashes with my own session:

/* Initiate the session to verify who this user is */
\IPS\Session\Front::i();

Any idea how to get past this issue? I'm really stuck right now.

Kev

Posted

So you have the user's authentication details (username/email and password) and want to validate them against an Invision Community database? Assuming you are using 4.3.x and you are using the Standard/Internal login handler, you should be able to do the following:

require '/path/to/forums/init.php';

$username = '';
$password = '';
$login = new \IPS\Login( \IPS\Http\Url::external( "http://yoururl.com" ), \IPS\Login::LOGIN_FRONT );
$member = \IPS\Login\Handler::findMethod( 'IPS\Login\Handler\Standard' )->authenticateUsernamePassword( $login, $username, $password );

This is a crude mockup and I haven't tested it, but hopefully it points you in the right direction.

Posted

OK, so that code works straight out of the box in terms of validating the login credentials and returning a valid member object. But this bumps me to my next problem! I need to access the member's group (member_group_id) to determine what happens next, as only certain member groups are allowed to log in to the CMS. However, I can't seem to access this property, presumably because it's marked protected (my knowledge of PHP OOP is very slight indeed). Executing print_r on the member object shows me all the data, but I can't seem to access it programmatically.

Is there any easy way around this?

Kev

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...