<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: amit17rajput</title>
    <description>The latest articles on DEV Community by amit17rajput (@amit17rajput).</description>
    <link>https://dev.to/amit17rajput</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1098283%2F76163dd1-b90c-47e0-b59c-810115b584fe.jpeg</url>
      <title>DEV Community: amit17rajput</title>
      <link>https://dev.to/amit17rajput</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amit17rajput"/>
    <language>en</language>
    <item>
      <title>Micro Frontends</title>
      <dc:creator>amit17rajput</dc:creator>
      <pubDate>Thu, 15 Jun 2023 10:38:35 +0000</pubDate>
      <link>https://dev.to/amit17rajput/angular-micro-frontends-architecture-39jh</link>
      <guid>https://dev.to/amit17rajput/angular-micro-frontends-architecture-39jh</guid>
      <description>&lt;p&gt;&lt;strong&gt;Angular Micro Frontends?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Angular Micro Frontends refers to an architectural pattern, involving the breaking down of a large Angular web application into small, independent, and deployable micro-applications with every micro-application being responsible for handling its own set of features.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The Angular Miocrofrontend architecture brings various benefits for the developers and product owners such as:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1. Multiple Tech Stacks can be used simultaneously&lt;/li&gt;
&lt;li&gt;2. Easy to Add/Update/Remove Code&lt;/li&gt;
&lt;li&gt;3. No code Sharing&lt;/li&gt;
&lt;li&gt;4. Single Page Applications or SPA look alike&lt;/li&gt;
&lt;li&gt;5. Easier Application Maintenance&lt;/li&gt;
&lt;li&gt;6. Improved Code Organization&lt;/li&gt;
&lt;li&gt;7. Simplified Development Process&lt;/li&gt;
&lt;li&gt;8. Efficient Debugging&lt;/li&gt;
&lt;li&gt;9. Better Team Co-ordination&lt;/li&gt;
&lt;li&gt;10. Enhanced Flexibility&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Angular Micro frontend Architecture vs Traditional architecture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How Microfrontend architecture is different from traditional architecture let us take a few instances:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Repository&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Traditional Architecture, the Application’s all Code/Modules/Pages/Functionality are kept/committed within a single Repository, While in Angular Micro Frontend Architecture it is not needed to keep all Code / Modules/Pages/Functionality within a same Repository.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technology&lt;/strong&gt;&lt;br&gt;
In a Traditional Architecture, all the Code / Modules/Pages/Functionality mostly shares the same technology i.e., Angular/PHP/JAVA/C#, etc. But for Micro Frontend Architecture this is not required anymore i.e., Page 1 can be of Angular, Page 2 Code can be of C#, etc.&lt;/p&gt;

&lt;p&gt;When the Application becomes larger, the initial loading time of the application also increases, and the ‘Waiting’ scenario does not give a good impression to the end user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implement the Micro Frontend Angular Architecture&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Iframe&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;The iframe is used to load nested /independent web pages along with the parent webpage.&lt;/li&gt;
&lt;li&gt;It is an HTML element and by specifying the desired URL in the tag we can load a different webpage and implement the Microfrontend Architecture&lt;/li&gt;
&lt;li&gt;As Iframe has its context and sharing data with a parent or other webpage becomes more difficult and all operation needs to be done using Global context and Objects i.e ‘Window ‘object of the browser and that makes the application more vulnerable.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;NGINX&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;NGINX is an Open-Source web server created for modern web applications to provide high performance and easy to maintain the routing of different applications if all applications are on the Same server.&lt;/li&gt;
&lt;li&gt;Based on the Config provided on file for matching route and landing page, The NGINX process the request.&lt;/li&gt;
&lt;li&gt;As the Config file is a text file only, it’s easy to add/update and remove the mapping of route and landing page details&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Third-party Libraries&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Many libraries are there to implement Angular Micro Frontend Architecture, below are the some of popular libraries:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Single-SPA&lt;/li&gt;
&lt;li&gt;Module-federation&lt;/li&gt;
&lt;li&gt;FrintJS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This library does not need to change existing code Or logic, It needs some wrapping code/config to enable Microfrontend Architecture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Step-by-Step Guide to Implementing Angular Micro Frontend Architecture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;From the different ways we discussed above, we will use ‘single-spa’ the popular and easy-to-implement library. Below is the Traditional / Existing Code structure that has different department-wise codes and is released independently and accessed via different URLs i.e&lt;br&gt;
test1.mydomain.com / test2.mydoamin.com / test3.mydomain.com&lt;/p&gt;

&lt;p&gt;Step 1: Create Root / Wrapper Application&lt;/p&gt;

&lt;p&gt;Install the Package:&lt;br&gt;
&lt;em&gt;npm install create-single-spa &amp;lt;-global&amp;gt;&lt;/em&gt;&lt;br&gt;
Run the below Command with Options at the root of the repository level:&lt;br&gt;
&lt;em&gt;create-single-spa&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here we are creating a wrapper application that will represent/wrap all different domain applications under a single Base URL, here we have used the “single-spa root config” option as the project already exists and we need to create only a wrapper.&lt;/p&gt;

&lt;p&gt;Note: This command will install node modules as well.&lt;br&gt;
The output of the above command will be:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Af0MSqQS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nuev7ujxe6cafitlgdau.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Af0MSqQS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nuev7ujxe6cafitlgdau.PNG" alt="Micro Frontend" width="800" height="697"&gt;&lt;/a&gt;&lt;br&gt;
One “root” folder will be created with some files that look like kind of config files along with common Angular files like tsconfig,package.json, etc.&lt;br&gt;
Let’s understand Each file in brief:&lt;br&gt;
bacancy-root-config.ts&lt;br&gt;
All the desired applications must be registered here along with their path (same as router config file of Angular module)&lt;br&gt;
The “index.ejs“ file loads this config file.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>angular</category>
      <category>designpatterns</category>
      <category>frontend</category>
    </item>
    <item>
      <title>OAuth vs JWT : What is the Different</title>
      <dc:creator>amit17rajput</dc:creator>
      <pubDate>Wed, 14 Jun 2023 12:53:13 +0000</pubDate>
      <link>https://dev.to/amit17rajput/oauth-vs-jwt-what-is-the-different-26jj</link>
      <guid>https://dev.to/amit17rajput/oauth-vs-jwt-what-is-the-different-26jj</guid>
      <description>&lt;p&gt;*&lt;em&gt;What Is JWT? *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;_JSON Web Tokens (JWT) are an open industry standard for sharing information between two entities, typically a client (the front end of an application) and a server (the back end of an application).&lt;br&gt;
A JWT contains a JSON object with information that needs to be shared. Additionally, each JWT is cryptographically signed, so that clients or malicious parties cannot modify JSON content (also known as JWT claims).&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;What Is OAuth? *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;_Open Authorization (OAuth) is an open standard for token-based authentication over public networks.&lt;br&gt;
OAuth allows third-party services such as Facebook and Google to use end-user account information without exposing the user’s account credentials to a third party. &lt;br&gt;
It acts as an intermediary on behalf of end users, providing access tokens to third-party services authorized to share certain account information. The process of obtaining a token is called the authorization flow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantage of JWT token:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;WT is preferred over any other authentication method because of certain distinct benefits it presents.  These tokens are self-contained and don’t ask for any effort to collect info about the user. &lt;/li&gt;
&lt;li&gt;Saves Developer efforts for database query generation or server authentication for every request. This saves a huge deal of time and effort.
&lt;/li&gt;
&lt;li&gt;JWTs are popular for better security and reliability that comes from their digitally signed nature. &lt;/li&gt;
&lt;li&gt;No explicit signing is allowed or needed, no outside source like a hacker or another client can access them.&lt;/li&gt;
&lt;li&gt;Using JWT asks for less digital storage space. They have generated servers and then forwarded them to the client who further stores them alongside attaching them to each most recent request.&lt;/li&gt;
&lt;li&gt;For verification, the job is easy with JWT as it won’t ask for extensive searching of the database.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Structure of JWT tokens: Header, Payload, Signature&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In case of environment that requires partial information transformation to any unverified user.&lt;/li&gt;
&lt;li&gt;In situation demands client-side information verification at the payload.&lt;/li&gt;
&lt;li&gt;For API and server-to-server authorization.&lt;/li&gt;
&lt;li&gt;JWT is best used whenever you want to transmit some information to an untrusted client, in such a way that that client can verify the information contained in the payload themselves.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Open Authorization (OAuth):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Protocol is known for allowing secured user authorization. Nothing like API or service, as OAuth is a globally-recognized standard which anyone throughout the world can use. Functional over HTTPS, it works wonderfully with servers, APIs, devices, and access-token-based applications.&lt;/li&gt;
&lt;li&gt;With the help of OAuth, apps can decide how to allow secure and controlled access to a use for a client app. It’s widely used in Java-based, web, mobile, and browser-based app development.&lt;/li&gt;
&lt;li&gt;OAuth 2.0 is the latest version of OAuth that works both ways, as a protocol and as a framework. It has fixed the bottleneck of early OAuth versions and promotes interoperability. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;*&lt;em&gt;Advantages of OAuth: *&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;One of the useful things about OAuth is that it enables you to delegate account access in a secure way without sharing credentials. Instead of credentials, OAuth relies on access tokens.&lt;/li&gt;
&lt;li&gt;Highly preferred and standardized authorization protocols. &lt;/li&gt;
&lt;li&gt;Compatible with most authentication services.&lt;/li&gt;
&lt;li&gt;Due to compatibility, the users will have ample OAuth plug-ins and feature options.
&lt;/li&gt;
&lt;li&gt;It makes client library testing in multiple languages and frameworks possible.
&lt;/li&gt;
&lt;li&gt;It’s best for code decoupling as the appl code isn’t hampered during auth code processing.&lt;/li&gt;
&lt;li&gt;It’s a highly secured protocol that has been tested extensively. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;JWT Vs OAuth:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;JWT is mainly used for APIs while OAuth can be used for web, browser, API, and various apps or resources. &lt;/li&gt;
&lt;li&gt;JWT defines a token format while OAuth deals in defining authorization protocols.&lt;/li&gt;
&lt;li&gt;JWT is simple and easy to learn from the initial stage while OAuth is complex.&lt;/li&gt;
&lt;li&gt;OAuth uses both client-side and server-side storage while JWT must use only client-side storage.&lt;/li&gt;
&lt;li&gt;JWT has limited scope and use cases. OAuth is highly flexible and can be easily used in a wide range of situations.&lt;/li&gt;
&lt;li&gt;Both can be used together for improved authentication. They are compatible with each other and work together towards secured data transmission.&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>JWT (JSON Web Token) authentication</title>
      <dc:creator>amit17rajput</dc:creator>
      <pubDate>Tue, 13 Jun 2023 07:17:01 +0000</pubDate>
      <link>https://dev.to/amit17rajput/jwt-json-web-token-authentication-2a2p</link>
      <guid>https://dev.to/amit17rajput/jwt-json-web-token-authentication-2a2p</guid>
      <description>&lt;p&gt;REST APIs are great because they are logically simple. They don’t keep complex states in memory, and they deal with resources instead of loose, unconnected functions, making their entire business logic cohesive.&lt;/p&gt;

&lt;p&gt;However, due to the nature and mechanics underlying ‘REST APIs, securing them is not always straightforward’. What happens after the user submits their credentials? You can’t keep a state on your server side to signal when a user has logged in on their subsequent requests, so how can you know that they’ve done so correctly?&lt;/p&gt;

&lt;p&gt;In this article, we’ll cover one very powerful yet simple way to secure a REST API using JSON Web Tokens (JWT), reviewing some best practices and implementing an example. Let’s get started!&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is a JWT?&lt;/li&gt;
&lt;li&gt;JSON Web Token structure&lt;/li&gt;
&lt;li&gt;How to use JWT to authenticate a REST API&lt;/li&gt;
&lt;li&gt;Securing a secret API: Example&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;What is a JWT?&lt;/strong&gt;&lt;br&gt;
JWT stands for JSON Web Token. It is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. JWTs are commonly used for authentication and authorization purposes in web applications and APIs.&lt;/p&gt;

&lt;p&gt;A JWT consists of three parts:&lt;/p&gt;

&lt;p&gt;Header: Contains metadata about the type of token and the signing algorithm used. It typically includes the token type (JWT) and the signing algorithm used, such as HMAC, RSA, or ECDSA.&lt;/p&gt;

&lt;p&gt;Payload: Contains the claims or statements about the user or entity being authenticated. Claims are represented as key-value pairs and can include standard claims (such as issuer, expiration time, subject, audience, etc.) as well as custom claims (additional information specific to your application).&lt;/p&gt;

&lt;p&gt;Signature: The signature is created by combining the encoded header, encoded payload, and a secret key known only to the server. The signature ensures the integrity of the token and allows the server to verify its authenticity.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aNMUbldd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dlbtye2qzmpi9ef3md2h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aNMUbldd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dlbtye2qzmpi9ef3md2h.png" alt="Image description" width="634" height="201"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JWT Process Diagram&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The process of using JWTs typically involves the following steps:&lt;/p&gt;

&lt;p&gt;Authentication: Upon successful authentication, the server generates a JWT and signs it with a secret key.&lt;/p&gt;

&lt;p&gt;Token Issuance: The server sends the JWT back to the client, usually as a response to a login request. The client then stores the JWT securely (e.g., in local storage, cookies, or other client-side storage mechanisms).&lt;/p&gt;

&lt;p&gt;Token Usage: The client includes the JWT in subsequent requests to the server by adding it to the request headers (e.g., Authorization header) or as a query parameter.&lt;/p&gt;

&lt;p&gt;Token Verification: On the server side, each incoming request is checked for the presence of a JWT. The server verifies the token's signature using the secret key to ensure its authenticity and integrity.&lt;/p&gt;

&lt;p&gt;Access Control: After verifying the JWT, the server extracts the claims from the payload and performs authorization checks to determine if the user has the necessary permissions to access the requested resource.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;structure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_hxbIRtT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/feb6blc3a9jmklnlhl0y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_hxbIRtT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/feb6blc3a9jmklnlhl0y.png" alt="Image description" width="310" height="163"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To use JWT for authenticating a REST API, you can follow these steps:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set up a JWT library: Choose a JWT library suitable for your programming language or framework. Install the library and any dependencies required.&lt;/li&gt;
&lt;li&gt;Generate a secret key: Create a secret key that will be used to sign and verify JWTs. This key should be kept secure and not shared publicly.&lt;/li&gt;
&lt;li&gt;User authentication: Implement a user authentication mechanism in your application. This could involve storing user credentials securely (such as hashed passwords) and providing a login endpoint for users to authenticate.&lt;/li&gt;
&lt;li&gt;Generate JWT upon successful authentication: When a user successfully logs in, generate a JWT containing the necessary claims (e.g., user ID, role, expiration time, etc.). Sign the JWT using the secret key.&lt;/li&gt;
&lt;li&gt;Protect API endpoints: Add authentication middleware or filters to protect your API endpoints. This middleware should validate the JWT included in the request's authorization header or query parameter.&lt;/li&gt;
&lt;li&gt;Verify JWT signature: On each incoming API request, extract the JWT from the request header or query parameter. Verify the JWT's signature using the secret key. If the signature is invalid, reject the request.&lt;/li&gt;
&lt;li&gt;Extract JWT claims: Once the JWT signature is verified, extract the claims from the JWT payload. These claims might include user ID, role, or any other relevant information.&lt;/li&gt;
&lt;li&gt;Implement authorization checks: Use the extracted claims to perform authorization checks and ensure that the user has the necessary permissions to access the requested resource. This could involve checking roles, scopes, or any other authorization criteria.&lt;/li&gt;
&lt;li&gt;Handling token expiration: If the JWT has an expiration time, handle token expiration properly. If a token has expired, return an appropriate response or provide a mechanism for users to refresh their tokens.&lt;/li&gt;
&lt;li&gt;Revoking tokens (optional): If you need the ability to revoke tokens (e.g., for implementing logout functionality), you can maintain a token blacklist or use token revocation mechanisms provided by some JWT libraries.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Workflow of JWT&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U-LO-RRx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uth6wmt61zjw4i7la04q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U-LO-RRx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uth6wmt61zjw4i7la04q.png" alt="Image description" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By leveraging JWTs, you can achieve stateless authentication, eliminate the need for session storage, and scale your application effectively. However, it's important to follow best practices for token handling, keep the secret key secure, and thoroughly test your implementation to ensure its security and reliability.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
