Search code examples
laraveloauth-2.0laravel-socialitemicrosoft-oauth

How do I get a user's organization id when they login with Microsoft oauth?


I try to implement the microsoft auth into my application using Laravel Socialite, but since I'm working in a multi-tenant environment, I need to assign a user to a organisation. Is there anything such a microsoft organisation id or a domain name I can access in the docs? I'm unable to find it in the docs. Also I try to get the street, postal and city and wasn't able to access that as well, but this is not as critical as the company identifier.

I found this thread, but it handles over Google, so maybe the approach might be similar: How do I get a user's organization id when they login with Google oauth?

As I searched, I also found this docs, which seems to list all available fields of oauth: https://learn.microsoft.com/de-de/azure/active-directory/develop/id-tokens https://learn.microsoft.com/en-us/graph/auth-v2-user#4-use-the-access-token-to-call-microsoft-graph


Solution

  • According to this docs: https://learn.microsoft.com/en-gb/previous-versions/azure/ad/graph/howto/azure-ad-graph-api-permission-scopes you can add tenant details to the request including the id, display name and verified domains.