Search code examples
azure-ad-b2cazure-ad-b2c-custom-policy

How to find a user in B2C by ProxyAddresses?


I'm trying to register a user in azure B2C, but I can't because another object with the property ProxyAddresses already exists. The problem is that when I try to find this user, it does not exist. Is there a way to find out which user is assigned whit this ProxyAddresses?

enter image description here


Solution

  • To find a user in B2C by proxyAddresses, you can make use of below Microsoft Graph API call:

    GET https://graph.microsoft.com/beta/users?$filter=proxyAddresses/any(x:x+eq+'SMTP:{email}')
    

    In my case, I ran below query in Graph Explorer by signing in with B2C user consenting User.Read.All permission and got response like this:

    GET https://graph.microsoft.com/beta/users?$filter=proxyAddresses/any(x:x+eq+'SMTP:[email protected]')&$select=id,displayName,proxyAddresses
    

    Response:

    enter image description here

    You can get the same results by running below MS Graph PowerShell commands:

    Connect-MgGraph -Scope "User.Read.All"
    
    Import-Module Microsoft.Graph.Beta.Users
    Get-MgBetaUser -Filter  "proxyAddresses/any(x:x eq 'SMTP:[email protected]')" -Property "id,displayName,proxyAddresses"
    

    Response:

    enter image description here