Search code examples
microsoft-graph-api

Graph API - Is there a way to search for a user that has a mobile phone number set as his 2FA method?


So, I'd like to search for a user that has particular number set as his 2FA mobile phone?

Is that possible?


Solution

  • It's definitely not possible by one call. It requires more steps. The limitation is that you can't expand authentication relationship on user resource, so this query will not work

    GET /v1.0/users?$expand=authentication/phoneMethods
    

    You can use the report (requires AuditLog.Read.All permission) with a list of the authentication methods registered for users and filter users by registered methods

    GET /v1.0/reports/authenticationMethods/userRegistrationDetails?$filter=methodsRegistered/any(x:x eq 'mobilePhone')&$select=id,methodsRegistered
    

    Then iterate all users with phone method

    GET /v1.0/users/{user_id}/authentication/phoneMethods
    

    and check if the user has the phone number you are looking for.