{"id":3512,"date":"2016-12-12T00:27:07","date_gmt":"2016-12-12T08:27:07","guid":{"rendered":"http:\/\/www.cloudidentity.com\/blog\/?p=3512"},"modified":"2017-01-09T01:07:08","modified_gmt":"2017-01-09T09:07:08","slug":"from-tenantid-to-domain","status":"publish","type":"post","link":"https:\/\/www.cloudidentity.com\/blog\/2016\/12\/12\/from-tenantid-to-domain\/","title":{"rendered":"From TenantID to Domain"},"content":{"rendered":"<p>Few years ago I wrote <a href=\"https:\/\/www.cloudidentity.com\/blog\/2014\/11\/18\/from-domain-to-tenantid\/\">a post<\/a> about how you can obtain the ID of a tenant from one of its domains. Something so simple, and yet I am told that it ended up to be of use for lots of people. Yay!<\/p>\n<p>(BTW, at the time the root domain for Azure AD was <span style=\"font-family: Courier New;\">login.windows.net<\/span>, but now it is <span style=\"font-family: Courier New;\">login.microsoftonline.com<\/span>)<\/p>\n<p>I do often get asked how to do the inverse operation: given the tenantID, how do I determine the domain associated to it?<\/p>\n<p>Before we answer that question, we need to clarify things a bit. Whereas there\u2019s only one immutable, non-reassignable, gloriously opaque tenantID per tenant, every tenant can register a crazy number of domains. That said, only one of those is designated to be the default domain for the tenant. So, a better formulation would be: given the tenantID, how do I determine the <em>default<\/em> domain associated to it?<\/p>\n<p>As it turns out, I don\u2019t know of a way to do that without doing an authenticated call to the Microsoft Graph API. Luckily, it\u2019s all super straightforward. Here\u2019s what we need to do:<\/p>\n<ul>\n<li>get a token for the Microsoft Graph API in the target tenant<\/li>\n<li>retrieve the <span style=\"font-family: Courier New;\">organization<\/span> entity, by doing a GET against <a title=\"https:\/\/graph.microsoft.com\/v1.0\/organization\/\" href=\"https:\/\/graph.microsoft.com\/v1.0\/{tenantID}\/organization\/\">https:\/\/graph.microsoft.com\/v1.0\/{tenantID}\/organization\/<\/a>. Reference in <a title=\"https:\/\/graph.microsoft.io\/en-us\/docs\/api-reference\/v1.0\/resources\/organization\" href=\"https:\/\/graph.microsoft.io\/en-us\/docs\/api-reference\/v1.0\/resources\/organization\">https:\/\/graph.microsoft.io\/en-us\/docs\/api-reference\/v1.0\/resources\/organization<\/a><\/li>\n<li>once you have <span style=\"font-family: Courier New;\">organization <\/span>, scan its <span style=\"font-family: Courier New;\">verifiedDomains<\/span> collection to find the entry with default value set to true. Example below. The <span style=\"font-family: Courier New;\">name<\/span> property contains the value you seek.<\/li>\n<\/ul>\n<div id=\"codeSnippetWrapper\" style=\"font-size: 8pt; overflow: auto; cursor: text; font-family: 'Courier New', courier, monospace; width: 97.5%; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;\">\n<div id=\"codeSnippet\" style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\">\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum1\" style=\"color: #606060;\">   1:<\/span> {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum2\" style=\"color: #606060;\">   2:<\/span>  <span style=\"color: #006080;\">\"capabilities\"<\/span>: <span style=\"color: #006080;\">\"Email, OfficeCommunicationsOnline\"<\/span>,<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum3\" style=\"color: #606060;\">   3:<\/span>  <span style=\"color: #006080;\">\"isDefault\"<\/span>: <span style=\"color: #0000ff;\">true<\/span>,<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum4\" style=\"color: #606060;\">   4:<\/span>  <span style=\"color: #006080;\">\"isInitial\"<\/span>: <span style=\"color: #0000ff;\">true<\/span>,<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum5\" style=\"color: #606060;\">   5:<\/span>  <span style=\"color: #006080;\">\"name\"<\/span>: <span style=\"color: #006080;\">\"developertenant.onmicrosoft.com\"<\/span>,<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum6\" style=\"color: #606060;\">   6:<\/span>  <span style=\"color: #006080;\">\"type\"<\/span>: <span style=\"color: #006080;\">\"Managed\"<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum7\" style=\"color: #606060;\">   7:<\/span> }<\/pre>\n<p><!--CRLF--><\/p>\n<\/div>\n<\/div>\n<p>Clear as mud? here there\u2019s a magical ADAL snippet that will do the job for you.<\/p>\n<div id=\"codeSnippetWrapper\" style=\"font-size: 8pt; overflow: auto; cursor: text; font-family: 'Courier New', courier, monospace; width: 97.5%; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;\">\n<div id=\"codeSnippet\" style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\">\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum1\" style=\"color: #606060;\">   1:<\/span> <span style=\"color: #0000ff;\">static<\/span> <span style=\"color: #0000ff;\">void<\/span> Main(<span style=\"color: #0000ff;\">string<\/span>[] args)<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum2\" style=\"color: #606060;\">   2:<\/span> {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum3\" style=\"color: #606060;\">   3:<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum4\" style=\"color: #606060;\">   4:<\/span>     <span style=\"color: #008000;\">\/\/ put your tenantID here<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum5\" style=\"color: #606060;\">   5:<\/span>     <span style=\"color: #0000ff;\">string<\/span> tenantID = <span style=\"color: #006080;\">\"6c3d51dd-f0e5-4959-b4ea-a80c4e36fe5e\"<\/span>;<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum6\" style=\"color: #606060;\">   6:<\/span>     <span style=\"color: #0000ff;\">string<\/span> orgQuery = <span style=\"color: #0000ff;\">string<\/span>.Format(<span style=\"color: #006080;\">\"https:\/\/graph.microsoft.com\/v1.0\/{0}\/organization\/\"<\/span>, tenantID)<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum7\" style=\"color: #606060;\">   7:<\/span>     <span style=\"color: #0000ff;\">string<\/span> graphResource = <span style=\"color: #006080;\">\"https:\/\/graph.microsoft.com\"<\/span>;<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum8\" style=\"color: #606060;\">   8:<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum9\" style=\"color: #606060;\">   9:<\/span>     <span style=\"color: #008000;\">\/\/get a token to call the Microsoft Graph<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum10\" style=\"color: #606060;\">  10:<\/span>     AuthenticationContext ac =<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum11\" style=\"color: #606060;\">  11:<\/span>         <span style=\"color: #0000ff;\">new<\/span> AuthenticationContext(<span style=\"color: #0000ff;\">string<\/span>.Format(<span style=\"color: #006080;\">\"https:\/\/login.microsoftonline.com\/{0}\"<\/span>,tenantID));<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum12\" style=\"color: #606060;\">  12:<\/span>     AuthenticationResult ar = ac.AcquireTokenAsync(graphResource,<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum13\" style=\"color: #606060;\">  13:<\/span>         <span style=\"color: #006080;\">\"e11a0451-ac9d-4c89-afd8-d2fa3322ef68\"<\/span>,<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum14\" style=\"color: #606060;\">  14:<\/span>         <span style=\"color: #0000ff;\">new<\/span> Uri(<span style=\"color: #006080;\">\"http:\/\/li\"<\/span>),<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum15\" style=\"color: #606060;\">  15:<\/span>         <span style=\"color: #0000ff;\">new<\/span> PlatformParameters(PromptBehavior.Always)).Result;<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum16\" style=\"color: #606060;\">  16:<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum17\" style=\"color: #606060;\">  17:<\/span>     <span style=\"color: #008000;\">\/\/get the company info from the graph<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum18\" style=\"color: #606060;\">  18:<\/span>     HttpClient client = <span style=\"color: #0000ff;\">new<\/span> HttpClient();<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum19\" style=\"color: #606060;\">  19:<\/span>     HttpRequestMessage request = <span style=\"color: #0000ff;\">new<\/span> HttpRequestMessage(HttpMethod.Get, orgQuery);<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum20\" style=\"color: #606060;\">  20:<\/span>     request.Headers.Authorization =<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum21\" style=\"color: #606060;\">  21:<\/span>         <span style=\"color: #0000ff;\">new<\/span> System.Net.Http.Headers.AuthenticationHeaderValue(<span style=\"color: #006080;\">\"bearer\"<\/span>, ar.AccessToken);<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum22\" style=\"color: #606060;\">  22:<\/span>     HttpResponseMessage response = client.SendAsync(request).Result;<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum23\" style=\"color: #606060;\">  23:<\/span>     <span style=\"color: #0000ff;\">string<\/span> responseString = response.Content.ReadAsStringAsync().Result;<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum24\" style=\"color: #606060;\">  24:<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum25\" style=\"color: #606060;\">  25:<\/span>     <span style=\"color: #008000;\">\/\/retrieve the default domain for the tenant<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum26\" style=\"color: #606060;\">  26:<\/span>     JObject jo = JObject.Parse(responseString);<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum27\" style=\"color: #606060;\">  27:<\/span>     JArray domains = jo[<span style=\"color: #006080;\">\"value\"<\/span>][0][<span style=\"color: #006080;\">\"verifiedDomains\"<\/span>] <span style=\"color: #0000ff;\">as<\/span> JArray;<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum28\" style=\"color: #606060;\">  28:<\/span>     <span style=\"color: #0000ff;\">string<\/span> defaultDomain = <span style=\"color: #0000ff;\">string<\/span>.Empty;<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum29\" style=\"color: #606060;\">  29:<\/span>     <span style=\"color: #0000ff;\">foreach<\/span>(JObject domain <span style=\"color: #0000ff;\">in<\/span> domains)<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum30\" style=\"color: #606060;\">  30:<\/span>     {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum31\" style=\"color: #606060;\">  31:<\/span>         <span style=\"color: #0000ff;\">if<\/span> ((<span style=\"color: #0000ff;\">bool<\/span>)domain[<span style=\"color: #006080;\">\"isDefault\"<\/span>])<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum32\" style=\"color: #606060;\">  32:<\/span>         {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum33\" style=\"color: #606060;\">  33:<\/span>             defaultDomain = domain[<span style=\"color: #006080;\">\"name\"<\/span>].ToString();<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum34\" style=\"color: #606060;\">  34:<\/span>         }<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum35\" style=\"color: #606060;\">  35:<\/span>     }<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum36\" style=\"color: #606060;\">  36:<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum37\" style=\"color: #606060;\">  37:<\/span>     Console.WriteLine(<span style=\"color: #006080;\">\"The default domain for tenant {0} is {1}\"<\/span>, tenantID, defaultDomain);<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;\"><span id=\"lnum38\" style=\"color: #606060;\">  38:<\/span>     Console.ReadLine();<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: white; border-style: none; padding: 0px;\"><span id=\"lnum39\" style=\"color: #606060;\">  39:<\/span> }<\/pre>\n<p><!--CRLF--><\/p>\n<\/div>\n<\/div>\n<p>Now, I am sure that some of the Microsoft Graph experts will hasten to point out that instead of specifying the tenantID, I could use common and get <a title=\"https:\/\/graph.microsoft.com\/v1.0\/organization\/\" href=\"https:\/\/graph.microsoft.com\/v1.0\/organization\">https:\/\/graph.microsoft.com\/v1.0\/organization<\/a>, thus making the code more generic. Unfortunately, that\u2019s not a viable approach:<\/p>\n<ul>\n<li>If I already know a user UPN in the default domain, I already know the default domain \u2013 and the entire brouhaha becomes unnecessary. The approach might work and might be useful if I have access to a user whose UPN belongs to a NON-default domain verified for the tenantID, however it still falls short for the next point.<\/li>\n<li>If the user account I have access to for the tenantID happens to be a guest from a different tenant, the approach with common and no tenantID in the resource URI would yield the default domain of the ORIGIN tenant for the user, rather than the domain for the tenantID we are looking for.<\/li>\n<\/ul>\n<p>Well, there you have it. I asked to my peeps in the directory service if there\u2019s any simpler way to go about retrieving the default verified domain for a given tenantID, but I didn\u2019t hear back. The above isn\u2019t really that hard, it\u2019s just a GET and a big of JSON scavenging \u2013 but who knows, maybe there\u2019s some unauthenticated feed somewhere with the domain info. If I\u2019ll hear something in that sense, I\u2019ll update the post accordingly. Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Few years ago I wrote a post about how you can obtain the ID of a tenant from one of its domains. Something so simple, and yet I am told that it ended up to be of use for lots of people. Yay! (BTW, at the time the root domain for Azure AD&#8230;<\/p>\n","protected":false},"author":1,"featured_media":3517,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3512","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/3512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/comments?post=3512"}],"version-history":[{"count":2,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/3512\/revisions"}],"predecessor-version":[{"id":3523,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/3512\/revisions\/3523"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/media\/3517"}],"wp:attachment":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/media?parent=3512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/categories?post=3512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/tags?post=3512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}