Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zness21's avatar

Socialite/OAuth & Google Apps?

Fellow Developers,

Hey Everyone, I was hoping I could get some help with an issue I've been struggling with. I am working on building an internal "portal" of sorts for my company that will have custom built "tools" for individual users of the company. I am struggling with the login portion of the portal app. Currently our company uses Google Apps for user, email, device etc....management on top of a Linux architecture with MySQL, Node.js, & Laravel applications. I was able to successfully setup & use Socialite for Google OAuth integration the problem is, I am unable to retrieve the Google Apps Company Directory variables from the standard setup with Socialite. The only details I can get are the standard, getId(); getNickname(); getName(); getEmail(); getAvatar();. I am looking to get SO MUCH more, such as the department the user belongs too, their manager, groups they belong too, phone, email, name, avatar, addresses, work phone, aliases, organization etc etc etc....Does anyone know of anyway to integrate Socialite with Google Apps? It doesn't need to be Socialite specifically, it can be a Google Apps specific OAuth solution, composer projects, etc...Anything at all! I hope someone out there has an anwser for me! I appreciate all your help in advance! If anyone needs clarification, examples, code snippets etc...let me know.

Thanks again! Zac

0 likes
1 reply
jplhomer's avatar

@zness21 Hey Zac,

It sounds like you're almost there - you just need to take an extra step to get the data you want!

I'd double check that you're indeed requesting the OAuth scopes required to traverse the Google Apps directory stuff: https://laravel.com/docs/5.5/socialite#access-scopes

Once the user has granted access, you'll get a $token variable you can use to make future requests using Google's own PHP SDK:

$user = Socialite::driver('google')->user();
$token = $user->token;

// TODO: Install google/api-client via Composer
$client = new Google_Client();
$client->setApplicationName("My Application");
$client->setDeveloperKey("MY_SIMPLE_API_KEY");
$client->setAccessToken($token);
$service = new Google_Service_Directory($client);
// use $service to access your directory

Google has more docs on their Getting Started guide here: https://developers.google.com/admin-sdk/directory/v1/quickstart/php

Please or to participate in this conversation.