<?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: Mohammad Saddan Hussain</title>
    <description>The latest articles on DEV Community by Mohammad Saddan Hussain (@hussaincode).</description>
    <link>https://dev.to/hussaincode</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%2F819014%2F11982ba5-a817-4c84-b941-bb6c875c9d01.jpeg</url>
      <title>DEV Community: Mohammad Saddan Hussain</title>
      <link>https://dev.to/hussaincode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hussaincode"/>
    <language>en</language>
    <item>
      <title>How to host a website on GitHub with custom domain</title>
      <dc:creator>Mohammad Saddan Hussain</dc:creator>
      <pubDate>Fri, 23 Dec 2022 11:27:03 +0000</pubDate>
      <link>https://dev.to/hussaincode/how-to-host-a-website-on-github-with-custom-domain-58ca</link>
      <guid>https://dev.to/hussaincode/how-to-host-a-website-on-github-with-custom-domain-58ca</guid>
      <description>&lt;p&gt;In this article, we are going to learn how we can host a website on a GitHub page with a custom domain name.&lt;/p&gt;

&lt;p&gt;I will upload my portfolio website on GitHub step by step.&lt;/p&gt;

&lt;p&gt;First of all, we need to code your website and collect all the file and upload it to the GitHub repository.&lt;/p&gt;

&lt;p&gt;If you don't know how to upload your code to the GitHub repository then let me know in the comment section, and I will write an article on the same.&lt;/p&gt;

&lt;p&gt;Once the code is uploaded to the GitHub repository, Goto the same repository as shown in the below screenshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fno46atxdgyk5apfnvbqb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fno46atxdgyk5apfnvbqb.png" alt=" " width="800" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above screenshot, we can see a lot of repositories are there. I am going to upload myPortfolio website so I will click on the same.&lt;/p&gt;

&lt;p&gt;Once we will click on the repository that we want to upload we will get to see a setting icon as shown in the below screenshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs12nk5scbxxialmc2x20.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs12nk5scbxxialmc2x20.png" alt=" " width="800" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After clicking on the setting, we will find a section on the left side call pages. we will on that as shown in the below screenshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1gr50pa3mu112zsqhnpz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1gr50pa3mu112zsqhnpz.png" alt=" " width="800" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we click on pages, we will see a source, we need to click on the dropdown and select "Deploy from a branch" as shown in the below screenshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp1ijj4lnmrlqex4zm01q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp1ijj4lnmrlqex4zm01q.png" alt=" " width="800" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that, we need to select the branch as the main and the folder as /(root) as shown in the below screenshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3kk9so5hhtrgtg9b8228.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3kk9so5hhtrgtg9b8228.png" alt=" " width="800" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After selecting the branch and folder, we will save it.&lt;/p&gt;

&lt;p&gt;Once it's saved, we will go to our GitHub account settings as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F725813o5n0lwojuyppm7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F725813o5n0lwojuyppm7.png" alt=" " width="800" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we will click on the pages on the left side as shown in the below screenshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe6n8yzvb87wklml0mrst.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe6n8yzvb87wklml0mrst.png" alt=" " width="800" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we click on pages, we will see a button called add a domain. we will click on that button as shown in the below screenshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1b5s5oxwjwao168dtpaf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1b5s5oxwjwao168dtpaf.png" alt=" " width="800" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After clicking on Add a domain button, we will see a field where we need to give the custom domain name that we would have purchased from GoDaddy or any other domain name provider.&lt;/p&gt;

&lt;p&gt;In my case, I have purchased from GoDaddy and my custom domain name is hussaincode.in so, I have given the same name as shown in the below screenshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8pt03obdjp30f4zhsy8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8pt03obdjp30f4zhsy8.png" alt=" " width="800" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And then we can click on "Add a domain" button as shown above.&lt;/p&gt;

&lt;p&gt;Once we will click on Add a domain button we will get some DNS TXT records as shown in the below screenshot that we need to add to our domain name provider like in my case on GoDaddy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmmvy8wohxticlg8gr1ed.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmmvy8wohxticlg8gr1ed.png" alt=" " width="800" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will copy this hostname and TXT record value and will go to our domain name provider and find the domain name DNS record.&lt;/p&gt;

&lt;p&gt;First, we will go to the GoDaddy website and log in through our id and click on my product as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbk9lh4sk3xj1dpc6svgm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbk9lh4sk3xj1dpc6svgm.png" alt=" " width="800" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we will go to the DNS of our domain name that we want to set up on the GitHub page as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faoszfbgc926tcpeolf26.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faoszfbgc926tcpeolf26.png" alt=" " width="800" height="373"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we click on DNS, we will find all the DNS records. In that record, we need to add the TXT record as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw7csrfwg63kwtyowm5c2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw7csrfwg63kwtyowm5c2.png" alt=" " width="800" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After clicking on add, we need to select the TXT record and put the hostname and its value that we copied from the GitHub TXT record during adding a domain.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkwg9a50ds5l765qrgrse.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkwg9a50ds5l765qrgrse.png" alt=" " width="800" height="339"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once it's done we will save it and look for the CNAME record in the DNS if it's there we need to edit it and if it's not there we need to add the CNAME record and give the value as "hussaincode.github.io" where hussaincode is my username, you can check your username from your GitHub profile and change it accordingly.&lt;/p&gt;

&lt;p&gt;Select all the values same as shown below just change the hussaincode with your username.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4qyeid6ipwap1t9l5p8w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4qyeid6ipwap1t9l5p8w.png" alt=" " width="800" height="151"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will check all the values if it's correct we will save them and then we will look for the "A" record in the DNS and give the value from this GitHub documentation as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2jr8wl1liizzppt7u29o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2jr8wl1liizzppt7u29o.png" alt=" " width="800" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that, we will save this and come back to our repository settings again and will go to the pages.&lt;/p&gt;

&lt;p&gt;And then at last we can see the custom domain field is there, we will give our custom domain name in that field and save it as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqfwt6q2j4j8065dn3byw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqfwt6q2j4j8065dn3byw.png" alt=" " width="800" height="362"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It will show as a DNS check in progress. We will wait for some time and it will show as the DNS check is successful as shown below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9k1fw7nz7gy2dc28aq96.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9k1fw7nz7gy2dc28aq96.png" alt=" " width="800" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once DNS is successful, our website will go live. we can check on our custom domain our website will be up and running.&lt;/p&gt;

&lt;p&gt;In my case, my site hussaincode.in is up and running as shown in the below screenshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F42qezbeh6jnwlqqv7bba.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F42qezbeh6jnwlqqv7bba.png" alt=" " width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hurray, Our site is up and running using GitHub pages without and hosting coast.&lt;/p&gt;

&lt;p&gt;If you have any doubt or get stuck at any point, comment it and I will try to help as much as possible.&lt;/p&gt;

&lt;p&gt;Thank you all for reading this article, Hope it helps.&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>hosting</category>
    </item>
    <item>
      <title>Most Commonly Asked DSA Question in Interview - 2022</title>
      <dc:creator>Mohammad Saddan Hussain</dc:creator>
      <pubDate>Mon, 28 Feb 2022 07:17:55 +0000</pubDate>
      <link>https://dev.to/hussaincode/most-commonly-asked-dsa-question-in-interview-2022-51g5</link>
      <guid>https://dev.to/hussaincode/most-commonly-asked-dsa-question-in-interview-2022-51g5</guid>
      <description>&lt;h1&gt;
  
  
  Most Commonly Asked DSA Question in Interview - 2022
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://hashnode.com/@hussaincode" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hashnode.com/@hussaincode" rel="noopener noreferrer"&gt;Hussain Code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;·&lt;a href="https://hussaincodes.in/most-commonly-asked-dsa-question-in-interview-2022" rel="noopener noreferrer"&gt;Feb 18, 2022&lt;/a&gt;·&lt;/p&gt;

&lt;p&gt;7 min read&lt;/p&gt;

&lt;p&gt;Subscribe to my newsletter and never missmy upcoming articles&lt;/p&gt;

&lt;p&gt;Subscribe&lt;/p&gt;

&lt;h3&gt;
  
  
  Table of contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;1) What is Data Structure?&lt;/li&gt;
&lt;li&gt;2) What are the applications of Data Structure?&lt;/li&gt;
&lt;li&gt;3) Tell us about linked list.&lt;/li&gt;
&lt;li&gt;4) Give us one advantage of linked list?&lt;/li&gt;
&lt;li&gt;5) What is the difference between PUSH and POP?&lt;/li&gt;
&lt;li&gt;6) Where is data structure majorly used?&lt;/li&gt;
&lt;li&gt;7) Are linked lists considered linear or non-linear data structures?&lt;/li&gt;
&lt;li&gt;8) What do you mean by LIFO?&lt;/li&gt;
&lt;li&gt;9) What are the various operations that can be performed on different Data Structures?&lt;/li&gt;
&lt;li&gt;10) Which Data Structure Should be used for implementing LRU cache?&lt;/li&gt;
&lt;li&gt;11)  What are the advantages of Linked List over an array?&lt;/li&gt;
&lt;li&gt;12) Tell us something about binary trees.&lt;/li&gt;
&lt;li&gt;15) What exactly do you mean by merge sort?&lt;/li&gt;
&lt;li&gt;16) What is the least number of nodes that a binary tree can have?&lt;/li&gt;
&lt;li&gt;17) What are the scenarios in which an element can be inserted into the circular queue?&lt;/li&gt;
&lt;li&gt;
18) What do you know about stack?

&lt;ul&gt;
&lt;li&gt;
19) What is a dequeue?
&lt;/li&gt;
&lt;li&gt;
20) Define the graph data structure?
&lt;/li&gt;
&lt;li&gt;
21) Which data structures are used in BFS and DFS algorithm?
&lt;/li&gt;
&lt;li&gt;22) What are the applications of Graph data structure?&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;The tech interview stage of a job requires a thorough preparation before you can impress the interviewer. Right from knowing everything about the technical subject to apprising the interviewers about your previous achievements and projects, you are required to do everything that can convince them about your knowledge and skills.&lt;/p&gt;

&lt;p&gt;In this article, we have prepared a list of most frequently asked Data Structure interview questions and answers.&lt;/p&gt;

&lt;h3&gt;
  
  
  1) What is Data Structure?
&lt;/h3&gt;

&lt;p&gt;Data structure is a fundamental concept of any programming language, essential for algorithmic design.&lt;br&gt;
It is used for the efficient organization and modification of data.&lt;br&gt;
DS is how data and the relationship amongst different data is represented, that aids in how efficiently various functions or operations or algorithms can be applied.&lt;/p&gt;

&lt;h3&gt;
  
  
  2) What are the applications of Data Structure?
&lt;/h3&gt;

&lt;p&gt;Data structures form the core foundation of software programming as any efficient algorithm to a given problem is dependent on how effectively a data is structured.&lt;/p&gt;

&lt;p&gt;Identifiers look ups in compiler implementations are built using hash tables.&lt;br&gt;
The B-trees data structures are suitable for the databases implementation.&lt;/p&gt;

&lt;p&gt;Some of the most important areas where data structures are used are as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Artificial intelligence&lt;/li&gt;
&lt;li&gt;Compiler design&lt;/li&gt;
&lt;li&gt;Machine learning&lt;/li&gt;
&lt;li&gt;Database design and management&lt;/li&gt;
&lt;li&gt;Blockchain&lt;/li&gt;
&lt;li&gt;Numerical and Statistical analysis&lt;/li&gt;
&lt;li&gt;Operating system development&lt;/li&gt;
&lt;li&gt;Image &amp;amp; Speech Processing&lt;/li&gt;
&lt;li&gt;Cryptography&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  3) Tell us about linked list.
&lt;/h3&gt;

&lt;p&gt;A linked list can be defined as a chain of nodes wherein each node is connected to the next one.&lt;/p&gt;

&lt;h3&gt;
  
  
  4) Give us one advantage of linked list?
&lt;/h3&gt;

&lt;p&gt;One inherent advantage of linked list is that it is very easy to modify irrespective of the number of elements that are there in the list.&lt;/p&gt;

&lt;h3&gt;
  
  
  5) What is the difference between PUSH and POP?
&lt;/h3&gt;

&lt;p&gt;PUSH and POP operations specify how data is stored and retrieved in a stack.&lt;/p&gt;

&lt;p&gt;PUSH: PUSH specifies that data is being "inserted" into the stack.&lt;/p&gt;

&lt;p&gt;POP: POP specifies data retrieval. It means that data is being deleted from the stack.&lt;/p&gt;

&lt;h3&gt;
  
  
  6) Where is data structure majorly used?
&lt;/h3&gt;

&lt;p&gt;Simplistically speaking, data structures are involved in all areas when data is engaged. Some of the prominent areas where it is applied are artificial intelligence, database management, statistical analysis, etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  7) Are linked lists considered linear or non-linear data structures?
&lt;/h3&gt;

&lt;p&gt;A linked list is considered both linear and non-linear data structure depending upon the situation.&lt;/p&gt;

&lt;p&gt;On the basis of data storage, it is considered as a non-linear data structure.&lt;br&gt;
On the basis of the access strategy, it is considered as a linear data-structure.&lt;/p&gt;

&lt;h3&gt;
  
  
  8) What do you mean by LIFO?
&lt;/h3&gt;

&lt;p&gt;LIFO stands for Last In First Out. It means that the data which was stored last would be the first one to be extracted.&lt;/p&gt;

&lt;h3&gt;
  
  
  9) What are the various operations that can be performed on different Data Structures?
&lt;/h3&gt;

&lt;p&gt;Insertion ? Add a new data item in the given collection of data items.&lt;br&gt;
Deletion ? Delete an existing data item from the given collection of data items.&lt;br&gt;
Traversal ? Access each data item exactly once so that it can be processed.&lt;br&gt;
Searching ? Find out the location of the data item if it exists in the given collection of data items.&lt;br&gt;
Sorting ? Arranging the data items in some order i.e. in ascending or descending order in case of numerical data and in dictionary order in case of alphanumeric data.&lt;/p&gt;

&lt;h3&gt;
  
  
  10) Which Data Structure Should be used for implementing LRU cache?
&lt;/h3&gt;

&lt;p&gt;We use two data structures to implement an LRU Cache.&lt;br&gt;
Queue which is implemented using a doubly linked list. The maximum size of the queue will be equal to the total number of frames available (cache size). The most recently used pages will be near rear end and least recently pages will be near front end.&lt;br&gt;
A Hash with page number as key and address of the corresponding queue node as value. See How to implement LRU caching scheme? What data structures should be used?&lt;/p&gt;

&lt;h3&gt;
  
  
  11)  What are the advantages of Linked List over an array?
&lt;/h3&gt;

&lt;p&gt;The size of a linked list can be incremented at runtime which is impossible in the case of the array.&lt;br&gt;
The List is not required to be contiguously present in the main memory, if the contiguous space is not available, the nodes can be stored anywhere in the memory connected through the links.&lt;br&gt;
The List is dynamically stored in the main memory and grows as per the program demand while the array is statically stored in the main memory, size of which must be declared at compile time.&lt;br&gt;
The number of elements in the linked list are limited to the available memory space while the number of elements in the array is limited to the size of an array.&lt;/p&gt;

&lt;h3&gt;
  
  
  12) Tell us something about binary trees.
&lt;/h3&gt;

&lt;p&gt;A binary tree is a form of data structure. It has two nodes, namely the left node and the right node.&lt;/p&gt;

&lt;p&gt;13) How to check if a given Binary Tree is BST or not? &lt;/p&gt;

&lt;p&gt;If in order traversal of a binary tree is sorted, then the binary tree is BST. The idea is to simply do in order traversal and while traversing keep track of previous key value. If current key value is greater, then continue, else return false. See A program to check if a binary tree is BST or not for more details. &lt;/p&gt;

&lt;p&gt;14)  What is a queue?&lt;/p&gt;

&lt;p&gt;A queue is a form of data structure that induces a list of data. In this form of structure, the old elements are removed from one end while the new ones keep getting added to the other end.&lt;/p&gt;

&lt;h3&gt;
  
  
  15) What exactly do you mean by merge sort?
&lt;/h3&gt;

&lt;p&gt;In merge sort, adjacent data elements are merged into one to form a bigger list. These lists are further merged into another big list and the process keeps happening until a single list is obtained.&lt;/p&gt;

&lt;h3&gt;
  
  
  16) What is the least number of nodes that a binary tree can have?
&lt;/h3&gt;

&lt;p&gt;A binary tree can have zero nodes as the least number. Further, the number can be increased to 1 or 2 nodes.&lt;br&gt;
Data structure is a large concept. A range of questions can be extracted from this data storage model. Keeping that in mind, we have another set of questions below that you should prepare for the interview.&lt;/p&gt;

&lt;h3&gt;
  
  
  17) What are the scenarios in which an element can be inserted into the circular queue?
&lt;/h3&gt;

&lt;p&gt;If (rear + 1)% maxsize = front, the queue is full. In that case, overflow occurs and therefore, insertion can not be performed in the queue.&lt;br&gt;
If rear != max - 1, the rear will be incremented to the mod(maxsize) and the new value will be inserted at the rear end of the queue.&lt;br&gt;
If front != 0 and rear = max - 1, it means that queue is not full therefore, set the value of rear to 0 and insert the new element there.&lt;/p&gt;

&lt;h2&gt;
  
  
  18) What do you know about stack?
&lt;/h2&gt;

&lt;p&gt;In stack, the newest data element is accessed first. As the name suggests, all old elements are pushed downwards leaving the last added one on the top.&lt;/p&gt;

&lt;h3&gt;
  
  
  19) What is a dequeue?
&lt;/h3&gt;

&lt;p&gt;Dequeue (also known as double-ended queue) can be defined as an ordered set of elements in which the insertion and deletion can be performed at both the ends, i.e. front and rear.&lt;/p&gt;

&lt;h3&gt;
  
  
  20) Define the graph data structure?
&lt;/h3&gt;

&lt;p&gt;A graph G can be defined as an ordered set G(V, E) where V(G) represents the set of vertices and E(G) represents the set of edges which are used to connect these vertices. A graph can be seen as a cyclic tree, where the vertices (Nodes) maintain any complex relationship among them instead of having parent-child relations.&lt;/p&gt;

&lt;h3&gt;
  
  
  21) Which data structures are used in BFS and DFS algorithm?
&lt;/h3&gt;

&lt;p&gt;In BFS algorithm, Queue data structure is used.&lt;br&gt;
In DFS algorithm, Stack data structure is used.&lt;/p&gt;

&lt;h3&gt;
  
  
  22) What are the applications of Graph data structure?
&lt;/h3&gt;

&lt;p&gt;The graph has the following applications:&lt;/p&gt;

&lt;p&gt;Graphs are used in circuit networks where points of connection are drawn as vertices and component wires become the edges of the graph.&lt;br&gt;
Graphs are used in transport networks where stations are drawn as vertices and routes become the edges of the graph.&lt;br&gt;
Graphs are used in maps that draw cities/states/regions as vertices and adjacency relations as edges.&lt;br&gt;
Graphs are used in program flow analysis where procedures or modules are treated as vertices and calls to these procedures are drawn as edges of the graph.&lt;/p&gt;

&lt;p&gt;Some Extra questions for your preparation :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;• What do you understand by dynamic data structures?&lt;/li&gt;
&lt;li&gt;• Differentiate between Null and Void&lt;/li&gt;
&lt;li&gt;• Cite the difference between Stack and Array.&lt;/li&gt;
&lt;li&gt;• How would you define dequeue?&lt;/li&gt;
&lt;li&gt;• Tell us about the working of a selection list.&lt;/li&gt;
&lt;li&gt;• What do you know about graph?&lt;/li&gt;
&lt;li&gt;• What exactly is an AVL tree?&lt;/li&gt;
&lt;li&gt;• Do you know anything about Huffman’s algorithm?&lt;/li&gt;
&lt;li&gt;• Tell us about recursive algorithm.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While appearing for your interview, Be confident and approach the day with an optimistic outlook. Present yourself with smile and take your time to think about the solutions, do not hurry yourself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks for the reading. All the best!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;3&lt;/p&gt;

&lt;p&gt;Share this&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Java Solution to leetcode problem 1572. Matrix Diagonal Sum</title>
      <dc:creator>Mohammad Saddan Hussain</dc:creator>
      <pubDate>Mon, 28 Feb 2022 05:13:10 +0000</pubDate>
      <link>https://dev.to/hussaincode/java-solution-to-leetcode-problem-1572-matrix-diagonal-sum-425c</link>
      <guid>https://dev.to/hussaincode/java-solution-to-leetcode-problem-1572-matrix-diagonal-sum-425c</guid>
      <description>&lt;h1&gt;
  
  
  Java Solution to leetcode problem 1572. Matrix Diagonal Sum
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://hashnode.com/@hussaincode" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hashnode.com/@hussaincode" rel="noopener noreferrer"&gt;Hussain Code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;·&lt;a href="https://hussaincodes.in/java-solution-to-leetcode-problem-1572-matrix-diagonal-sum" rel="noopener noreferrer"&gt;Feb 28, 2022&lt;/a&gt;·&lt;/p&gt;

&lt;p&gt;1 min read&lt;/p&gt;

&lt;p&gt;Subscribe to my newsletter and never missmy upcoming articles&lt;/p&gt;

&lt;p&gt;Subscribe&lt;/p&gt;

&lt;p&gt;Given a square matrix mat, return the sum of the matrix diagonals.&lt;/p&gt;

&lt;p&gt;Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgtixiywv87l20lxk47qh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgtixiywv87l20lxk47qh.png" alt="sample_1911.png" width="448" height="232"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input:mat= [[1,2,3],
              [4,5,6],
              [7,8,9]]Output:25Explanation: Diagonals sum:1+5+9+3+7=25Noticethatelementmat[1][1]=5iscountedonlyonce.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Leetcode question link - &lt;a href="https://leetcode.com/problems/matrix-diagonal-sum/" rel="noopener noreferrer"&gt;leetcode.com/problems/matrix-diagonal-sum&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Solution :-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Q15 {public static void main(String[] args) {int[][] mat={{1,2,3},
                {4,5,6},
                {7,8,9}};
        System.out.println(diagonalSum(mat));
    }
    static int diagonalSum(int[][] mat) {int n = mat.length;int principal =0, secondary =0;for (int i =0; i &amp;amp;lt; n; i++) {
            principal += mat[i][i];
            secondary += mat[i][n - i -1];
        }return n%2==0 ? (principal + secondary) : (principal + secondary - mat[n/2][n/2]);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Like&lt;/p&gt;

&lt;p&gt;Share this&lt;/p&gt;

</description>
    </item>
    <item>
      <title>OAuth 2.0 and OpenID Connect</title>
      <dc:creator>Mohammad Saddan Hussain</dc:creator>
      <pubDate>Mon, 28 Feb 2022 04:59:46 +0000</pubDate>
      <link>https://dev.to/hussaincode/oauth-20-and-openid-connect-4kfa</link>
      <guid>https://dev.to/hussaincode/oauth-20-and-openid-connect-4kfa</guid>
      <description>&lt;h1&gt;
  
  
  OAuth 2.0 and OpenID Connect
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://hashnode.com/@hussaincode" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hashnode.com/@hussaincode" rel="noopener noreferrer"&gt;Hussain Code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;·&lt;a href="https://hussaincodes.in/oauth-20-and-openid-connect" rel="noopener noreferrer"&gt;Feb 22, 2022&lt;/a&gt;·&lt;/p&gt;

&lt;p&gt;11 min read&lt;/p&gt;

&lt;p&gt;Subscribe to my newsletter and never missmy upcoming articles&lt;/p&gt;

&lt;p&gt;Subscribe&lt;/p&gt;

&lt;h3&gt;
  
  
  Table of contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;What is OAuth 2.0 ?&lt;/li&gt;
&lt;li&gt;Different identity use case&lt;/li&gt;
&lt;li&gt;Delegated Authorization with OAuth 2.0&lt;/li&gt;
&lt;li&gt;OAuth 2.0 Terminology&lt;/li&gt;
&lt;li&gt;More OAuth 2.0 Terminology&lt;/li&gt;
&lt;li&gt;More OAuth 2.0 Terminology&lt;/li&gt;
&lt;li&gt;Why we have to get Authorization code and then exchange that for Access Token&lt;/li&gt;
&lt;li&gt;Some key points regarding the Flow&lt;/li&gt;
&lt;li&gt;Starting the flow&lt;/li&gt;
&lt;li&gt;Calling Back / Redirect URI&lt;/li&gt;
&lt;li&gt;Exchange code for Access Token&lt;/li&gt;
&lt;li&gt;Authorization server returns an Access Token&lt;/li&gt;
&lt;li&gt;Use the Access Token&lt;/li&gt;
&lt;li&gt;Different types of OAuth 2.0 flows&lt;/li&gt;
&lt;li&gt;Identity use cases (Earlier)&lt;/li&gt;
&lt;li&gt;Problems with OAuth 2.0 for authentication&lt;/li&gt;
&lt;li&gt;OAuth 2.0 and OpenID Connect&lt;/li&gt;
&lt;li&gt;What OpenID Connect adds to OAuth 2.0&lt;/li&gt;
&lt;li&gt;OpenID Connect authorization code flow&lt;/li&gt;
&lt;li&gt;Starting the OpenID flow&lt;/li&gt;
&lt;li&gt;Exchange code for access token and ID token&lt;/li&gt;
&lt;li&gt;Authorization server returns access and ID tokens&lt;/li&gt;
&lt;li&gt;Identity use cases (Today)&lt;/li&gt;
&lt;li&gt;Which flow (grant type) should we use?&lt;/li&gt;
&lt;li&gt;Example: web application with server backend&lt;/li&gt;
&lt;li&gt;Example: native mobile app&lt;/li&gt;
&lt;li&gt;Example: SPA with API backend&lt;/li&gt;
&lt;li&gt;Example: SSO with 3rd-party services&lt;/li&gt;
&lt;li&gt;Token validation&lt;/li&gt;
&lt;li&gt;Keeping the user signed in&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What is OAuth 2.0 ?
&lt;/h3&gt;

&lt;p&gt;To understand OAuth, let us take this classic example of photo printing service you must have seen websites like this where you give them an image file and you pay them to ship printed photos to your home address. Imagine you're starting a new photo printing business that lets people upload photos to your website and they can order prints of these photos. you code your website and apply the people sign up everything is good but nobody keeps photos on their machines anymore they use the cloud and so you keep getting this feature request to provide users the ability to import their photos from&lt;br&gt;
somewhere like Google Drive and then print it directly from there without the users having to download and upload again. Now what do you have to do to implement this import from Google Drive feature in your application. You need to connect to the users Google Drive account and access their files but how can your application do that. The users files on Google Drive need Google authentication how can you write code for your website that can authenticate with Google on behalf of your users well.&lt;br&gt;
 You can ask the user for their Google ID and password you can say hey user do you want me to print your photos on Google. Google doesn't give me access, so here's my screen where you enter your Google ID and password you just give them to me I will log into your Google account and access your photos and print them.&lt;br&gt;
It'll work in theory but do you think users will give you their Google ID and password. no they probably won't because they don't trust you what they want to give you is access to just certain photos. They don't want to give you access to their whole Google Drive and email and everything else.&lt;br&gt;
Now you can say to your user I promise to access just your files that you mentioned and I promise to throw out the password after I'm done I'm totally not saving that but there's no guarantee that this service is gonna do that. So now we can say Google Drive has a share feature you can ask the user&lt;br&gt;
to share the files out and then give the link to them in your service but there are problems here what if the users don't want to share files out to anyone also what if it's a different scenario where sharing isn't an option. For example - Think of the scenario where your service wants to access the list of your users friends to send invites to the application there's no way you can ask the user to share their address book such a feature just doesn't exist. So how do you have a third party service authorize with the Google address book service as your user without the user providing their credentials. &lt;strong&gt;This is where OAuth comes in to solve this problem of services trying to access each other on behalf of the user.&lt;/strong&gt;There was the standard created called OAuth. There was a version 1.0 of the standard but the current&lt;br&gt;
version is the most widely used this is &lt;strong&gt;OAuth 2.0&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Different identity use case
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Simple Login                          -&amp;gt;   Forms and Cookies&lt;/li&gt;
&lt;li&gt;Single Sign On across site   -&amp;gt;    SAML&lt;/li&gt;
&lt;li&gt;Mobile App Login                 -&amp;gt;    Authorization code through PKCE&lt;/li&gt;
&lt;li&gt;Delegated Authorization      -&amp;gt;   OAuth&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will focus on Delegated authorization as it will cover the whole OAuth perspectives.&lt;/p&gt;
&lt;h3&gt;
  
  
  Delegated Authorization with OAuth 2.0
&lt;/h3&gt;

&lt;p&gt;We will start with user like you and me who wants to login in to some website called &lt;a href="http://yelp.com" rel="noopener noreferrer"&gt;yelp.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So you have trust on google and you have a little trust on &lt;a href="http://yelp.com" rel="noopener noreferrer"&gt;yelp.com&lt;/a&gt; and you want this site to just access my contacts but you don't want to give them enough access to let them delete your contacts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ijhb53gqanx3wmtyngr.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ijhb53gqanx3wmtyngr.PNG" alt="Oauth1.PNG" width="800" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When user will click on this &lt;strong&gt;connect with Google&lt;/strong&gt; link, user would go to the OAuth flow. It's basically the set of steps that ultimately results in the application being able to access that information or having the authorization to access that information.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frjf8jo4o0xrc1x1cd725.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frjf8jo4o0xrc1x1cd725.PNG" alt="oauth2.PNG" width="800" height="483"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This diagram illustrate at high level how this flow works.&lt;/p&gt;

&lt;p&gt;So, if the user clicks on this link user will be redirected to google domain &lt;a href="http://accounts.google.com" rel="noopener noreferrer"&gt;accounts.google.com&lt;/a&gt; then user will enter the email and password.&lt;br&gt;
Now it's little safe as we are sharing the email and password with &lt;a href="http://google.com" rel="noopener noreferrer"&gt;google.com&lt;/a&gt; an not &lt;a href="http://yelp.com" rel="noopener noreferrer"&gt;yelp.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Assuming you logged in successfully, there you get a prompts that says this application yelp is trying to access your list of things. &lt;strong&gt;are you sure you want to allow this?  Yes or No&lt;/strong&gt;So users explicitly have to give their consent to whatever they are granting access.&lt;/p&gt;

&lt;p&gt;Assuming user click &lt;strong&gt;Yes&lt;/strong&gt; then browser will be redirected back to &lt;a href="http://yelp.com" rel="noopener noreferrer"&gt;yelp.com&lt;/a&gt;. The application called a callback or redirect URI. That application is the  allowed to go an talk to some other APIs like google contacts API.&lt;/p&gt;
&lt;h3&gt;
  
  
  OAuth 2.0 Terminology
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Resource Owner&lt;/li&gt;
&lt;li&gt;Client&lt;/li&gt;
&lt;li&gt;Authorization Server&lt;/li&gt;
&lt;li&gt;Resource Server&lt;/li&gt;
&lt;li&gt;Authorization Grant&lt;/li&gt;
&lt;li&gt;Redirect URI&lt;/li&gt;
&lt;li&gt;Access Token&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Resource Owner :-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You, me and number of users who owns the data would give the permission to other application to access their data from google.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Client :-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We are using &lt;a href="http://yelp.com" rel="noopener noreferrer"&gt;yelp.com&lt;/a&gt; here as an example. so &lt;a href="http://Yelp.com" rel="noopener noreferrer"&gt;Yelp.com&lt;/a&gt; would be a client.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authorization Server :-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is a system that you can use to say  "Yes I authorize this permission"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resource Server :-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is the API or the system that actually holds the data that clients wants to get.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sometimes the Authorization server and the Resource server are same thing.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authorization Grant :-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is a thing that basically proves that user has clicked yes when asked for permission or allow you to have this permission.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Redirect URI :-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The url that we give when user get the permission from the Resource server using the Authorization grant and get back to the site where we have started like &lt;a href="http://yelp.com" rel="noopener noreferrer"&gt;yelp.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Access Token :-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An access token is an object encapsulating the security identity of a process or thread. A token is used to make security decisions and to store tamper-proof information about some system entity. While a token is generally used to represent only security information, it is capable of holding additional free-form data that can be attached while the token is being created.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;At higher level client needs something called Access Token.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2057p1h6omdus8go87kh.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2057p1h6omdus8go87kh.PNG" alt="oauth3.PNG" width="800" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because of this access token, client can have the access to the contacts but instead of getting the contacts if they try to delete your contacts they couldn't delete your contacts because you have given the permission to just access the contacts and access token generated according to your permission. so using that access token user can just access your contacts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now we want some way of being very granular, have specific permission that we can turn on or off.&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  More OAuth 2.0 Terminology
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Scope&lt;/li&gt;
&lt;li&gt;Consent&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Scope is a specific permission you want to give to the users. for example it can be read contacts, write contacts.&lt;br&gt;
when we define the scope user will be allowed to take the information.&lt;/p&gt;

&lt;p&gt;List of permission that client is asking for is then used by authorization server to generate that consent screen that is presented to the users that says &lt;a href="http://yelp.com" rel="noopener noreferrer"&gt;yelp.com&lt;/a&gt; is asking for the permission to do XYZ.&lt;br&gt;
Users give an explicit ability to consent or not consent to that particular list of contacts.&lt;/p&gt;

&lt;p&gt;For example, Facebook changed the authorization service recently  to be really explicit about let you know weather or not an application that you are giving access is to allowed to post on your wall because earlier it was not clear after connecting will they just get your information or they are going to spam you facebook wall with each and every post. Now Facebook made it very granular.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz2p02btjkf6jh968sjfp.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz2p02btjkf6jh968sjfp.PNG" alt="oauth4.PNG" width="800" height="485"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  More OAuth 2.0 Terminology
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Front Channel  (Less secure channel)&lt;/li&gt;
&lt;li&gt;Back Channel  (High secure channel)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Back Channel&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If your server code is running on your server which only you have access to and you can make an API request or some other HTTP request from your server to another server like Google's API and that is going over HTTP, SSL encrypted, no one can intercept that communication. it's highly secure, that's what we call as a Back Channel.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Front Channel&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your Browser can be considered as a front channel, where your browser is secure but there might be loopholes or there is some place where stuff could leak from the browser.&lt;/p&gt;

&lt;p&gt;Suppose you are building a web application and you want to store a secret password or any secret key in your web application. If you put it in HTML or JavaScript of your web application then anybody could just right click and view the source code and can see the secret key. That's why browser is considered as Front Channel and less secure.&lt;/p&gt;
&lt;h3&gt;
  
  
  Why we have to get Authorization code and then exchange that for Access Token
&lt;/h3&gt;

&lt;p&gt;As you would go through this OAuth flow you will find out that the flow is designed including the reason why we have to get the authorization code and exchange that for access token is designed to take the advantages of best things about front channel and back channel to make it more secure.&lt;/p&gt;

&lt;p&gt;Authorization code gets exchange with access token at authorization server so that no one could steal that access token and access our information in wrong way.&lt;/p&gt;
&lt;h3&gt;
  
  
  Some key points regarding the Flow
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Access Token is very sensitive information.&lt;/li&gt;
&lt;li&gt;Front channel is used to interact with the user.&lt;/li&gt;
&lt;li&gt;The last step of the flow happened at back channel.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Starting the flow
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;client_id=abc123&amp;amp;amp;
redirect_uri=https://yelp.com/callback&amp;amp;amp;
scope=profile&amp;amp;amp;
response_type=code&amp;amp;amp;
state=foobar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Client Secret will be on authorization server&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Calling Back / Redirect URI
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://yelp.com/callback?error=access_denied&amp;amp;amp;
error_description=The user did not consent.https://yelp.com/callback?code=oMsCeLvIaQm6bTrgtp7&amp;amp;amp;
state=foobar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Exchange code for Access Token
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POST www.googleapis.com/oauth2/v4/token
Content-Type: application/x-www-form-urlencoded
code=oMsCeLvIaQm6bTrgtp7&amp;amp;amp;client_id=abc123&amp;amp;amp;client_secret=secret123&amp;amp;amp;grant_type=authorization_code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Authorization server returns an Access Token
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"access_token": "fFAGRNJru1FTz70BzhT3Zg","expires_in": 3920,"token_type": "Bearer",
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Use the Access Token
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET api.google.com/some/endpointAuthorization: Bearer fFAGRNJru1FTz70BzhT3Zg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo6vbnnn80czbzwyh6hjv.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo6vbnnn80czbzwyh6hjv.PNG" alt="oauth5.PNG" width="800" height="246"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Different types of OAuth 2.0 flows
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Authorization code (front channel + back channel)&lt;/li&gt;
&lt;li&gt;Implicit (front channel only)&lt;/li&gt;
&lt;li&gt;Resource owner password credentials (back channel only)&lt;/li&gt;
&lt;li&gt;Client credentials (back channel only)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We use the Implicit flows when we have pure JavaScript or Angular web application which doesn't have any backend server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffna4qv1syi94q1383tml.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffna4qv1syi94q1383tml.PNG" alt="oauth6.PNG" width="697" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Although it's less secure but anyway just make sure no body could steal your access token, try to hide it in front end only. &lt;/p&gt;
&lt;h3&gt;
  
  
  Identity use cases (Earlier)
&lt;/h3&gt;

&lt;p&gt;• Simple login – OAuth 2.0                                  Authentication&lt;br&gt;
• Single sign-on across sites – OAuth 2.0         Authentication &lt;br&gt;
• Mobile app login – OAuth 2.0                          Authentication &lt;br&gt;
• Delegated authorization – OAuth 2.0             Authorization&lt;/p&gt;

&lt;p&gt;OAuth 2.0 was originally invented for &lt;strong&gt;Authorization&lt;/strong&gt; but later company like google, facebook and twitter started using in Authentication also by making some changes on the top of the OAuth 2.0.&lt;/p&gt;
&lt;h3&gt;
  
  
  Problems with OAuth 2.0 for authentication
&lt;/h3&gt;

&lt;p&gt;• No standard way to get the user's information&lt;br&gt;
• Every implementation is a little different&lt;br&gt;
• No common set of scopes&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The reason why we shouldn't use the OAuth 2.0 for Authentication because there is no standard of getting the user info in OAuth 2.0&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  OAuth 2.0 and OpenID Connect
&lt;/h3&gt;

&lt;p&gt;To standardize the Authentication to get the user information on top of OAuth 2.0, OpenID Connect came in picture.&lt;/p&gt;
&lt;h3&gt;
  
  
  What OpenID Connect adds to OAuth 2.0
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;ID token&lt;/li&gt;
&lt;li&gt;UserInfo endpoint for getting more user information&lt;/li&gt;
&lt;li&gt;Standard set of scopes&lt;/li&gt;
&lt;li&gt;Standardized implementation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8iis0bj9isr9sd8x9tey.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8iis0bj9isr9sd8x9tey.PNG" alt="oauth7.PNG" width="628" height="307"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  OpenID Connect authorization code flow
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd4tepiagp898z7cqqbej.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd4tepiagp898z7cqqbej.PNG" alt="oauth8.PNG" width="673" height="352"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Starting the OpenID flow
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://accounts.google.com/o/oauth2/v2/auth?client_id=abc123&amp;amp;amp;redirect_uri=https://yelp.com/callback&amp;amp;amp;scope=openid profile&amp;amp;amp;response_type=code&amp;amp;amp;state=foobar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Exchange code for access token and ID token
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POST www.googleapis.com/oauth2/v4/token
Content-Type: application/x-www-form-urlencoded
code=oMsCeLvIaQm6bTrgtp7&amp;amp;amp;client_id=abc123&amp;amp;amp;client_secret=secret123&amp;amp;amp;grant_type=authorization_code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Authorization server returns access and ID tokens
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"access_token": "fFAGRNJru1FTz70BzhT3Zg","id_token": "eyJraB03ds3F...""expires_in": 3920,"token_type": "Bearer",
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;ID token is just a token encoding the bunch of information. it's also called as JWT.&lt;/p&gt;

&lt;p&gt;it looks something like gibberish words but underneath it contains all the information of the users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example of ID Token or JWT&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eyJhbGciOiJSUzI1NiIsImtpZCI6IkRNa3Itd0JqRU1EYnhOY25xaVJISVhu
YUxubWI3UUpfWF9rWmJyaEtBMGMifQ
.
eyJzdWIiOiIwMHU5bzFuaWtqdk9CZzVabzBoNyIsInZlciI6MSwiaXNzIjoi
aHR0cHM6Ly9kZXYtMzQxNjA3Lm9rdGFwcmV2aWV3LmNvbS9vYXV0aDIvYXVz
OW84d3ZraG9ja3c5VEwwaDciLCJhdWQiOiJsWFNlbkx4eFBpOGtRVmpKRTVz
NCIsImlhdCI6MTUwOTA0OTg5OCwiZXhwIjoxNTA5MDUzNDk4LCJqdGkiOiJJ
RC5oa2RXSXNBSXZTbnBGYVFHTVRYUGNVSmhhMkgwS2c5Ykl3ZEVvVm1ZZHN3
IiwiYW1yIjpbImtiYSIsIm1mYSIsInB3ZCJdLCJpZHAiOiIwMG85bzFuaWpr
aWpLeGNpbjBoNyIsIm5vbmNlIjoidWpwMmFzeHlqN2UiLCJhdXRoX3RpbWUi
OjE1MDkwNDk3MTl9
.
dv4Ek8B4BDee1PcQT_4zm7kxDEY1sRIGbLoNtlodZcSzHzXU5GkKyl6sAVmdXOIPUlAIrJAhNfQWQ-
_XZLBVPjETiZE8CgNg5uqNmeXMUnYnQmvN5oWlXUZ8Gcub-GAbJ8-NQuyBmyec1j3gmGzX3wemke8NkuI6SX2L4Wj1PyvkknBtbjfiF9ud1-ERKbobaFbnjDFOFTzvL6g34SpMmZWy6uc_Hs--n4IC-ex-_Ps3FcMwRggCW_-7o2FpH6rJTOGPZYrOx44n3ZwAu2dGm6axtPIsqU8b6sw7DaHpogD_hxsXgMIOzOBMbYsQEiczoGn71ZFz_1O7FiW4dH6g
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you paste this value in &lt;a href="http://jwt.io" rel="noopener noreferrer"&gt;jwt.io&lt;/a&gt; , you will get a lot of information contained by this jwt.&lt;/p&gt;

&lt;p&gt;There is different segment of this id token like header portion, signature portion and payload portion.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Header
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"alg": "RS256","kid": "DMkr-wBjEMDbxNcnqiRHIXnaLnmb7QJ_X_kZbrhKA0c"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Payload
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"iss": "https://accounts.google.com","sub": "you@gmail.com","name": "Nate Barbettini""aud": "s6BhdRkqt3","exp": 1311281970,"iat": 1311280970,"auth_time": 1311280969,
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Signature can be used to verify the ID Token has not been modified or compromised or rather changed in any way.&lt;/p&gt;

&lt;h3&gt;
  
  
  Identity use cases (Today)
&lt;/h3&gt;

&lt;p&gt;• Simple login – OpenID Connect                                 Authentication&lt;/p&gt;

&lt;p&gt;• Single sign-on across sites – OpenID Connect         Authentication &lt;/p&gt;

&lt;p&gt;• Mobile app login – OpenID Connect                         Authentication &lt;/p&gt;

&lt;p&gt;• Delegated authorization – OAuth 2.0                        Authorization&lt;/p&gt;

&lt;p&gt;OAuth OpenID Connect &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7pyngwr398n5ujt48xcy.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7pyngwr398n5ujt48xcy.PNG" alt="oauth9.PNG" width="639" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Which flow (grant type) should we use?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Web application w/ server backend: authorization code flow&lt;/li&gt;
&lt;li&gt;Native mobile app: authorization code flow with PKCE&lt;/li&gt;
&lt;li&gt;JavaScript app (SPA) w/ API backend: implicit flow&lt;/li&gt;
&lt;li&gt;Microservices and APIs: client credentials flow&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example: web application with server backend
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwj6giikh8w4dno02skzw.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwj6giikh8w4dno02skzw.PNG" alt="oauth10.PNG" width="662" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: native mobile app
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcsi0k89y4hfpi9nqym5r.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcsi0k89y4hfpi9nqym5r.PNG" alt="oauth11.PNG" width="683" height="319"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: SPA with API backend
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvwzvdvmmwpar1khy1xb4.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvwzvdvmmwpar1khy1xb4.PNG" alt="oauth12.PNG" width="680" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: SSO with 3rd-party services
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvz1nzbx0f79y5izfp2pg.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvz1nzbx0f79y5izfp2pg.PNG" alt="oauth13.PNG" width="661" height="323"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Token validation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The fast way: local validation&lt;/li&gt;
&lt;li&gt;Check expiration timestamp&lt;/li&gt;
&lt;li&gt;Validate cryptographic signature&lt;/li&gt;
&lt;li&gt;The strong way: introspection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3uphv6k2c2w4wzbjs05f.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3uphv6k2c2w4wzbjs05f.PNG" alt="oauth14.PNG" width="636" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Keeping the user signed in
&lt;/h3&gt;

&lt;p&gt;For both local validation and introspection, the token is invalid once it&lt;br&gt;
expires, so:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If there's a user at the keyboard, just redirect through the&lt;/li&gt;
&lt;li&gt;authorization server again.&lt;/li&gt;
&lt;li&gt;If there's no user (automated tasks), request a refresh token (offline scope).&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Thank you for reading out this blog! I hope now you have very good understanding of OAuth 2.0 and OpenID Connect.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;1&lt;/p&gt;

&lt;p&gt;Share this&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Registration/Login System using Spring Boot and Spring Security</title>
      <dc:creator>Mohammad Saddan Hussain</dc:creator>
      <pubDate>Mon, 28 Feb 2022 04:50:47 +0000</pubDate>
      <link>https://dev.to/hussaincode/registrationlogin-system-using-spring-boot-and-spring-security-jc6</link>
      <guid>https://dev.to/hussaincode/registrationlogin-system-using-spring-boot-and-spring-security-jc6</guid>
      <description>&lt;h1&gt;
  
  
  Registration/Login System using Spring Boot and Spring Security
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://hashnode.com/@hussaincode" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hashnode.com/@hussaincode" rel="noopener noreferrer"&gt;Hussain Code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;·&lt;a href="https://hussaincodes.in/registrationlogin-system-using-spring-boot-and-spring-security" rel="noopener noreferrer"&gt;Feb 20, 2022&lt;/a&gt;·&lt;/p&gt;

&lt;p&gt;7 min read&lt;/p&gt;

&lt;p&gt;Subscribe to my newsletter and never missmy upcoming articles&lt;/p&gt;

&lt;p&gt;Subscribe&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In this article we are going to build complete Registration/Login System using Spring Boot and Spring Security.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Technology used :-
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; =&amp;amp;gt; Spring Boot

   =&amp;amp;gt; Spring Security

   =&amp;amp;gt; Java Mail

   =&amp;amp;gt; Email verification with expiry
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1. Create Project using Spring Initializer
&lt;/h3&gt;

&lt;p&gt;Follow this &lt;a href="https://start.spring.io/#!type=maven-project&amp;amp;language=java&amp;amp;platformVersion=2.6.3&amp;amp;packaging=jar&amp;amp;jvmVersion=11&amp;amp;groupId=com.example&amp;amp;artifactId=demo&amp;amp;name=demo&amp;amp;description=Demo%20project%20for%20Spring%20Boot&amp;amp;packageName=com.example.demo&amp;amp;dependencies=lombok,web,security,postgresql,data-jpa,mail" rel="noopener noreferrer"&gt;link&lt;/a&gt; and you will be redirected to the spring initializer with all the dependencies requires for this project.&lt;/p&gt;

&lt;p&gt;Download this project and you will get the zip file. unzip it and open with intelliJ Idea.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs1e7lt2wc8b6h48uxxrj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs1e7lt2wc8b6h48uxxrj.png" alt="step1.PNG" width="800" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Create appuser package
&lt;/h3&gt;

&lt;p&gt;Inside this package we will configure all the user details in different classes and Interfaces.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a AppUser class and define all the properties of the user like firstName, lastName, email, password, etc.&lt;/li&gt;
&lt;li&gt;Create a AppUserRepository interface and an inherit the JpaRepository class to do all the database operations on the users.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Transactional(readOnly = true)
public interface AppUserRepository extends JpaRepository&amp;amp;lt;AppUser, Long&amp;amp;gt; {
    Optional&amp;amp;lt;AppUser&amp;amp;gt; findByEmail(String email);

    @Transactional
    @Modifying
    @Query("UPDATE AppUser a " +
            "SET a.enabled = TRUE WHERE a.email = ?1")
    int enableAppUser(String email);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create a AppUserRole enum to define the role of the user.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;public enum AppUserRole {&lt;br&gt;
    USER,&lt;br&gt;
    ADMIN&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a AppUserService class to define the service in terms of how user will register and share the data to login.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Service
@AllArgsConstructorpublic class AppUserService implements UserDetailsService {private static final String USER_NOT_FOUND ="user with email %s not found!";private final AppUserRepository appUserRepository;private final BCryptPasswordEncoder bCryptPasswordEncoder;private final ConfirmationTokenService confirmationTokenService;

    @Overridepublic UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {return appUserRepository.findByEmail(email)
                .orElseThrow(() -&amp;amp;gt;new UsernameNotFoundException(String.format(USER_NOT_FOUND,email)));
    }public String signUpUser(AppUser appUser){
       boolean userExists = appUserRepository
                .findByEmail(appUser.getEmail())
                .isPresent();if (userExists){// TODO: CHECK OF ATTRIBUTES ARE THE SAME AND//TODO: IF EMAIL NOT CONFIRMED SENDD CONFIRMATION MAILthrownew IllegalStateException("email already taken!");
       }
       String encodedPassword = bCryptPasswordEncoder.encode(appUser.getPassword());
       appUser.setPassword(encodedPassword);

       appUserRepository.save(appUser);

        String token = UUID.randomUUID().toString();//TODO: Send confirmation token ConfirmationToken confirmationToken =new ConfirmationToken(
                token,
                LocalDateTime.now(),
                LocalDateTime.now().plusMinutes(15),
                appUser
        );
        confirmationTokenService.saveConfirmationToken(confirmationToken);//TODO Send Emailreturn token;
    }publicint enableAppUser(String email) {return appUserRepository.enableAppUser(email);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Create registration package
&lt;/h3&gt;

&lt;p&gt;Inside this package we will configure all the registration details in different classes and Interfaces that will register a user we have in appuser package.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a UserRegistration Class to map a registration endpoint
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@RequestMapping(path = "api/v1/registration")
@AllArgsConstructor
public class UserRegistration {

    private final RegistrationService registrationService;

    @PostMapping
    public String register(@RequestBody RegistrationRequest request){

        return registrationService.register(request);
    }

    @GetMapping(path = "confirm")
    public String confirm(@RequestParam("token") String token) {
        return registrationService.confirmToken(token);
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create a RegistrationRequest class to request all the data from the user.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@AllArgsConstructor
@EqualsAndHashCode
@ToString
public class RegistrationRequest {
    private final String firstName;
    private final String lastName;
    private final String email;
    private final String password;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create a EmailValidator class that will validate the user's email
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Service@AllArgsConstructorpublicclassEmailValidatorimplementsPredicate&amp;amp;lt;String&amp;amp;gt; {@Overridepublicbooleantest(String s){returnfalse;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create a RegistrationService class to map the relation between the user and registration endpoint.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@AllArgsConstructor
public class RegistrationService {
    private final AppUserService appUserService;
    private final EmailValidator emailValidator;
    private final EmailSender emailSender;
    private final ConfirmationTokenService confirmationTokenService;

    public String register(RegistrationRequest request) {

        boolean isValidEmail = emailValidator.test(request.getEmail());

        if(isValidEmail){
            throw new IllegalStateException("Email is not valid!");
        }
            String token = appUserService.signUpUser(
                    new AppUser(
                            request.getFirstName(),
                            request.getLastName(),
                            request.getEmail(),
                            request.getPassword(),
                            AppUserRole.USER
                    )
            );
        String link = "http://localhost:8080/api/v1/registration/confirm/?token=" + token;
        emailSender.send(
                request.getEmail(),
                buildEmail(request.getFirstName(), link) );

        return  token;
    }
    @Transactional
    public String confirmToken(String token) {
        ConfirmationToken confirmationToken = confirmationTokenService
                .getToken(token)
                .orElseThrow(() -&amp;amp;gt;
                        new IllegalStateException("token not found"));

        if (confirmationToken.getConfirmedAt() != null) {
            throw new IllegalStateException("email already confirmed");
        }

        LocalDateTime expiredAt = confirmationToken.getExpiredAt();

        if (expiredAt.isBefore(LocalDateTime.now())) {
            throw new IllegalStateException("token expired");
        }

        confirmationTokenService.setConfirmedAt(token);
        appUserService.enableAppUser(
                confirmationToken.getAppUser().getEmail());
        return "confirmed";
    }

    private String buildEmail(String name, String link) {
        return "&amp;amp;lt;div style=\"font-family:Helvetica,Arial,sans-serif;font-size:16px;margin:0;color:#0b0c0c\"&amp;amp;gt;\n" +
                "\n" +
                "&amp;amp;lt;span style=\"display:none;font-size:1px;color:#fff;max-height:0\"&amp;amp;gt;&amp;amp;lt;/span&amp;amp;gt;\n" +
                "\n" +
                "  &amp;amp;lt;table role=\"presentation\" width=\"100%\" style=\"border-collapse:collapse;min-width:100%;width:100%!important\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"&amp;amp;gt;\n" +
                "    &amp;amp;lt;tbody&amp;amp;gt;&amp;amp;lt;tr&amp;amp;gt;\n" +
                "      &amp;amp;lt;td width=\"100%\" height=\"53\" bgcolor=\"#0b0c0c\"&amp;amp;gt;\n" +
                "        \n" +
                "        &amp;amp;lt;table role=\"presentation\" width=\"100%\" style=\"border-collapse:collapse;max-width:580px\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\"&amp;amp;gt;\n" +
                "          &amp;amp;lt;tbody&amp;amp;gt;&amp;amp;lt;tr&amp;amp;gt;\n" +
                "            &amp;amp;lt;td width=\"70\" bgcolor=\"#0b0c0c\" valign=\"middle\"&amp;amp;gt;\n" +
                "                &amp;amp;lt;table role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"border-collapse:collapse\"&amp;amp;gt;\n" +
                "                  &amp;amp;lt;tbody&amp;amp;gt;&amp;amp;lt;tr&amp;amp;gt;\n" +
                "                    &amp;amp;lt;td style=\"padding-left:10px\"&amp;amp;gt;\n" +
                "                  \n" +
                "                    &amp;amp;lt;/td&amp;amp;gt;\n" +
                "                    &amp;amp;lt;td style=\"font-size:28px;line-height:1.315789474;Margin-top:4px;padding-left:10px\"&amp;amp;gt;\n" +
                "                      &amp;amp;lt;span style=\"font-family:Helvetica,Arial,sans-serif;font-weight:700;color:#ffffff;text-decoration:none;vertical-align:top;display:inline-block\"&amp;amp;gt;Confirm your email&amp;amp;lt;/span&amp;amp;gt;\n" +
                "                    &amp;amp;lt;/td&amp;amp;gt;\n" +
                "                  &amp;amp;lt;/tr&amp;amp;gt;\n" +
                "                &amp;amp;lt;/tbody&amp;amp;gt;&amp;amp;lt;/table&amp;amp;gt;\n" +
                "              &amp;amp;lt;/a&amp;amp;gt;\n" +
                "            &amp;amp;lt;/td&amp;amp;gt;\n" +
                "          &amp;amp;lt;/tr&amp;amp;gt;\n" +
                "        &amp;amp;lt;/tbody&amp;amp;gt;&amp;amp;lt;/table&amp;amp;gt;\n" +
                "        \n" +
                "      &amp;amp;lt;/td&amp;amp;gt;\n" +
                "    &amp;amp;lt;/tr&amp;amp;gt;\n" +
                "  &amp;amp;lt;/tbody&amp;amp;gt;&amp;amp;lt;/table&amp;amp;gt;\n" +
                "  &amp;amp;lt;table role=\"presentation\" class=\"m_-6186904992287805515content\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"border-collapse:collapse;max-width:580px;width:100%!important\" width=\"100%\"&amp;amp;gt;\n" +
                "    &amp;amp;lt;tbody&amp;amp;gt;&amp;amp;lt;tr&amp;amp;gt;\n" +
                "      &amp;amp;lt;td width=\"10\" height=\"10\" valign=\"middle\"&amp;amp;gt;&amp;amp;lt;/td&amp;amp;gt;\n" +
                "      &amp;amp;lt;td&amp;amp;gt;\n" +
                "        \n" +
                "                &amp;amp;lt;table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"border-collapse:collapse\"&amp;amp;gt;\n" +
                "                  &amp;amp;lt;tbody&amp;amp;gt;&amp;amp;lt;tr&amp;amp;gt;\n" +
                "                    &amp;amp;lt;td bgcolor=\"#1D70B8\" width=\"100%\" height=\"10\"&amp;amp;gt;&amp;amp;lt;/td&amp;amp;gt;\n" +
                "                  &amp;amp;lt;/tr&amp;amp;gt;\n" +
                "                &amp;amp;lt;/tbody&amp;amp;gt;&amp;amp;lt;/table&amp;amp;gt;\n" +
                "        \n" +
                "      &amp;amp;lt;/td&amp;amp;gt;\n" +
                "      &amp;amp;lt;td width=\"10\" valign=\"middle\" height=\"10\"&amp;amp;gt;&amp;amp;lt;/td&amp;amp;gt;\n" +
                "    &amp;amp;lt;/tr&amp;amp;gt;\n" +
                "  &amp;amp;lt;/tbody&amp;amp;gt;&amp;amp;lt;/table&amp;amp;gt;\n" +
                "\n" +
                "\n" +
                "\n" +
                "  &amp;amp;lt;table role=\"presentation\" class=\"m_-6186904992287805515content\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"border-collapse:collapse;max-width:580px;width:100%!important\" width=\"100%\"&amp;amp;gt;\n" +
                "    &amp;amp;lt;tbody&amp;amp;gt;&amp;amp;lt;tr&amp;amp;gt;\n" +
                "      &amp;amp;lt;td height=\"30\"&amp;amp;gt;&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;/td&amp;amp;gt;\n" +
                "    &amp;amp;lt;/tr&amp;amp;gt;\n" +
                "    &amp;amp;lt;tr&amp;amp;gt;\n" +
                "      &amp;amp;lt;td width=\"10\" valign=\"middle\"&amp;amp;gt;&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;/td&amp;amp;gt;\n" +
                "      &amp;amp;lt;td style=\"font-family:Helvetica,Arial,sans-serif;font-size:19px;line-height:1.315789474;max-width:560px\"&amp;amp;gt;\n" +
                "        \n" +
                "            &amp;amp;lt;p style=\"Margin:0 0 20px 0;font-size:19px;line-height:25px;color:#0b0c0c\"&amp;amp;gt;Hi " + name + ",&amp;amp;lt;/p&amp;amp;gt;&amp;amp;lt;p style=\"Margin:0 0 20px 0;font-size:19px;line-height:25px;color:#0b0c0c\"&amp;amp;gt; Thank you for registering. Please click on the below link to activate your account: &amp;amp;lt;/p&amp;amp;gt;&amp;amp;lt;blockquote style=\"Margin:0 0 20px 0;border-left:10px solid #b1b4b6;padding:15px 0 0.1px 15px;font-size:19px;line-height:25px\"&amp;amp;gt;&amp;amp;lt;p style=\"Margin:0 0 20px 0;font-size:19px;line-height:25px;color:#0b0c0c\"&amp;amp;gt; &amp;amp;lt;a href=\"" + link + "\"&amp;amp;gt;Activate Now&amp;amp;lt;/a&amp;amp;gt; &amp;amp;lt;/p&amp;amp;gt;&amp;amp;lt;/blockquote&amp;amp;gt;\n Link will expire in 15 minutes. &amp;amp;lt;p&amp;amp;gt;See you soon&amp;amp;lt;/p&amp;amp;gt;" +
                "        \n" +
                "      &amp;amp;lt;/td&amp;amp;gt;\n" +
                "      &amp;amp;lt;td width=\"10\" valign=\"middle\"&amp;amp;gt;&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;/td&amp;amp;gt;\n" +
                "    &amp;amp;lt;/tr&amp;amp;gt;\n" +
                "    &amp;amp;lt;tr&amp;amp;gt;\n" +
                "      &amp;amp;lt;td height=\"30\"&amp;amp;gt;&amp;amp;lt;br&amp;amp;gt;&amp;amp;lt;/td&amp;amp;gt;\n" +
                "    &amp;amp;lt;/tr&amp;amp;gt;\n" +
                "  &amp;amp;lt;/tbody&amp;amp;gt;&amp;amp;lt;/table&amp;amp;gt;&amp;amp;lt;div class=\"yj6qo\"&amp;amp;gt;&amp;amp;lt;/div&amp;amp;gt;&amp;amp;lt;div class=\"adL\"&amp;amp;gt;\n" +
                "\n" +
                "&amp;amp;lt;/div&amp;amp;gt;&amp;amp;lt;/div&amp;amp;gt;";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now create one more package inside the registration package in which we will configure the token from the user for the successful registration.&lt;/li&gt;
&lt;li&gt;And then inside this token package, we will create a ConfirmationToken class to create the token for the user.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Setter
@NoArgsConstructor
@Entity
public class ConfirmationToken {
    @SequenceGenerator(
            name = "confirmation_token_sequence",
            sequenceName = "confirmation_token_sequence",
            allocationSize = 1
    )
    @Id
    @GeneratedValue(
            strategy = GenerationType.SEQUENCE,
            generator = "confirmation_token_sequence"
    )
    private Long id;
    @Column(nullable = false)
    private  String token;
    @Column(nullable = false)
    private LocalDateTime createdAt;
    @Column(nullable = false)
    private LocalDateTime expiredAt;
    private LocalDateTime confirmedAt;

    @ManyToOne
    @JoinColumn(
            nullable = false,
            name= "app_user_id"
    )
    private AppUser appUser;

    public ConfirmationToken(String token,
                             LocalDateTime createdAt,
                             LocalDateTime expiredAt,
                             AppUser appUser) {
        this.token = token;
        this.createdAt = createdAt;
        this.expiredAt = expiredAt;
        this.appUser =appUser;
    }
   }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Run the project and then you can go to postman and hit this url - localhost:8080/api/v1/registration, you will get the access token&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0fnqn0o533i87eugd1ew.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0fnqn0o533i87eugd1ew.png" alt="postmanRegistration.PNG" width="800" height="441"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create an interface ConfirmationTokenRepository and extends the JpaRepository to do all the database operation like to save the token to specific user in databse.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface ConfirmationTokenRepository extends
        JpaRepository&amp;amp;lt;ConfirmationToken,Long&amp;amp;gt; {

    Optional&amp;amp;lt;ConfirmationToken&amp;amp;gt; findByToken(String token);

    @Transactional
    @Modifying
    @Query("UPDATE ConfirmationToken c " +
            "SET c.confirmedAt = ?2 " +
            "WHERE c.token = ?1")
    int updateConfirmedAt(String token,
                          LocalDateTime confirmedAt);


}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create a ConfirmationTokenService class to save this token to the specific users for 15 mins so that he can activate their account within 15 min and will be able to login.&lt;/li&gt;
&lt;li&gt;we have set the token expiry time to 15 mins for the security purpose, we can increase or decrease the expiration time of token according to our purpose.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@AllArgsConstructor
public class ConfirmationTokenService {

    private final ConfirmationTokenRepository confirmationTokenRepository;

    public void saveConfirmationToken(ConfirmationToken token){
        confirmationTokenRepository.save(token);
    }

    public Optional&amp;amp;lt;ConfirmationToken&amp;amp;gt; getToken(String token) {
        return confirmationTokenRepository.findByToken(token);
    }

    public int setConfirmedAt(String token) {
        return confirmationTokenRepository.updateConfirmedAt(
                token, LocalDateTime.now());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now you can hit the access token url localhost:8080/api/v1/registration/confirm/?token=17de5cc5-2f43-48e3-acd2-c47f26bba311&lt;/li&gt;
&lt;li&gt;And access token would be the same which we have created while hitting the registration url&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk66liqnp0td2op3t95q5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk66liqnp0td2op3t95q5.png" alt="postmanTokenConfirmation.PNG" width="800" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Create an email package in which we will configure the property of email sending.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create an interface EmailSender, where we will define the send method that will take t2 String parameters "to" and "email"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;\&lt;/code&gt;`public interface EmailSender {&lt;br&gt;
    void send(String to, String email);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a classEmailServicewherewewillimplementthissendmethodandthepropertytosendanemailtoaparticularuser'semailwhowilltrytoregister.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;@Service@AllArgsConstructorpublicclassEmailServiceimplementsEmailSender{privatefinalstatic Logger LOGGER = LoggerFactory.getLogger(EmailService.class);privatefinal JavaMailSender javaMailSender;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Override
@Asyncpublicvoid send(String to, String email) {try {
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage,"utf-8");
        mimeMessageHelper.setText(email,true);
        mimeMessageHelper.setTo(to);
        mimeMessageHelper.setSubject("Confirm your email");
        mimeMessageHelper.setFrom("info@hussaincode.in");
        javaMailSender.send(mimeMessage);
    }catch (MessagingException e){
        LOGGER.error("failed to send email",e);thrownew IllegalStateException("failed to send email");

    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
&lt;code&gt;&lt;/code&gt;`&lt;/p&gt;

&lt;h3&gt;
  
  
  5. For sending a mail we have used the MailDev Service.
&lt;/h3&gt;

&lt;p&gt;MailDev is a free service which we can use to send an email to user for the confirmation of registration.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyznv1k9qgg6su3y8p4ym.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyznv1k9qgg6su3y8p4ym.png" alt="MailDDev.PNG" width="800" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can install the MailDev using below commands.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To install MailDev -  $ npm install -g maildev&lt;/li&gt;
&lt;li&gt;To run MailDev -  $ maildev&lt;/li&gt;
&lt;li&gt;Once you have installed it you will get a url like to access the email service.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;MailDev webapp running at &lt;a href="http://0.0.0.0:1080" rel="noopener noreferrer"&gt;http://0.0.0.0:1080&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;MailDev SMTP Server running at 0.0.0.0:1025&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Once you get this then go to &lt;a href="http://localhost/1080" rel="noopener noreferrer"&gt;localhost/1080&lt;/a&gt; to access the MailDev.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;This is complete Registration/Login Project steps and code. If you have any doubt leave a comment and i will reply.&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Get the complete code base of this project on my &lt;a href="https://github.com/hussaincode/registrationSystem" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Like&lt;/p&gt;

&lt;p&gt;Share this&lt;/p&gt;

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