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

mariaquinn156's avatar

Microsoft Graph/Azure Socialite - additional user fields

Hi,

I've installed Microsoft Azure socialite package on my Laravel (9) project and have successfully gotten authentication with our Azure AD up and running. The user fields I am getting back are the default ones, e.g.: businessPhones": [ "" ], "displayName": "", "givenName": "", "jobTitle": "", "mail": "", "mobilePhone": "", "officeLocation": "", "preferredLanguage": "", "surname": "", "userPrincipal Name": "", "id": ""

I'm looking to bring in user fields other than the default ones, e.g. department. I've done a lot of googling but have found nothing specific to the azure socialite package with Laravel 9. Has anyone done this before and can help? Maybe there's an easy way to do it that I've missed. Please help :)

Thanks, M

0 likes
3 replies
OussamaMater's avatar

This has nothing to do with "Socialite".

I never worked with Azure, but I am sure you created an application to get the secret key and the app key, in that application's settings you'll find something like "scopes", there you can tick whatever permissions and fields you want in return, keep in mind that anything you tick there will be shown to the user when they're asking his permission to authorize your application.

If you don't have the scopes options then there's nothing much you can do.

My answer is based on the other providers I worked with like Github, Facebook, Google.

mariaquinn156's avatar

Hi,

Thanks for the speedy response, but I believe it does have something to do with socialite. I have given my app permissions to user.read.

See below which is on the Microsoft website under the Microsoft Graph topic:

For work or school accounts, the full profile includes all of the declared properties of the User resource. On reads, only a limited number of properties are returned by default. To read properties that are not in the default set, use $select. The default properties are:

displayName givenName jobTitle mail mobilePhone officeLocation preferredLanguage surname userPrincipalName

From the above I understand that I need to send in a list of fields I would like to receive because at the minute I am just receiving the default, which I'm sure is enough in most cases. I am just not sure if there is an easy way for me to send in the fields. It looks like you can do something like ->fields(['department', 'jobDescription'])->user(); in older versions of Laravel with other socialite providers but this isn't the case with the Azure one.

Thanks, Maria

OussamaMater's avatar

@mariaquinn156 I see, to be honest I still don't agree that "Socialite" have something to do with the returned response, and note well that these fields can be null, so if a user is not providing a jobTitle for example, it won't be present in the response, so in your testing making sure that the account having all the wanted fields correctly set and re-test, if they're not present I don't really know what's the reasons, all my encounters with the kind of scenarios always was related to the "scopes".

Please or to participate in this conversation.