{"id":115,"date":"2024-02-25T09:16:29","date_gmt":"2024-02-25T09:16:29","guid":{"rendered":"https:\/\/blog.fubuha.com\/?p=115"},"modified":"2024-06-17T05:48:35","modified_gmt":"2024-06-17T05:48:35","slug":"azure-app-registration-role-w-aplikacji-spa-2-2","status":"publish","type":"post","link":"https:\/\/blog.fubuha.com\/index.php\/2024\/02\/25\/azure-app-registration-role-w-aplikacji-spa-2-2\/","title":{"rendered":"Azure App Registration &#8211; roles in react SPA (2\/2)"},"content":{"rendered":"\r\n<p><a href=\"https:\/\/blog.fubuha.com\/index.php\/2023\/11\/04\/azure-app-registration-role-w-aplikacji-spa-1-2\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Part 1<\/a><\/p>\r\n\r\n\r\n\r\n<p><br>We continue the implementation of a free and robust authentication and access control mechanism in the SPA application, namely Azure App Registration. In this post, we will use the previously created app registration to create a working demo. Let&#8217;s move directly to the example described in the Microsoft documentation. <a href=\"https:\/\/github.com\/Azure-Samples\/ms-identity-javascript-react-tutorial\/tree\/main\/5-AccessControl\/1-call-api-roles#step-2-install-express-web-api-dependencies\" target=\"_blank\" rel=\"noopener\" title=\"\">LINK<\/a>.<\/p>\r\n\r\n\r\n\r\n<p><br>To start running the example, you should begin by preparing your runtime environment. Here are the steps outlined in the documentation:<\/p>\r\n\r\n\r\n\r\n<p>Preinstaled <a href=\"https:\/\/nodejs.org\/en\/download\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Node.js<\/a> (server javascript) \/ installed <a href=\"https:\/\/git-scm.com\/downloads\" target=\"_blank\" rel=\"noopener\" title=\"\">GIT<\/a> <br>(tool for working with code repositories) \/ Modern web browser. This example uses ES6 conventions. The tutorial suggests using VS Code, but you can manage without it. We start by downloading the project, so create a new folder on drive C (creating a folder on the desktop may cause problems) and enter &#8216;cmd&#8217; in the address bar to open the console.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"489\" height=\"159\" src=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/1.png\" alt=\"\" class=\"wp-image-116\" style=\"width:327px;height:auto\" srcset=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/1.png 489w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/1-300x98.png 300w\" sizes=\"(max-width: 489px) 100vw, 489px\" \/><\/figure>\r\n\r\n\r\n\r\n<p><br>After launching the console, we enter the command:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>git clone https:\/\/github.com\/Azure-Samples\/ms-identity-javascript-react-tutorial.git<\/code><\/pre>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1111\" height=\"306\" src=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/2-1024x282.png\" alt=\"\" class=\"wp-image-117\" srcset=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/2-1024x282.png 1024w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/2-300x83.png 300w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/2-768x212.png 768w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/2.png 1111w\" sizes=\"(max-width: 1111px) 100vw, 1111px\" \/><\/figure>\r\n\r\n\r\n\r\n<p><br>Now, we execute the commands (confirming each line with Enter).<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>cd ms-identity-javascript-react-tutorial\r\ncd 5-AccessControl\\1-call-api-roles\\SPA\r\nnpm install<\/code><\/pre>\r\n\r\n\r\n\r\n<p><br>Installing all dependencies may take a while, and upon completion, we should see the following message:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/4-1024x576.png\" alt=\"\" class=\"wp-image-118\" srcset=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/4-1024x576.png 1024w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/4-300x169.png 300w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/4-768x432.png 768w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/4.png 1113w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\r\n\r\n\r\n\r\n<p><br>Now, in the file explorer, open the file authConfig.js (path is \\ms-identity-javascript-react-tutorial\\5-AccessControl\\1-call-api-roles\\API) and fill it out based on the app registration done in part 1 of the blog. Save the changes.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"581\" src=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/5-1024x581.png\" alt=\"\" class=\"wp-image-119\" style=\"width:950px;height:auto\" srcset=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/5-1024x581.png 1024w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/5-300x170.png 300w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/5-768x436.png 768w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/5.png 1455w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\r\n\r\n\r\n\r\n<p><br>Next, move on to edit the second file authConfig.js (path \\ms-identity-javascript-react-tutorial\\5-AccessControl\\1-call-api-roles\\SPA\\src\\authConfig.js) and fill it out with data from the app registration, and of course, save the changes.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1915\" height=\"871\" src=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/6-1024x466.png\" alt=\"\" class=\"wp-image-120\" style=\"width:1063px;height:auto\" srcset=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/6-1024x466.png 1024w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/6-300x136.png 300w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/6-768x349.png 768w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/6-1536x699.png 1536w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/6.png 1915w\" sizes=\"(max-width: 1915px) 100vw, 1915px\" \/><\/figure>\r\n\r\n\r\n\r\n<p>At this point, we are ready to launch the sample application. We have two applications: one Frontend (React) and the other Backend (Node.js server). We go to the directory created at the beginning of the blog:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>\/\/FRONTEND\r\ncd ms-identity-javascript-react-tutorial\r\ncd 5-AccessControl\\1-call-api-roles\\SPA\r\nnpm start<\/code><\/pre>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/7-1024x576.png\" alt=\"\" class=\"wp-image-121\" srcset=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/7-1024x576.png 1024w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/7-300x169.png 300w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/7-768x432.png 768w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/7.png 1113w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>\/\/FRONTEND\r\ncd ms-identity-javascript-react-tutorial\r\ncd 5-AccessControl\\1-call-api-roles\\SPA\r\nnpm start<\/code><\/pre>\r\n\r\n\r\n\r\n<p><br>The application should start automatically; if not, launch the browser and enter the address <a href=\"http:\/\/localhost:3000\/\">http:\/\/localhost:3000\/<\/a>. The next step is to start the backend application:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>\/\/BACKEND\r\ncd ms-identity-javascript-react-tutorial\r\ncd 5-AccessControl\\1-call-api-roles\\API\r\nnpm install\r\nnpm start<\/code><\/pre>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/9-1024x576.png\" alt=\"\" class=\"wp-image-123\" srcset=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/9-1024x576.png 1024w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/9-300x169.png 300w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/9-768x432.png 768w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/9.png 1113w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\r\n\r\n\r\n\r\n<p><br>At this point, we have a working example of authentication using SPA application registration in Microsoft Entra, in which the data embedded in the authorization token are detailed. A detailed description of the functionalities implemented in the example and a discussion of the source codes can be found in the Microsoft documentation. <a href=\"https:\/\/github.com\/Azure-Samples\/ms-identity-javascript-react-tutorial\/tree\/main\/5-AccessControl\/1-call-api-roles#step-2-install-express-web-api-dependencies\" target=\"_blank\" rel=\"noopener\" title=\"\">Microsoft<\/a> .<\/p>\r\n\r\n\r\n\r\n<p>The topic is extensive and complex, but it is an excellent starting point for building your own application with authentication and roles defined in Microsoft Entra.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"491\" src=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/8-1024x491.png\" alt=\"\" class=\"wp-image-122\" srcset=\"https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/8-1024x491.png 1024w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/8-300x144.png 300w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/8-768x368.png 768w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/8-1536x736.png 1536w, https:\/\/blog.fubuha.com\/wp-content\/uploads\/2023\/11\/8.png 1912w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\r\n","protected":false},"excerpt":{"rendered":"<p>Part 1 We continue the implementation of a free and robust authentication and access control mechanism in the SPA application, namely Azure App Registration. In this post, we will use the previously created app registration to create a working demo. Let&#8217;s move directly to the example described in the Microsoft documentation. LINK. To start running&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"om_disable_all_campaigns":false,"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[2],"tags":[8,10,15,16,14,13,6,12],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.fubuha.com\/index.php\/wp-json\/wp\/v2\/posts\/115"}],"collection":[{"href":"https:\/\/blog.fubuha.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fubuha.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fubuha.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fubuha.com\/index.php\/wp-json\/wp\/v2\/comments?post=115"}],"version-history":[{"count":4,"href":"https:\/\/blog.fubuha.com\/index.php\/wp-json\/wp\/v2\/posts\/115\/revisions"}],"predecessor-version":[{"id":151,"href":"https:\/\/blog.fubuha.com\/index.php\/wp-json\/wp\/v2\/posts\/115\/revisions\/151"}],"wp:attachment":[{"href":"https:\/\/blog.fubuha.com\/index.php\/wp-json\/wp\/v2\/media?parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fubuha.com\/index.php\/wp-json\/wp\/v2\/categories?post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fubuha.com\/index.php\/wp-json\/wp\/v2\/tags?post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}