<?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>web development services &gt; Metasys Software Pvt Ltd.</title>
	<atom:link href="https://www.metasyssoftware.com/tag/web-development-services/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.metasyssoftware.com</link>
	<description>Unique People, Unique Solutions</description>
	<lastBuildDate>Tue, 04 Jun 2024 11:37:50 +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>https://www.metasyssoftware.com/wp-content/uploads/2023/10/metasys-svg-.png</url>
	<title>web development services &gt; Metasys Software Pvt Ltd.</title>
	<link>https://www.metasyssoftware.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Web API security using JSON web tokens</title>
		<link>https://www.metasyssoftware.com/others/custom-software-web-api-security-using-json-web-tokens/</link>
					<comments>https://www.metasyssoftware.com/others/custom-software-web-api-security-using-json-web-tokens/#respond</comments>
		
		<dc:creator><![CDATA[meta_prasad]]></dc:creator>
		<pubDate>Fri, 24 Jul 2020 08:10:54 +0000</pubDate>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[Custom Software solutions]]></category>
		<category><![CDATA[web application development]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Web designing and application development]]></category>
		<category><![CDATA[Web API]]></category>
		<category><![CDATA[Web tokens]]></category>
		<category><![CDATA[Offshore web developement services]]></category>
		<category><![CDATA[Offshore web development]]></category>
		<category><![CDATA[web development services]]></category>
		<guid isPermaLink="false">https://www.metasyssoftware.com/?p=3121</guid>

					<description><![CDATA[<p>Today data security during financial transactions is super important and critical. The protection of sensitive user data should be a [&#8230;]</p>
The post <a href="https://www.metasyssoftware.com/others/custom-software-web-api-security-using-json-web-tokens/">Web API security using JSON web tokens</a> appeared first on <a href="https://www.metasyssoftware.com">Metasys Software Pvt Ltd.</a>.]]></description>
										<content:encoded><![CDATA[<div id="pl-3362"  class="panel-layout" ><div id="pg-3362-0"  class="panel-grid panel-no-style" ><div id="pgc-3362-0-0"  class="panel-grid-cell" ><div id="panel-3362-0-0-0" class="so-panel widget widget_sow-editor panel-first-child panel-last-child" data-index="0" ><div
			
			class="so-widget-sow-editor so-widget-sow-editor-base"
			
		>
<div class="siteorigin-widget-tinymce textwidget">
	<p>Today data security during financial transactions is super important and critical. The protection of sensitive user data should be a major priority for developers working on applications that use financial or personal information of the clients.</p>
<p>These days, many apps are accessed through multiple devices including desktops, laptops, mobile phones and tablets. Both web apps, and native apps can use web APIs for accessing data and providing services. This article addresses the topic of ensuring client security of a web API during the development phase. I will share my experience with using JSON web tokens (JWT) to ensure security of a representational state transfer (REST) web API.</p>
<h2>There are a two simpler alternatives to JWT that I will briefly mention first:</h2>
<ol>
<li>
<h3><strong>Basic authentication:<br />
</strong></h3>
<p>This method is very easy to implement. A username and password is passed and validated in a database to identify legitimate users. Since the username and password are sent as plain text, every request is very susceptible to cross-site request forgery (CSRF). The security can be improved somewhat by passing the details in the headers section of the web API instead of the URL, nevertheless this method is not very secure as it does not involve any encryption.</p>
</li>
<li>
<h3><strong>API keys:<br />
</strong></h3>
<p>This technique is used to overcome the drawbacks of basic authentication. In this method, a unique key is assigned every time the user signs in indicating that the user is known. A user can use the same key to re-enter the system. The security issue with this method is that the key can easily be picked up during network transmission. Often, the key is passed as a query string in the URL, making it easier for someone to compromise the security of the web API.</p>
</li>
</ol>
<p>JWT avoids the security flaws of the two simpler methods, by providing a bearer token authentication of the Web API. With this method, the user name and password validates, whether, the user exists in the system. Information about the validated user like name, email address and UserID can be fetched. These items are included in the ‘claim’. Claims are pieces of information about a user that have been packaged and signed into security tokens.</p>
<p>A JWT token consists of three parts, the header, the payload and the signature.</p>
<p><strong>Header</strong> – Contains the type of token and signing algorithm used</p>
<p><strong>Payload</strong> – Contains the issuer of the claim, the subject of the claim and the audience, which refers to the intended recipient of the claim. Other information can also be included, such as an expiry time of the token, or additional user information.</p>
<p><strong>Signature</strong> –Contains the encoded header, encoded payload and a secret key</p>
<h2>Implementation</h2>
<p>To give you more details about JWT implementation, I’ll be going through the steps I took to implement JWT in my web API. First I created a web API project in .Net core 2.2. Next I installed two packages via npm of visual studio, using the following commands:</p>
<ul>
<li><strong>Install-Package System.IdentityModel.Tokens.Jwt -Version 5.6.0</strong></li>
<li><strong>Install-Package Microsoft.AspNetCore.Authentication.JwtBearer -Version 3.1.0</strong></li>
</ul>
<p>In the appsetting.json file, I added my JWT keys including the secret key, issuer, subject and audience as follows:</p>
<p><img decoding="async" class="alignnone wp-image-3122 size-full" title="JWT keys" src="/wp-content/uploads/2024/05/web-api-security-2024.jpg" alt="JWT keys" width="294" height="105" /></p>
<p>Next, I registered a JWT authentication schema by using the "AddAuthentication" method and specifying JwtBearerDefaults.AuthenticationScheme. in the ConfigureServices section of the start-up class.</p>
<p><img fetchpriority="high" fetchpriority="high" decoding="async" class="alignnone wp-image-3123 size-full" title="JWT Authentication Schema" src="https://stage.metasyssoftware.com/wp-content/uploads/Image2.png" alt="JWT Authentication Schema" width="996" height="420" /></p>
<p>I also added app.UseAuthentication() in the configure method of the startup class.</p>
<p><img decoding="async" class="alignnone wp-image-3124 size-full" title="UseAuthenticationConfiguration" src="https://stage.metasyssoftware.com/wp-content/uploads/Image3.png" alt="UseAuthenticationConfiguration" width="683" height="104" /></p>
<p>Next, I created a token controller in the web API. This token controller action GetApiToken took the two input parameters: Username and Password, and validated these details against the database. Once the user is validated, I generated a token using the secret key, claims information and signing credentials.</p>
<p><img loading="lazy" loading="lazy" decoding="async" class="alignnone wp-image-3125 size-full" title="TokenControlerInfo" src="https://stage.metasyssoftware.com/wp-content/uploads/Image4.png" alt="TokenControlerInfo" width="744" height="378" /></p>
<p>The generated token was then stored as an item in sessionStorage.</p>
<p>For all my web API requests, I used the following key in the header section of each Ajax web API  call request.</p>
<p><img loading="lazy" loading="lazy" decoding="async" class="alignnone wp-image-3126 size-full" title="AjaxCallWithBearerToken" src="https://stage.metasyssoftware.com/wp-content/uploads/Image5.png" alt="AjaxCallWithBearerToken" width="586" height="137" /></p>
<p>Finally, I applied the <strong>[Authorize]</strong> attribute to my controller to which I was calling the web API.</p>
<p><img loading="lazy" loading="lazy" decoding="async" class="alignnone wp-image-3127 size-full" title="AuthorizeAttribute" src="https://stage.metasyssoftware.com/wp-content/uploads/Image6.png" alt="AuthorizeAttribute" width="541" height="175" /></p>
<p>These were all the steps I required to implement JWT authentication in my Web API. The tokens are encrypted, so they are difficult to tamper with. They expire at specific intervals and are cryptographically signed using a cryptographic algorithm.</p>
<p><img loading="lazy" loading="lazy" decoding="async" class="alignnone wp-image-3128 size-full" title="AjaxCallRequestHeaders" src="https://stage.metasyssoftware.com/wp-content/uploads/Image7.png" alt="AjaxCallRequestHeaders" width="808" height="216" /></p>
<p>The final implementation step is to remove the generated token item which was stored in sessionStorage when a user logs out of the system.</p>
<p><img loading="lazy" loading="lazy" decoding="async" class="alignnone size-full wp-image-3129" src="https://stage.metasyssoftware.com/wp-content/uploads/Image8.png" alt="LogoutInfo" width="469" height="95" /></p>
<p>MetaSys has extensive expertise in building secure web APIs for web applications. Our team has experience in building custom software solutions for clients across different industry verticals. Please feel free to contact us if you are in need of a partner to build a secure web API.  For more info, visit our website: <a href="https://www.metasyssoftware.com/dot-net">https://www.metasyssoftware.com/dot-net</a>.</p>
</div>
</div></div></div></div></div>The post <a href="https://www.metasyssoftware.com/others/custom-software-web-api-security-using-json-web-tokens/">Web API security using JSON web tokens</a> appeared first on <a href="https://www.metasyssoftware.com">Metasys Software Pvt Ltd.</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.metasyssoftware.com/others/custom-software-web-api-security-using-json-web-tokens/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
