Topic-icon Gmail Authentication with suffix

Active Subscriptions:

None
9 years 9 months ago #45712 by crommie
Hi Alex,

I have a website that uses Gmail Authentication with suffix. Only users with a certain domain suffix can login. If they don't have an account yet, an account is created using email address and Gmail password. This works fine.

The website is a portal. Among other stuff, users need to access documents and applications from their Google account through it (Gmail, Drive, Groups etc.). For that, I have JFBConnect. But... I discovered any user can connect his Google account to the website, and if he does, he gets a thank you message and is asked to register for the site. If he does, and he doesn't have the domain suffix, he gets an authentication error message - but the account does get created.

Can I configure JFBConnect to only accept users with the right suffix? Or is there a workaround for this?

Thanks!
The topic has been locked.
Support Specialist
9 years 9 months ago #45720 by alzander
There's nothing built in to JFBConnect to do what you're looking for, but it'd be pretty trivial to add a few checks to make sure the email is formatted a specific way with the right suffix.

First, can you let me know:
* What are you using for the GMail authentication? Is that portion working correctly with JFBConnect? It sounds like it is, but just want to make sure.
* What email suffixes are you requiring?
* Does the validation only need to work with Google authentication, or are you using other social networks in JFBConnect that would need to be validated as well?
* What registration mode are you using in JFBConnect: Automatic or the form-based registration?

Sorry for all the follow up questions, but those answers will help us in getting you the right code snippet to add to JFBConnect's registration/authentication code.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
9 years 9 months ago #45752 by crommie
Hi Alex,

Does this mean you're going to write a code snippet especially for me? That is way beyond awesome!

I'm using the Gmail Authentication plugin that is part of the Joomla core. And it looks like this works fine with JFBConnect.

Before I even considered code moderation, my workaround would be two buttons on the front page, one for first time visiters (creates account with Gmail authentication, user connects to Google account as a second step) and one for returning visitors (login with Google). But if we could have this all in one, I would be very, very happy.

In the code you can use "mydomain.com" as suffix; I can replace it with the correct one myself.

Validation only needs to work with Google.

I would like to use automatic registration.

If you would like to know anything else, please ask. The more you ask, the more I have to think this through - and that's a good thing :)

Thanks!
The topic has been locked.
Support Specialist
9 years 9 months ago - 9 years 9 months ago #45791 by alzander
Thanks for the info. The below code edit should do what you're looking for. It's extremely simplistic, but of course, you'll still want to test as much as you can to verify it works as expected.

The file you want to edit is /components/com_jfbconnect/models/loginregister.php. Around line 224, you'll see:
$newEmail = $profile->get('email');
        $fullname = $profile->get('full_name');
Modify that by adding the following lines after that:
if (strpos($newEmail, 'mydomain.com') === false)
{
    $app = JFactory::getApplication();
    $app->enqueueMessage("We're sorry, we couldn't create your account because you aren't using a mydomain.com address", 'error');
    $app->redirect('index.php');
}
That *should* do what you want.. but again, test test test!

Please let me know how that goes, and if you need anything else, just let us know!

Thanks,
Alex

Edit: Updated the strpos check
Last edit: 9 years 9 months ago by alzander.
The topic has been locked.
Support Specialist
9 years 9 months ago #45792 by alzander
Oh, by the way, that check will work for all social networks that are performing automatic registration. If you *only* want it to work for Google and not the others, that's an easy modification to the above code.

Alex
The topic has been locked.
Active Subscriptions:

None
9 years 9 months ago #45817 by crommie
Yes! This works! Thank you!

Small thing though: if a user doesn't have the right credentials, he still gets logged in to his Google account.
And because of that, he can't retry by hitting the Google button, because in that case he gets the "we're sorry" message over and over again.
Is there a solution for that or do I have to teach them to log out from Google first and then retry?
The topic has been locked.
Support Specialist
9 years 9 months ago #45821 by alzander
There isn't anything JFBConnect can do about that. When we authenticate a user, we simply hand them off to Google and wait for a response back with the user information. Google decides if the user is logged in yet or not. If not, they'll show the authentication window and let the user enter their Google credentials. While that's happening, JFBConnect doesn't know what the user is doing.. we just get information once the user has successfully authenticated.

Once that's done, we get the user's email address. If it doesn't match your requirements, there's no way for us to log the user out of Google. That's an option solely up to the users. Google really doesn't ever want users logged out since that gives them a lot of their analytics data.

I hope that helps answer your question, even if it doesn't help you do what you were looking to do.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
9 years 9 months ago #45832 by crommie
Yes, it answers my question. No problem, this just means I have to write a small what-to-do-guide for the unfortunate users accidently trying to log in with a different Google account. So it all comes down to my educational skills now :-)

Thanks again Alex!
The topic has been locked.
Support Specialist
9 years 9 months ago #45836 by alzander
No problem for the help. It's what we're here for! If you have any other questions, just let me know.

Finally, if you haven't already, please consider leaving a rating and review for JFBConnect, or our support, on the Joomla Extension Directory. It certainly isn't required, but is very appreciated:
extensions.joomla.org/extensions/social-...ook-integration/7215

Thanks,
Alex
The topic has been locked.