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

usanzadunje's avatar

Socialite Microsoft Azure - Getting roles

Hello guys,

I know this is specific question but I am going out of resources which I tried. So the problem is following:

I am using oAuth from Azure with Socialite and custom driver for it from socialiteproviders/microsoft-azure package. Everything regarding authentication works fine but I have additional request and that is to check which roles this Azure user has.

  1. How can I obtain roles, I do not see any key in Azure user response which indicates roles.

  2. I have found from some sources that roles are actually stored in the token itself. I have used following code to decode body of a token:

$body = explode('.', $azureUser->token)[1];
$decoded = JWT::jsonDecode(JWT::urlsafeB64Decode($body));

But there is no key roles there. I am using campus account which I am not sure has roles added to it (I am no expert in Azure AD, sorry) and I also do not have access to add them which makes my problem a bit more difficult. But I wanted to know if roles key would be always present even if there are no roles, meaning it would be empty array or is it only returned when there are some actual values?

Thank you in advance, any help is appreciated.

0 likes
2 replies
nexxai's avatar

Why not set up an Azure account and create an Azure AD tenant to find out? Tenants are free (you do not need any premium licenses to set up a tenant) and you can then play around all you want.

usanzadunje's avatar

@nexxai I am unable to Manage Tenants(to create one). I tried creating application but I get 400 response from oAuth. Maybe I am doing something wrong :/

Please or to participate in this conversation.