<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Azure AD &#8211; Sibeesh Passion</title>
	<atom:link href="https://sibeeshpassion.com/tag/azure-ad/feed/" rel="self" type="application/rss+xml" />
	<link>https://sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Tue, 19 Oct 2021 14:39:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>Azure AD &#8211; Sibeesh Passion</title>
	<link>https://sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Change MFA Phone/Mobile Number Using PowerShell</title>
		<link>https://sibeeshpassion.com/change-mfa-phone-mobile-number-using-powershell/</link>
					<comments>https://sibeeshpassion.com/change-mfa-phone-mobile-number-using-powershell/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 19 Oct 2021 14:39:18 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Azure AD]]></category>
		<category><![CDATA[change mfa mobile number using powershell]]></category>
		<category><![CDATA[powershell]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=14494</guid>

					<description><![CDATA[Did you know that you can change the mobile number of a user from Azure AD, by using PowerShell? Here in this post, we will see how easy it is to change the user properties of an AD user.]]></description>
										<content:encoded><![CDATA[
<p>Did you know that you can change the mobile number of a user from Azure AD, by using PowerShell? Here in this post, we will see how easy it is to change the user properties of an AD user. To get started, we need to install the AzureAD module from the <a rel="noreferrer noopener" href="https://www.powershellgallery.com/packages/AzureAD/2.0.2.140" target="_blank">PowerShell Gallery</a> You can get more details about this module <a rel="noreferrer noopener" href="https://docs.microsoft.com/en-us/powershell/module/azuread/?view=azureadps-2.0&amp;WT.mc_id=AZ-MVP-5001828" target="_blank">here</a>. </p>



<pre class="wp-block-code"><code>Install-Module -Name AzureAD</code></pre>



<p>You will be prompted to accept the installation, give Yes or A. </p>



<pre class="wp-block-code"><code>Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'?
&#91;Y] Yes  &#91;A] Yes to All  &#91;N] No  &#91;L] No to All  &#91;S] Suspend  &#91;?] Help (default is "N"): A</code></pre>



<p>You can also check whether this module is installed or not by using the command <code>Get-Module AzureADPreview</code></p>



<p>Once you are done, it is time to connect to your Azure AD by using the command <code>Connect-AzureAD</code>. That will give you an output as in the preceding image. </p>



<figure class="wp-block-image size-large"><a href="/wp-content/uploads/2021/10/image.png"><img fetchpriority="high" decoding="async" width="1024" height="111" src="/wp-content/uploads/2021/10/image-1024x111.png" alt="" class="wp-image-14495" srcset="/wp-content/uploads/2021/10/image-1024x111.png 1024w, /wp-content/uploads/2021/10/image-300x33.png 300w, /wp-content/uploads/2021/10/image-768x83.png 768w, /wp-content/uploads/2021/10/image-1536x166.png 1536w, /wp-content/uploads/2021/10/image.png 1707w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>Connect-AzureAD Output</figcaption></figure>



<p>Now, use the command below to change the properties of your user. </p>



<pre class="wp-block-code"><code>Set-AzureADUser -ObjectId user1@domain.com -OtherMails @("user2@domain.com") -Mobile "+353 000000000" -TelephoneNumber "+353 000000000"</code></pre>



<p>You can also verify the changes by running the commands below. </p>



<pre class="wp-block-code"><code>Get-AzureADUser -ObjectID user@domain.com | select otherMails
Get-AzureADUser -ObjectID user@domain.com | select Mobile
Get-AzureADUser -ObjectID user@domain.com | select TelephoneNumber</code></pre>



<figure class="wp-block-image size-large"><a href="/wp-content/uploads/2021/10/image-1.png"><img decoding="async" width="1024" height="470" src="/wp-content/uploads/2021/10/image-1-1024x470.png" alt="" class="wp-image-14496" srcset="/wp-content/uploads/2021/10/image-1-1024x470.png 1024w, /wp-content/uploads/2021/10/image-1-300x138.png 300w, /wp-content/uploads/2021/10/image-1-768x353.png 768w, /wp-content/uploads/2021/10/image-1-1536x705.png 1536w, /wp-content/uploads/2021/10/image-1.png 1708w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>Get-AzureADUser Output</figcaption></figure>



<p>After you have changed your mobile number, verify the same when it is asked, and you should be able to Enable the Two-Step Verification on the <a href="https://mysignins.microsoft.com/security-info" target="_blank" rel="noreferrer noopener">Security Information page</a>. </p>



<figure class="wp-block-image size-large"><a href="/wp-content/uploads/2021/10/image-2.png"><img decoding="async" width="1024" height="231" src="/wp-content/uploads/2021/10/image-2-1024x231.png" alt="" class="wp-image-14497" srcset="/wp-content/uploads/2021/10/image-2-1024x231.png 1024w, /wp-content/uploads/2021/10/image-2-300x68.png 300w, /wp-content/uploads/2021/10/image-2-768x173.png 768w, /wp-content/uploads/2021/10/image-2-1536x347.png 1536w, /wp-content/uploads/2021/10/image-2-2048x462.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>Enable two-step verification</figcaption></figure>



<p></p>



<h1 class="wp-block-heading">References</h1>



<p><a href="https://docs.microsoft.com/en-us/azure/active-directory/authentication/howto-sspr-authenticationdata#use-powershell-version-2">https://docs.microsoft.com/en-us/azure/active-directory/authentication/howto-sspr-authenticationdata#use-powershell-version-2</a></p>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/change-mfa-phone-mobile-number-using-powershell/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Create Azure AD Application with Configurations Using PowerShell</title>
		<link>https://sibeeshpassion.com/create-azure-ad-application-with-configurations-using-powershell/</link>
					<comments>https://sibeeshpassion.com/create-azure-ad-application-with-configurations-using-powershell/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 08 Feb 2021 18:24:23 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Azure AD]]></category>
		<category><![CDATA[azure ad app powershell]]></category>
		<category><![CDATA[azure ad app registration]]></category>
		<category><![CDATA[azure ad app registration using powershell]]></category>
		<category><![CDATA[azure ad application permissions]]></category>
		<category><![CDATA[azure ad multi tenant users]]></category>
		<category><![CDATA[create azure ad app powershell]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=14315</guid>

					<description><![CDATA[There are different ways that you can create an Azure AD application aka Azure AD app registration. Sometimes, you may have to create it using the portal or by using PowerShell modules. Let's see how to create one using PowerShell.]]></description>
										<content:encoded><![CDATA[
<p>There are different ways that you can create an Azure AD application aka Azure AD app registration. Sometimes, you may have to create it using the portal or by using PowerShell modules. When you use PowerShell to do this, you can save the script and reuse the same in the future, one of the many advantages of using this approach is that it will help you remove human errors. Let&#8217;s see how we can do this. </p>



<h2 class="wp-block-heading">Creating Azure AD application </h2>



<p>Before we run the command to create the application, make sure that you have installed the AzureAD module. Open your PowerShell ISE with administrator access, and then type the preceding command. </p>



<pre class="wp-block-code"><code>PS C:\WINDOWS\system32&gt; Install-Module AzureAD</code></pre>



<p>This will install the module for you. You can see this in the modules list in the ISE. Click on the refresh button if you don&#8217;t see it.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/02/Install-AzureAD-Module.jpg"><img decoding="async" width="649" height="323" src="/wp-content/uploads/2021/02/Install-AzureAD-Module.jpg" alt="" class="wp-image-14316" srcset="/wp-content/uploads/2021/02/Install-AzureAD-Module.jpg 649w, /wp-content/uploads/2021/02/Install-AzureAD-Module-300x149.jpg 300w" sizes="(max-width: 649px) 100vw, 649px" /></a><figcaption>Install AzureAD Module</figcaption></figure></div>



<p>Now run the command &#8220;Connect-AzureAD&#8221; to connect to your Azure Account. If you have multiple directories with your account, then you must connect it with the tenant parameter. You can get the tenant id from the Tenant Properties window. Switch to the directory in the Azure Portal and search for the Tenant Properties in the search bar. Copy the Tenant ID from there and run it with the preceding command. </p>



<pre class="wp-block-code"><code>Connect-AzureAD -TenantId YourTenantIDHere</code></pre>



<p>Login again if you are asked again. And you are ready to run the command to create the AD application. </p>



<script src="https://gist.github.com/SibeeshVenu/776c866e848b686b02f0971cc8866695.js"></script>



<p>Here the parameter &#8220;-Oauth2AllowImplicitFlow&#8221; is to enable the OAuth flow and the -AvailableToOtherTenants is to make sure that my app is available to other tenants. You can see more options <a rel="noreferrer noopener" href="https://docs.microsoft.com/en-us/powershell/module/azuread/new-azureadapplication?WT.mc_id=AZ-MVP-5001828" target="_blank">here</a>. </p>



<p>If you are getting an error as &#8220;Message: Hostname in &#8216;http://&#8217; in property identifierUris is not on any verified domain of the company or its subdomain, make sure that you are giving the &#8220;$appUri&#8221; as your Azure AD primary domain or subdomain. You can get this value from the Azure AD applications overview window. </p>



<p>If you get an error as &#8220;Message: The URI scheme in property identifierUris is invalid or unsupported.&#8221;, make sure that you have included &#8220;http://&#8221; with your URI. </p>



<p>If you don&#8217;t see any other errors in your PowerShell, then it is more likely that the application is been created for, go to the Azure AD application registration page and see it yourself. In the overview page of your application, you can see that our application support multiple organization. If you go to the &#8220;Expose an API&#8221; section, that is where you can see your application ID URI configured. Make sure that you have created a service principal for your API application to use in the front end application. </p>



<p>It is also possible to create a secret of our Azure AD application using PowerShell, in one of my application it was required as I am using the Graph to fetch the users from multiple tenants with a Daemon user. You can read more about that <a rel="noreferrer noopener" href="https://sibeeshpassion.com/get-users-from-different-tenants-using-azure-ad-application-permission/" target="_blank">here</a>. Here is the command to add a secret. </p>



<pre class="wp-block-code"><code>$secret = New-AzureADApplicationPasswordCredential -ObjectId $myAdApp.ObjectId -CustomKeyIdentifier "GraphClientSecret"</code></pre>



<p>You can see the value of the secret if you just output the same. And later, you can save this value to your Azure Key Vault and read it in your application. By default, the end date of your secret will be 1 year, and if you want to change it, you need to provide the start date and end date in your command.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/02/AD-App-Secret-Expiry.jpg"><img decoding="async" width="642" height="324" src="/wp-content/uploads/2021/02/AD-App-Secret-Expiry.jpg" alt="" class="wp-image-14317" srcset="/wp-content/uploads/2021/02/AD-App-Secret-Expiry.jpg 642w, /wp-content/uploads/2021/02/AD-App-Secret-Expiry-300x151.jpg 300w" sizes="(max-width: 642px) 100vw, 642px" /></a><figcaption>AD App Secret Expiry</figcaption></figure></div>



<p>Now, this is how our updated script looks like. </p>



<script src="https://gist.github.com/SibeeshVenu/8e3181b6e32dab2fefc4c2b1e3b406d3.js"></script>



<p>I have one front end application and a backend api application, I need to make sure that the consent screen of the AD application shows the permission required of my backend application too. To do this, we have something called &#8220;-KnownClientApplications&#8221;, we can set this in our script to create the backend ad application. </p>



<p>Here is the entire PowerShell command.</p>



<script src="https://gist.github.com/SibeeshVenu/ea43ca7c4ce95fce204bb46137a3d02a.js"></script>



<p>What this will do its that,</p>



<ul class="wp-block-list"><li>Create an Azure AD application for the front end application</li><li>Create an Azure AD application for API application</li><li>Set both applications available to multiple tenants</li><li>Set the front end application to use OAuth flow</li><li>Add the Application ID of front end application to the KnownClientApplications of API application </li><li>Expose the API application and add an Application ID URL, that can be added as permission to the front end application</li><li>Create an application secret in the API application and set the expiry after 10 years</li></ul>



<p>If everything correct, then you should have the secret values shown in the PowerShell window. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/02/PowerShell-Result.jpg"><img decoding="async" width="1024" height="437" src="/wp-content/uploads/2021/02/PowerShell-Result-1024x437.jpg" alt="" class="wp-image-14318" srcset="/wp-content/uploads/2021/02/PowerShell-Result-1024x437.jpg 1024w, /wp-content/uploads/2021/02/PowerShell-Result-300x128.jpg 300w, /wp-content/uploads/2021/02/PowerShell-Result-768x328.jpg 768w, /wp-content/uploads/2021/02/PowerShell-Result.jpg 1144w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>PowerShell Result</figcaption></figure></div>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Congratulations and thanks a lot for being with me this far. Happy Coding!.</p>



<h2 class="wp-block-heading">About the Author</h2>



<p>I am yet another developer who is passionate about writing and video creation. I have written close to 500 blogs on my&nbsp;<a href="https://sibeeshpassion.com/" target="_blank" rel="noreferrer noopener">blog</a>. And I upload videos on my YouTube channels&nbsp;<a href="https://www.youtube.com/njanorumalayali" target="_blank" rel="noreferrer noopener">Njan Oru Malayali</a>&nbsp;and&nbsp;<a href="https://www.youtube.com/SibeeshPassion" target="_blank" rel="noreferrer noopener">Sibeesh Passion</a>. Please feel free to follow me.</p>



<ul class="wp-block-list"><li><a href="https://github.com/SibeeshVenu">GitHub</a></li><li><a href="https://medium.com/@sibeeshvenu">medium</a></li><li><a href="https://twitter.com/sibeeshvenu">Twitter</a></li></ul>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think is needed in this article? Could you find this post useful? Kindly do not forget to share your feedback.</p>



<p>Kindest Regards</p>



<p>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/create-azure-ad-application-with-configurations-using-powershell/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Get Users From Different Tenants Using Azure AD Application Permission</title>
		<link>https://sibeeshpassion.com/get-users-from-different-tenants-using-azure-ad-application-permission/</link>
					<comments>https://sibeeshpassion.com/get-users-from-different-tenants-using-azure-ad-application-permission/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 02 Feb 2021 17:37:17 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[azure active directory]]></category>
		<category><![CDATA[Azure AD]]></category>
		<category><![CDATA[azure ad app registration]]></category>
		<category><![CDATA[azure ad application permissions]]></category>
		<category><![CDATA[azure ad graph]]></category>
		<category><![CDATA[azure ad multi tenant users]]></category>
		<category><![CDATA[fetch users from multiple tenants]]></category>
		<category><![CDATA[get users from different tenants using graph]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[load users from different tenants]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=14294</guid>

					<description><![CDATA[In this post, we will see how we can get the users from different tenants using the Azure AD App registration with application permission]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Introduction</h2>



<p>Working with Microsoft Graph is fun, but it can get way too complex when the requirement is getting complex. Recently, I was working with such a requirement. I wanted to load users from different tenants, usually, this is too easy, and you just need an admin user in the tenant to load all the users using Graph API. But, in our case, there is no guarantee that the logged-in user is actually present in that tenant. And when the user tries to get the users from a different tenant, the Graph API returns an Unauthorized error, which is obvious and well handled.</p>



<p>So, we wanted something that can always perform these actions, no matter the logged-in user is present or not in the tenant given. I started with adding the Delegated permission to the Azure AD app registration, and in the end, the result was the same. Then I came to know about the application permission of Azure AD application registration and that sounded worth a try. </p>



<p>Here in this post, I will be sharing how did I achieve this requirement, it is not that problematic as it sounds. </p>



<h2 class="wp-block-heading">Azure AD Application Set Up</h2>



<p>Go to your Azure AD and select the App registration menu from the left pane. This will open the window where you can create and manage your app registrations.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/02/App-Registration-in-Azure-AD.jpg"><img decoding="async" width="651" height="495" src="/wp-content/uploads/2021/02/App-Registration-in-Azure-AD.jpg" alt="" class="wp-image-14295" srcset="/wp-content/uploads/2021/02/App-Registration-in-Azure-AD.jpg 651w, /wp-content/uploads/2021/02/App-Registration-in-Azure-AD-300x228.jpg 300w" sizes="(max-width: 651px) 100vw, 651px" /></a><figcaption>App Registration in Azure AD</figcaption></figure></div>



<p>When you are registering a new Azure AD application, make sure to select Multi-Tenant Support and give a redirect URL.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/02/Register-Multi-Tenant-AD-Application.jpg"><img decoding="async" width="650" height="551" src="/wp-content/uploads/2021/02/Register-Multi-Tenant-AD-Application.jpg" alt="" class="wp-image-14309" srcset="/wp-content/uploads/2021/02/Register-Multi-Tenant-AD-Application.jpg 650w, /wp-content/uploads/2021/02/Register-Multi-Tenant-AD-Application-300x254.jpg 300w" sizes="(max-width: 650px) 100vw, 650px" /></a><figcaption>Register Multi Tenant AD Application</figcaption></figure></div>



<p>Now let&#8217;s say that you have created your application and now open the application and click on the permission menu from the left-pane. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/02/Configured-Permission-Azure-AD.jpg"><img decoding="async" width="650" height="283" src="/wp-content/uploads/2021/02/Configured-Permission-Azure-AD.jpg" alt="" class="wp-image-14298" srcset="/wp-content/uploads/2021/02/Configured-Permission-Azure-AD.jpg 650w, /wp-content/uploads/2021/02/Configured-Permission-Azure-AD-300x131.jpg 300w" sizes="(max-width: 650px) 100vw, 650px" /></a><figcaption>Configured Permission Azure AD</figcaption></figure></div>



<p>As you can see that, all the permission types are Application, instead of the delegated ones. This will make sure that our application gets the privilege to act without a user, and will act as a Daemon user in the end. Please be careful in giving the application permissions as those are critical and should only be used when it is needed. So, just select only the permissions needed to complete your requirements. </p>



<p>Now, to make it work, we also need to set up a Client Secret in our application, which will then be used when we create a token. To do that, click on the Certificate &amp; Secrets menu from the left pane. And click on the +New client secret. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/02/Certificate-and-Secrets-in-Azure-AD.jpg"><img decoding="async" width="651" height="362" src="/wp-content/uploads/2021/02/Certificate-and-Secrets-in-Azure-AD.jpg" alt="" class="wp-image-14299" srcset="/wp-content/uploads/2021/02/Certificate-and-Secrets-in-Azure-AD.jpg 651w, /wp-content/uploads/2021/02/Certificate-and-Secrets-in-Azure-AD-300x167.jpg 300w" sizes="(max-width: 651px) 100vw, 651px" /></a><figcaption>Certificate and Secrets in Azure AD</figcaption></figure></div>



<p><strong>Remember to make a note of the secret as you will not be able to see the values later</strong>. Now that our application is ready for action, let us write some code. </p>



<h2 class="wp-block-heading">Code to Get Users from Multiple Tenants</h2>



<p>I do this in my .Net Core API application, and I have a module called Admin which does all the Admin related kinds of stuff. Here I have configured my application using a vertical layered architecture, thus this admin module is independent of any other features in our application. Having said that, let&#8217;s look at the code in AdminController. </p>



<script src="https://gist.github.com/SibeeshVenu/03faa0fc5efeea32d00732192db882bb.js"></script>



<p>As you can see that, nothing fancy there. Here I am just calling the method in the Admin Service and some error handlings. Let&#8217;s look at the code in the Admin Service. </p>



<script src="https://gist.github.com/SibeeshVenu/d0483db658f83d51053b70f4e07a8899.js"></script>



<p>Here I have some custom error handling and also I am doing some logic related to my requirement, but the important part here is&#8221; <em><code>var&nbsp;users&nbsp;=&nbsp;await&nbsp;_graphFacade.GetUsersUsingGraph(selectedTenant);</code></em>&#8221; Let&#8217; see that now. </p>



<script src="https://gist.github.com/SibeeshVenu/9f8ef9786d7ac321e0524b49d04641ab.js"></script>



<p>I am a fan of keeping things separate, and that is the reason why you are seeing a lot of separations here. I promise that there will only be one more. Here we have a GraphAuthService, and that is when I actually create the graph client and return the provider. Shall we see that now?</p>



<script src="https://gist.github.com/SibeeshVenu/821028ee794b70f893c7e3cab379a0fa.js"></script>



<p>Here we are creating a client credential provider with our tenant given and then create a graph client using that provider. Sounds good? We are getting all the other values from our configuration. In the non-development environment, I am loading the secret from a Key Vault, and for the development environment I load them using the secret.json file, I have already written a blog post about this, you can read it <a rel="noreferrer noopener" href="https://sibeeshpassion.com/why-not-secure-your-keys-and-secrets-asp-net-core-with-azure-key-vault-integration/" target="_blank">here</a>. </p>



<p>As per your need, you should select the authentication provider, <a rel="noreferrer noopener" href="https://docs.microsoft.com/en-us/graph/sdks/choose-authentication-providers?WT.mc_id=AZ-MVP-5001828&amp;tabs=CS" target="_blank">this post</a> will help you choose one. And we use this client in our façade service to get all the users. You have already seen that. Follow <a rel="noreferrer noopener" href="https://docs.microsoft.com/en-us/graph/sdks/sdk-installation?WT.mc_id=AZ-MVP-5001828" target="_blank">this link</a> to install all the dependencies, in short, install both &#8220;Microsoft. Graph&#8221; and &#8220;Microsoft.Graph.Auth&#8221; Nuget packages at least. </p>



<h2 class="wp-block-heading">Execution</h2>



<p>It is mandatory that you should have a UI application where an admin can grant access to our application, you can also prepare a URLS and sent it to your admin to give the consent, but the UI approach is more feasible. I have an application already that does this. Let&#8217;s run it now and see whether we are able to fetch the users from the different tenants or not. </p>



<p>In short, when the consent is given a new service principal of our application will be created in the tenant to which the admin is granted the consent. You can see this in the Enterprise application section in your Azure AD, check the left-side-pane. This is how the consent screen will look like.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/02/Azure-AD-Consent-Screen.jpg"><img decoding="async" width="500" height="919" src="/wp-content/uploads/2021/02/Azure-AD-Consent-Screen.jpg" alt="" class="wp-image-14303" srcset="/wp-content/uploads/2021/02/Azure-AD-Consent-Screen.jpg 500w, /wp-content/uploads/2021/02/Azure-AD-Consent-Screen-163x300.jpg 163w" sizes="(max-width: 500px) 100vw, 500px" /></a><figcaption>Azure AD Consent Screen</figcaption></figure></div>



<p>Now, as you can see that in the above image, whatever permission our application is requesting, is showing in the consent screen, and some admins will not give the consent if they see a lot of permissions there. This is the reason why it is important to choose the permissions that are needed. In my case, I have one Azure app for the front end and one for the backend, that is the reason why my backend application name is mentioned in the consent screen.</p>



<p>You can update the permissions of your application anytime you wish, and delete the consent given by going to the Enterprise application section in the Azure AD (remember that this is something that you do in the tenant where the application consent is given) and click on the Delete button in the Properties window. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/02/Deleting-Service-Principal-Created.jpg"><img decoding="async" width="1024" height="440" src="/wp-content/uploads/2021/02/Deleting-Service-Principal-Created-1024x440.jpg" alt="" class="wp-image-14312" srcset="/wp-content/uploads/2021/02/Deleting-Service-Principal-Created-1024x440.jpg 1024w, /wp-content/uploads/2021/02/Deleting-Service-Principal-Created-300x129.jpg 300w, /wp-content/uploads/2021/02/Deleting-Service-Principal-Created-768x330.jpg 768w, /wp-content/uploads/2021/02/Deleting-Service-Principal-Created-1536x659.jpg 1536w, /wp-content/uploads/2021/02/Deleting-Service-Principal-Created.jpg 1647w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>Deleting the Service Principal Created</figcaption></figure></div>



<p> Now I have updated my application API permission to use only &#8220;User.Read.All&#8221; permission and let&#8217;s see the consent screen now. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/02/App-Permissions-Consent-Screen-After-Update.jpg"><img decoding="async" width="500" height="869" src="/wp-content/uploads/2021/02/App-Permissions-Consent-Screen-After-Update.jpg" alt="" class="wp-image-14313" srcset="/wp-content/uploads/2021/02/App-Permissions-Consent-Screen-After-Update.jpg 500w, /wp-content/uploads/2021/02/App-Permissions-Consent-Screen-After-Update-173x300.jpg 173w" sizes="(max-width: 500px) 100vw, 500px" /></a><figcaption>App Permissions Consent Screen After Update</figcaption></figure></div>



<p>As my requirement is to fetch only the users, this would still work as it is and here are the debug screenshots to show you that this is actually working. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/02/Users-from-Tenant-1.jpg"><img decoding="async" width="801" height="209" src="/wp-content/uploads/2021/02/Users-from-Tenant-1.jpg" alt="" class="wp-image-14301" srcset="/wp-content/uploads/2021/02/Users-from-Tenant-1.jpg 801w, /wp-content/uploads/2021/02/Users-from-Tenant-1-300x78.jpg 300w, /wp-content/uploads/2021/02/Users-from-Tenant-1-768x200.jpg 768w" sizes="(max-width: 801px) 100vw, 801px" /></a><figcaption>Users from Tenant 1</figcaption></figure></div>



<div class="wp-block-image"><figure class="aligncenter size-large"><a href="/wp-content/uploads/2021/02/Users-from-Tenant-2.jpg"><img decoding="async" width="799" height="209" src="/wp-content/uploads/2021/02/Users-from-Tenant-2.jpg" alt="" class="wp-image-14302" srcset="/wp-content/uploads/2021/02/Users-from-Tenant-2.jpg 799w, /wp-content/uploads/2021/02/Users-from-Tenant-2-300x78.jpg 300w, /wp-content/uploads/2021/02/Users-from-Tenant-2-768x201.jpg 768w" sizes="(max-width: 799px) 100vw, 799px" /></a><figcaption>Users from Tenant 2</figcaption></figure></div>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Congratulations and thanks a lot for being with me this far. In this post, we have seen that how we can get the users from different tenants using the Azure AD App registration with application permission. Happy Coding!.</p>



<h2 class="wp-block-heading">About the Author</h2>



<p>I am yet another developer who is passionate about writing and video creation. I have written close to 500 blogs on my&nbsp;<a href="https://sibeeshpassion.com/" target="_blank" rel="noreferrer noopener">blog</a>. And I upload videos on my YouTube channels&nbsp;<a href="https://www.youtube.com/njanorumalayali" target="_blank" rel="noreferrer noopener">Njan Oru Malayali</a>&nbsp;and&nbsp;<a href="https://www.youtube.com/SibeeshPassion" target="_blank" rel="noreferrer noopener">Sibeesh Passion</a>. Please feel free to follow me.</p>



<ul class="wp-block-list"><li><a href="https://github.com/SibeeshVenu">GitHub</a></li><li><a href="https://medium.com/@sibeeshvenu">medium</a></li><li><a href="https://twitter.com/sibeeshvenu">Twitter</a></li></ul>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think is needed in this article? Could you find this post useful? Kindly do not forget to share your feedback.</p>



<p>Kindest Regards</p>



<p>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/get-users-from-different-tenants-using-azure-ad-application-permission/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Microsoft Partner Center DotNet Samples Secure App Model KeyVault Integration &#8211; Here is how it works</title>
		<link>https://sibeeshpassion.com/microsoft-partner-center-dotnet-samples-secure-app-model-keyvault-integration-here-is-how-it-works/</link>
					<comments>https://sibeeshpassion.com/microsoft-partner-center-dotnet-samples-secure-app-model-keyvault-integration-here-is-how-it-works/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Wed, 02 Dec 2020 13:38:20 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[AD Authentication]]></category>
		<category><![CDATA[Azure AD]]></category>
		<category><![CDATA[Microsoft Partner Center]]></category>
		<category><![CDATA[Microsoft Partner Center Key Vault Integration]]></category>
		<category><![CDATA[Microsoft Partner Center Samples]]></category>
		<category><![CDATA[Microsoft Partner Center Secure App Model Integration]]></category>
		<category><![CDATA[Microsoft Partner Center With Key Vault]]></category>
		<category><![CDATA[Microsoft Partner Center Working Sample]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=14259</guid>

					<description><![CDATA[Microsoft Partner Center DotNet Samples Secure App Model KeyVault Integration - Here is how it works. Sometimes following the document will not work, and I had to spend hours fixing the issues. That is the reason why I planned to write this post. I hope it will be helpful. ]]></description>
										<content:encoded><![CDATA[
<p>I recently had to work with the so-called Microsoft Partner Center Secure App Model with KeyVault integration, so I went through the <a href="https://github.com/microsoft/Partner-Center-DotNet-Samples" target="_blank" rel="noreferrer noopener">GitHub sample</a> provided and downloaded the same. As it was a completely new thing for me, I had to go through many documentation provided by Microsoft, for example, <a rel="noreferrer noopener" href="https://docs.microsoft.com/en-us/partner-center/develop/partner-center-authentication#net-appuser-authentication" target="_blank">this documentation</a> says about the Authentication, and that&#8217;s exactly what I wanted to try. Sometimes following the document will not work, and I had to spend hours fixing the issues. That is the reason why I planned to write this post. I hope it will be helpful. </p>



<h2 class="wp-block-heading">How does authentication work?</h2>



<p>Before we go and set up our application it is important that you should understand how the authentication mechanism works here. </p>



<p>There are two kinds of authentication in the Partner Center.</p>



<ol class="wp-block-list" type="1"><li>App-only, which will just be using the AD app we create.</li><li>App + User, that will require both app and the user context.</li></ol>



<p>Microsoft had created a new authentication model when we create App + User, which is the Secure application Model. This uses, multi-factor-authentication. This model is recommended and more secure, and with this approach, we can make sure that it supports all the operations as App-only authentication does not support some complex scenarios, for example, invoice operations.</p>



<p>We use a multi-tenant application and the initial registration for the application lives in the Host Azure AD tenant. When a user from a different tenant signs into the application for the first time, Azure AD asks for the consent and then a representation of the application (<strong>Service Principal</strong>) will be created in the user’s tenant.</p>



<p>This consent experience is based on the delegated permission we set in the app. And for us, it is important to give the appropriate permissions as we may have to act as the user. Below are the minimum set of permissions.</p>



<ol class="wp-block-list" type="1"><li>Azure Active Directory delegated permissions: Access the directory assigned user.</li><li>Partner Center APIs delegated permission: Access.</li></ol>



<p>Please be noted that you <strong>will not be able to configure this application with your account</strong>, <strong>even though you create a new tenant with your MPN account</strong>, as both Azure Active Directory and Microsoft Partner Center application must be present in your tenants, then only you will be able to give the delegated permissions.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="1024" height="784" src="/wp-content/uploads/2020/12/Azure-AD-App-with-Partner-Center-Permission-1024x784.jpg" alt="" class="wp-image-14261" srcset="/wp-content/uploads/2020/12/Azure-AD-App-with-Partner-Center-Permission-1024x784.jpg 1024w, /wp-content/uploads/2020/12/Azure-AD-App-with-Partner-Center-Permission-300x230.jpg 300w, /wp-content/uploads/2020/12/Azure-AD-App-with-Partner-Center-Permission-768x588.jpg 768w, /wp-content/uploads/2020/12/Azure-AD-App-with-Partner-Center-Permission-1536x1177.jpg 1536w, /wp-content/uploads/2020/12/Azure-AD-App-with-Partner-Center-Permission.jpg 1727w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Azure AD App with Partner Center Permission</figcaption></figure></div>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Read more about authentication <a rel="noreferrer noopener" href="https://docs.microsoft.com/en-us/partner-center/develop/enable-secure-app-model" target="_blank">here</a>. You can also download the <a href="https://assetsprod.microsoft.com/secure-application-model-guide.pdf">Secure Application Model framework</a> document. </p><cite>Partner Center Authentication &#8211; For better understanding!</cite></blockquote>



<h2 class="wp-block-heading">Configure the Partner Consent Application</h2>



<p>Once you clone <a href="https://github.com/microsoft/Partner-Center-DotNet-Samples" target="_blank" rel="noreferrer noopener">the repository</a> go to the secure-app-model folder in the root folder. Go to the folder <code>keyvault </code>and click on the solution file <code>PartnerConsent.sln</code>. Go to the <code>Web.config</code> file and that&#8217;s where all the configuration needs to be done. But if you working with the Partner Center for the first time, then things can be messy, it just won&#8217;t work. Let&#8217;s review the configuration one by one. </p>



<pre class="wp-block-code"><code>&lt;!-- AppID that represents CSP application -->
&lt;add key="ida:CSPApplicationId" value="ceec9e0d-d555-4472-952b-0ef9a77acba5 " /></code></pre>



<p>This one is easier, this is the ID of the application that you had created using your SandBox account or using your Primary Partner Account.  A <strong>Sandbox </strong>is for testing. No need to pay for the invoices, and will have a disclaimer “DO NOT PAY. THIS IS A SANDBOX INVOICE AND NO ACTION IS REQUIRED”.</p>



<p>Key things to consider:</p>



<ol class="wp-block-list" type="1"><li>Both accounts act independently and do not share the same accounts, customers, etc.</li><li>Supports transactions with a limited number of customers, orders, subscriptions, etc.</li></ol>



<p>To create an integration sandbox, click <a href="https://docs.microsoft.com/en-us/partner-center/develop/set-up-api-access-in-partner-center#create-an-integration-sandbox">here</a>.</p>



<p>Once you have your sandbox account is configured go to the <a rel="noreferrer noopener" href="https://partner.microsoft.com" target="_blank">https://partner.microsoft.com</a> and login with your Sandbox credential, click on the setting button on the right side of the page, and then click on the Account settings. Now from the left blade menu, click on the <strong>App management</strong>. This is where you actually create your application. You can create a Web App and Native App as per your requirement. If you are visiting this page for the first time, you will be given an option to create an application, and once that is done this is how it looks like. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="1024" height="720" src="/wp-content/uploads/2020/12/App-Management-in-Partner-Center-Sandbox-Account-1024x720.jpg" alt="" class="wp-image-14262" srcset="/wp-content/uploads/2020/12/App-Management-in-Partner-Center-Sandbox-Account-1024x720.jpg 1024w, /wp-content/uploads/2020/12/App-Management-in-Partner-Center-Sandbox-Account-300x211.jpg 300w, /wp-content/uploads/2020/12/App-Management-in-Partner-Center-Sandbox-Account-768x540.jpg 768w, /wp-content/uploads/2020/12/App-Management-in-Partner-Center-Sandbox-Account-1536x1081.jpg 1536w, /wp-content/uploads/2020/12/App-Management-in-Partner-Center-Sandbox-Account-2048x1441.jpg 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>App Management in Partner Center Sandbox Account</figcaption></figure></div>



<p>As you can see that every application has App ID, Account ID, Commerce ID, and Domain. Now copy the App ID of your application and paste it as the value of the key ida:CSPApplicationId in the web config file. </p>



<pre class="wp-block-code"><code>&lt;add key="ida:CSPApplicationSecret" value=".Gqs~Qhfdq8.eO-_6DtJrDNn32.VavwP_C208" /></code></pre>



<p>This is the key we generate for our application, and you can create it by clicking on the Add key button (please see the above image). <strong>Make sure to copy this value before you refresh the page</strong>. Now, if you go to your tenant (tenant you create the Partner Center app), you should see that there are applications registered for your Partner Center applications. Go to your Azure AD, and then click on App Registration from the left-side blade. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="1024" height="315" src="/wp-content/uploads/2020/12/App-Registration-in-Azure-AD-with-Partner-Center-1024x315.jpg" alt="" class="wp-image-14263" srcset="/wp-content/uploads/2020/12/App-Registration-in-Azure-AD-with-Partner-Center-1024x315.jpg 1024w, /wp-content/uploads/2020/12/App-Registration-in-Azure-AD-with-Partner-Center-300x92.jpg 300w, /wp-content/uploads/2020/12/App-Registration-in-Azure-AD-with-Partner-Center-768x236.jpg 768w, /wp-content/uploads/2020/12/App-Registration-in-Azure-AD-with-Partner-Center-1536x472.jpg 1536w, /wp-content/uploads/2020/12/App-Registration-in-Azure-AD-with-Partner-Center-2048x629.jpg 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>App Registration in Azure AD with Partner Center</figcaption></figure></div>



<p>Just to be clear, click on the application, and go to the API permissions from the left-side pane, you should see that some delegated permissions are given to the Azure Active Directory and Microsoft Partner Center.  Go to the Authentication page and add Redirect URI there, you can do this by clicking on the +Add platform button, from the next page select web and give the redirect URI, this is the URL of our MVC or .NET core application. For example, https://localhost:44395/. </p>



<p>Make sure that you add it correctly, even the trailing slash matters here. I was getting an error as &#8220;<em>&#8220;error&#8221;:&#8221;invalid_client&#8221;,&#8221;error_description&#8221;:&#8221;AADSTS500112: The reply address &#8216;<a href="https://localhost:44395/">https://localhost:44395/</a>&#8216; does not match the reply address &#8216;<a href="https://localhost:44395">https://localhost:44395</a>&#8216; provided when requesting Authorization code</em>.&#8221; </p>



<p>And if you don&#8217;t provide this reply URI, you will get an error &#8220;AADSTS500113: No reply address is registered for the application&#8221;</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="949" height="410" src="/wp-content/uploads/2020/12/No-reply-address-is-registered-for-the-application.jpg" alt="" class="wp-image-14265" srcset="/wp-content/uploads/2020/12/No-reply-address-is-registered-for-the-application.jpg 949w, /wp-content/uploads/2020/12/No-reply-address-is-registered-for-the-application-300x130.jpg 300w, /wp-content/uploads/2020/12/No-reply-address-is-registered-for-the-application-768x332.jpg 768w" sizes="(max-width: 949px) 100vw, 949px" /><figcaption>No reply address is registered for the application</figcaption></figure></div>



<pre class="wp-block-code"><code>&lt;!-- Endpoint address for the instance of Azure KeyVault -->
&lt;add key="KeyVaultEndpoint" value="https://my-access-key-vault.vault.azure.net" /></code></pre>



<p>You need a KeyVault to store your token, and you create one by using PowerShell or using a portal. If you are following <a rel="noreferrer noopener" href="https://docs.microsoft.com/en-us/partner-center/develop/partner-center-authentication#net-appuser-authentication" target="_blank">this document</a>, and prefer using PowerShell, make sure that you run all the steps as mentioned there. For now, let&#8217;s say that you had created the KeyVault and update the key KeyVaultEndpoint with the Vault URI, you can get this value from the Overview page of the Key Vault resource. </p>



<pre class="wp-block-code"><code>&lt;!-- AppID that is given access for keyvault to store the refresh tokens -->
&lt;add key="ida:KeyVaultClientId" value="e0d59487-585f-4b90-8ce1-f5f784246218" /></code></pre>



<p>This is the ID of the application that we are going to register in Azure AD. You can either create this with the PowerShell command or using the portal. </p>



<script src="https://gist.github.com/SibeeshVenu/fe68289a5f585ae2d99a29edc5808018.js"></script>



<p>Make sure you note down the Application ID and Application Secret. If you are using the portal to create this application, go to your Azure AD and click on the App registration blade from the left-side pan and click on the +New registration. As per your requirement, select the Account Type. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="1024" height="721" src="/wp-content/uploads/2020/12/AD-App-Registration-1024x721.jpg" alt="" class="wp-image-14266" srcset="/wp-content/uploads/2020/12/AD-App-Registration-1024x721.jpg 1024w, /wp-content/uploads/2020/12/AD-App-Registration-300x211.jpg 300w, /wp-content/uploads/2020/12/AD-App-Registration-768x541.jpg 768w, /wp-content/uploads/2020/12/AD-App-Registration-1536x1081.jpg 1536w, /wp-content/uploads/2020/12/AD-App-Registration.jpg 1649w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>AD App Registration</figcaption></figure></div>



<p>Once the application is created, we need to make sure that we give access to the Key Vault we created, so that this can get/post the token to the secret in our Key Vault. Copy the application ID and go to your Azure Key Vault and click on the Access Policy from the left-side pane. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="1024" height="371" src="/wp-content/uploads/2020/12/Key-Vault-Access-Policy-1024x371.jpg" alt="" class="wp-image-14267" srcset="/wp-content/uploads/2020/12/Key-Vault-Access-Policy-1024x371.jpg 1024w, /wp-content/uploads/2020/12/Key-Vault-Access-Policy-300x109.jpg 300w, /wp-content/uploads/2020/12/Key-Vault-Access-Policy-768x279.jpg 768w, /wp-content/uploads/2020/12/Key-Vault-Access-Policy.jpg 1494w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Key Vault Access Policy</figcaption></figure></div>



<p>Click on the +Add policy, and then select the <em>Secret management</em> from the <em>Configure from template</em> dropdown. Now click on the link &#8220;None Selected&#8221; near the service principal, and then paste the App ID of the Azure AD application we just created in the &#8220;Select a principal&#8221; screen. Click the add button <strong>make sure you click on the Save button on the next screen</strong>. You can also do this via PowerShell by following this command. </p>



<pre class="wp-block-code"><code>Set-AzureRmKeyVaultAccessPolicy -VaultName access-key-vault -ObjectId 296546541096da-acc2-4576-a4a2-47654a4389e45d7 -PermissionsToSecrets get
</code></pre>



<p>Here the ObjectId is the object ID of your Azure AD app. Make sure that you give enough permission, otherwise, you will get an error as follows. </p>



<p><strong>Operation returned an invalid status code &#8216;Forbidden&#8217;</strong></p>



<p>at Microsoft.Azure.KeyVault.KeyVaultClient.d__63.MoveNext()<br>at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)<br>at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)<br>at System.Runtime.CompilerServices.ConfiguredTaskAwaitable<code>1.ConfiguredTaskAwaiter.GetResult() at Microsoft.Azure.KeyVault.KeyVaultClientExtensions.&lt;SetSecretAsync&gt;d__46.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter</code>1.GetResult()</p>



<p>This is because there is no enough permission given in the access policy of our Key Vault. And also the access policy was showing as <strong>Unknown </strong>on the Access Policy page. I will be discussing this when we register our Azure AD application.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="1024" height="523" src="/wp-content/uploads/2020/12/Unknown-Policy-Azure-Key-Vault-1024x523.jpg" alt="" class="wp-image-14268" srcset="/wp-content/uploads/2020/12/Unknown-Policy-Azure-Key-Vault-1024x523.jpg 1024w, /wp-content/uploads/2020/12/Unknown-Policy-Azure-Key-Vault-300x153.jpg 300w, /wp-content/uploads/2020/12/Unknown-Policy-Azure-Key-Vault-768x392.jpg 768w, /wp-content/uploads/2020/12/Unknown-Policy-Azure-Key-Vault-1536x785.jpg 1536w, /wp-content/uploads/2020/12/Unknown-Policy-Azure-Key-Vault.jpg 1822w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Unknown Policy Azure Key Vault</figcaption></figure></div>



<pre class="wp-block-code"><code> &lt;add key="ida:KeyVaultClientSecret" value="Hewhfhu42Wz~Rs6UVna9-10.4lcdhdfh6krH-.TWK" />
</code></pre>



<p>You can create this secret for your Azure AD application via the portal or by using PowerShell. If you have created the AD application using the PowerShell command above, then you already have the secret value from the command <code>Write-Host "ApplicationSecret = $($password.Value)"</code>.</p>



<p>Go to your Azure AD application and click on the Certificates &amp; secrets menu from the left-side pane, and then click on the +New client secret button under the client secrets header. Copy the value and paste in the value of key &#8220;ida:KeyVaultClientSecret&#8221;. Make sure you don&#8217;t change the secret value, otherwise, you will get an error as &#8220;<strong>&#8220;error&#8221;:&#8221;invalid_client&#8221;,&#8221;error_description&#8221;:&#8221;AADSTS7000215: Invalid client secret is provided</strong>.&#8221;</p>



<p>If you are getting an error as <strong>&#8220;IDX10214: Audience validation failed. Audiences: &#8216;ceec9htdhe0d-d56564657-4472-952b&#8217;. Did not match: validationParameters.ValidAudience: &#8216;ceec6536463ef9a77acba5 &#8216; or validationParameters.ValidAudiences: &#8216;null&#8217;.&#8221;</strong>, you should add ValidAudiences in the OpenIdConnectAuthenticationOptions in ConfigureAuth method. </p>



<pre class="wp-block-code"><code>ValidAudiences = new List&lt;string>()
{
  "ceec9e0d-d557-6564-96542b-0ef9a6546acba5"
}</code></pre>



<p>Here the audience is the ID of the Azure AD web application that we created using the Partner Center (https://partner.microsoft.com). </p>



<p>Wow, that&#8217;s it. Now you have configured your partner consent application. It is time to run our project. If you have configured everything correctly, you should get a response as follows. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="552" height="288" src="/wp-content/uploads/2020/12/Partner-Consent-Successful.jpg" alt="" class="wp-image-14270" srcset="/wp-content/uploads/2020/12/Partner-Consent-Successful.jpg 552w, /wp-content/uploads/2020/12/Partner-Consent-Successful-300x157.jpg 300w" sizes="(max-width: 552px) 100vw, 552px" /><figcaption>Partner Consent Successful</figcaption></figure></div>



<p>Now, if you go and check your Azure Key Vault, you can see that there is a new secret created with our access token. </p>



<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img decoding="async" src="/wp-content/uploads/2020/12/Azure-Key-Vault-Access-Token-from-Partner-Center-687x1024.jpg" alt="" class="wp-image-14271" width="687" height="1024" srcset="/wp-content/uploads/2020/12/Azure-Key-Vault-Access-Token-from-Partner-Center-687x1024.jpg 687w, /wp-content/uploads/2020/12/Azure-Key-Vault-Access-Token-from-Partner-Center-201x300.jpg 201w, /wp-content/uploads/2020/12/Azure-Key-Vault-Access-Token-from-Partner-Center-768x1145.jpg 768w, /wp-content/uploads/2020/12/Azure-Key-Vault-Access-Token-from-Partner-Center-1030x1536.jpg 1030w, /wp-content/uploads/2020/12/Azure-Key-Vault-Access-Token-from-Partner-Center.jpg 1040w" sizes="(max-width: 687px) 100vw, 687px" /><figcaption>Azure Key Vault Access Token from Partner Center</figcaption></figure></div>



<p>Whenever the same user login to the application again, the Token will be refreshed in the Azure Key vault with a new version. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="1024" height="703" src="/wp-content/uploads/2020/12/Key-Vault-Token-Refresh-1024x703.jpg" alt="" class="wp-image-14274" srcset="/wp-content/uploads/2020/12/Key-Vault-Token-Refresh-1024x703.jpg 1024w, /wp-content/uploads/2020/12/Key-Vault-Token-Refresh-300x206.jpg 300w, /wp-content/uploads/2020/12/Key-Vault-Token-Refresh-768x527.jpg 768w, /wp-content/uploads/2020/12/Key-Vault-Token-Refresh.jpg 1049w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Key Vault Token Refresh</figcaption></figure></div>



<p>When you try with any other accounts outside of your tenant, they should be seeing a service principal of our Azure AD application in their Tenant. You can check this in the Enterprise Application page in the AD.</p>



<p>Please be also noted that if your Tenant Admin doesn&#8217;t grant permission to this application, you will get an error as &#8220;<strong>&#8220;error&#8221;:&#8221;invalid_grant&#8221;,&#8221;error_description&#8221;:&#8221;AADSTS65001: The user or administrator has not consented to use the application with ID</strong>&#8220;. This behavior is intended.</p>



<p>If you are trying to login with one of your tenants that don&#8217;t have the Partner Center App, then you will get an error as &#8220;<strong>OpenIdConnectMessage. An error was not null, indicating an error. Error: &#8216;access_denied&#8217;. Error_Description (may be empty): &#8216;AADSTS650052: The app needs access to a service (\&#8221;https://api.partnercenter.microsoft.com\&#8221;) that your organization \&#8221;50-865e-dd8763cd2cd4\&#8221; has not subscribed to or enabled. Contact your IT Admin to review the configuration of your service subscriptions.</strong>&#8220;. </p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="1024" height="490" src="/wp-content/uploads/2020/12/Azure-AD-Tenant-without-Partner-Center-App-1024x490.jpg" alt="" class="wp-image-14278" srcset="/wp-content/uploads/2020/12/Azure-AD-Tenant-without-Partner-Center-App-1024x490.jpg 1024w, /wp-content/uploads/2020/12/Azure-AD-Tenant-without-Partner-Center-App-300x143.jpg 300w, /wp-content/uploads/2020/12/Azure-AD-Tenant-without-Partner-Center-App-768x367.jpg 768w, /wp-content/uploads/2020/12/Azure-AD-Tenant-without-Partner-Center-App-1536x735.jpg 1536w, /wp-content/uploads/2020/12/Azure-AD-Tenant-without-Partner-Center-App.jpg 1886w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Azure AD Tenant without Partner Center App</figcaption></figure></div>



<p>This error is also intended. </p>



<h2 class="wp-block-heading">Debugging Tips</h2>



<p>While working with this application, I was getting a lot of errors, and the sad part was that the application was not throwing any errors, so I had to go place the debugger in almost all the places I could. And some errors were not having enough information too. To get detailed error information, I had to set &#8220;<code>IdentityModelEventSource.ShowPII = true</code>&#8221; in the COnfigureAuth method in the Startup.Auth.cs file. You <strong>should install the Nuget package &#8220;Microsoft.IdentityModel.Logging&#8221;</strong> to use this feature. </p>



<p>After that, I was getting detailed errors and I was just fixing errors one by one. And it took me quite a lot of time to make this application working, and that is the reason why I write this post. </p>



<p><strong>When you try with other accounts, make sure that MFA is configured for that account</strong>.  </p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Congratulations and thanks a lot for being with me this far. We now have a sample web application that has access to Azure AD, Partner Center, Azure Key Vault, and does the Authentication against a user. Please do not forget to share this post if you find it is useful. Happy Coding!.</p>



<h2 class="wp-block-heading">About the Author</h2>



<p>I am yet another developer who is passionate about writing and video creation. I have written close to 500 blogs on my&nbsp;<a href="https://sibeeshpassion.com/" target="_blank" rel="noreferrer noopener">blog</a>. And I upload videos on my YouTube channels&nbsp;<a href="https://www.youtube.com/njanorumalayali" target="_blank" rel="noreferrer noopener">Njan Oru Malayali</a>&nbsp;and&nbsp;<a href="https://www.youtube.com/SibeeshPassion" target="_blank" rel="noreferrer noopener">Sibeesh Passion</a>. Please feel free to follow me.</p>



<ul class="wp-block-list"><li><a href="https://github.com/SibeeshVenu">GitHub</a></li><li><a href="https://medium.com/@sibeeshvenu">medium</a></li><li><a href="https://twitter.com/sibeeshvenu">Twitter</a></li></ul>



<h2 class="wp-block-heading">Your turn. What do you think?</h2>



<p>Thanks a lot for reading. Did I miss anything that you may think is needed in this article? Could you find this post useful? Kindly do not forget to share your feedback.</p>



<p>Kindest Regards</p>



<p>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/microsoft-partner-center-dotnet-samples-secure-app-model-keyvault-integration-here-is-how-it-works/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
