title: OWIN OpenIdConnect Single Sign On with Office 365
body: <p>I have managed to do single sign on over Azure Active Directory with OpenIdConnect middleware:</p>
  
  <pre><code>app.UseOpenIdConnectAuthentication(
      new OpenIdConnectAuthenticationOptions
      {
          AuthenticationMode = AuthenticationMode.Passive,
          ClientId = "{guid}",
          Authority = "https://login.microsoftonline.com/common/",
  
          TokenValidationParameters = new TokenValidationParameters
          {
              ValidateIssuer = false
          }
      });
  </code></pre>
  
  <p>We use multi-tenant application on Azure and based on the <code>tenantid</code> on the returned token check whether this user is allowed (check <code>tenantid</code> from our database whether it comes from our trusted clients).</p>
  
  <p>It works perfectly fine, if client would like to do single sign on with our application. They have to sync their users to azure active directory and configure their <code>tenantid</code> on our application.</p>
  
  <p>The thing is, assume that some clients actually have Office 365. They already sync their company user accounts to Office 365 and they would like to take advantage user accounts on Office 365 and do single sign on with this.</p>
  
  <p>I know Office 365 is built on top of Azure, and I can configure to make our application works with our company user accounts by getting the office 365 <code>tenantid</code> (the way I got from code debugging):</p>
  
  <p><img src="https://i.stack.imgur.com/7MvM9.png" alt="enter image description here"></p>
  
  <p>But one thing I am not sure is the Office 365 <code>tenantid</code> will be different between companies right, example: both company A and company B uses Office 365, so the office 365 <code>tenantid</code> is different between company A and company B?</p>
  
  <p>If yes, how to get <code>tenantid</code> from Office 365 (not debugging like I did).</p>
  
  <p>Also, please advise if this way does not work with Office 365 Single Sign On.</p>