{"id":407805,"date":"2024-06-29T19:46:44","date_gmt":"2024-06-29T19:46:44","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=407805"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T19:46:44","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=407805","title":{"rendered":"<span>What are OAuth 2 and OpenID Connect\u00a0(OIDC)?<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>Author: Denys Zherdetskyi<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/76d\/7e6\/6cb\/76d7e66cb74f38796de5c4538c58b32d.png\" alt=\"\" title=\"\" width=\"1600\" height=\"811\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/76d\/7e6\/6cb\/76d7e66cb74f38796de5c4538c58b32d.png\"\/><figcaption><\/figcaption><\/figure>\n<p>Millions of users daily use features that facilitate their work with web services. The companies implement them to make their websites easy to use and safe. Good examples of those are <strong>OAuth 2 <\/strong> and <strong>OpenID Connect because <\/strong>they<strong> <\/strong>allow them to reach it.<\/p>\n<h4>What we will cover in this\u00a0article:<\/h4>\n<ol>\n<li>\n<p><a href=\"#d916\" rel=\"noopener noreferrer nofollow\">History of OAuth and flaws of prior methods<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#c281\" rel=\"noopener noreferrer nofollow\">OAuth 2 and OpenID Connect (OIDC), and the differences between them<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#c76e\" rel=\"noopener noreferrer nofollow\">Purposes of OAuth 2 and OpenID Connect (OIDC)<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#ddfb\" rel=\"noopener noreferrer nofollow\">Working principles of OAuth 2 and OpenID Connect<\/a><\/p>\n<\/li>\n<li>\n<p>The practical example of OAuth 2 working principle with GitHub OAuth usage.<\/p>\n<\/li>\n<\/ol>\n<h4>History of OAuth and flaws of prior\u00a0methods<\/h4>\n<p>Users always prefer websites full of features that would facilitate their work website. In 2004, as we know, there weren\u2019t any standards or protocols like OAuth 2 and OpenID Connect; that\u2019s why even well-known companies like Yelp implemented them as they could.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1dc\/7ea\/0ca\/1dc7ea0ca529054eca1323747a0d8991.png\" alt=\"\" title=\"\" width=\"690\" height=\"250\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1dc\/7ea\/0ca\/1dc7ea0ca529054eca1323747a0d8991.png\"\/><figcaption><\/figcaption><\/figure>\n<p>This picture shows a screenshot from an old Yelp website showing us the Yelp feature \u201cto find a friend.\u201d You could say that it is cool till the time when you will see its implementation. You needed to give your email address and PASSWORD (!) to find a friend on Yelp because it would allow the service to log in as you and get emails you wrote often.\u00a0<\/p>\n<p>Some of you would say that it is insane and cannot be accurate; however, it is. In 2004, most internet users didn\u2019t understand the basic rules that you should stick to in the \u201cnetwork\u201d and could give all their data only to use a cool feature. We should notice that, luckily, on Yelp, no one was deceived, and it was the only way for developers to implement this feature at that time. However, through the years, users became more educated, so no one wanted to give their data to anyone without protection. Developers that noticed this security flaw decided to create a standard that would allow users not to worry about their data protection and use such services easily; that\u2019s why the standard of <strong>authorization<\/strong> OAuth 1 was created. This standard still had some flaws, but it significantly shifted the security paradigm and allowed users to use cool features and not worry about their data. However, due to some problems of OAuth 1, like required cryptography, long-term living tokens, or complicated signatures, improved standard OAuth 2 was published in October 2012. It was created to solve all the problems of OAuth 1 and make using the OAuth standard easier and more secure.<\/p>\n<h3>OAuth 2 and OpenID Connect (OIDC), and the differences between\u00a0them<\/h3>\n<p>As you already know, OAuth 2 is an <strong>authorization<\/strong> (!) standard. This standard\u2019s work endpoint is an access token that allows us to manipulate or get users\u2019 data.<\/p>\n<p>Unlike OAuth 2, OpenID Connect (OIDC) is an <strong>authentication<\/strong> (!) standard. As you can see, the purpose of its usage differs from OAuth 2. Moreover, OpenID Connect (OIDC) is a standard built on OAuth 2. Developers of OIDC took the basics of OAuth 2 and expanded it with additional features that changed its shift on <strong>authentication<\/strong> from <strong>authorization<\/strong>.<\/p>\n<p>As you read before, the main difference between these standards is the field of its usage (<strong>authentication<\/strong> or <strong>authorization<\/strong>). Some people don\u2019t distinguish between authentication and authorization, which can cause faulty use of these standards in their projects.<\/p>\n<p><strong>Authorization<\/strong> is a process that gives the right to a website to access some users\u2019 data or even change it if possible and needed.<\/p>\n<p><strong>Authentication<\/strong> is a process by which the website can ensure that you have access to be who you want to be and that you are not pretending to be someone.<\/p>\n<p>Also, the significant difference is \u201cparty sides.\u201d The <strong>authorization<\/strong> is the \u201cthird party\u201d side, while authentication is the \u201cfirst party\u201d side. The difference lies in the purposes of these protocols. In <strong>authorization<\/strong>, you \u201cauthorize\u201d someone to access and manipulate your data freely. You don\u2019t participate directly in this process, so it\u2019s named the \u201cthird party\u201d side. In authentication, you prove to the website that you are someone, and it should or shouldn\u2019t allow you to access some of your data. In this process, you participate directly; that\u2019s why it\u2019s the \u201cfirst party\u201d side.<\/p>\n<h4>Purposes of OAuth 2 and OpenID Connect\u00a0(OIDC)<\/h4>\n<p>Imagine the website, where you would be able to see the alike subscriptions on YouTube with your friend. How would you implement this service? Of course, the best way and most secure way is to implement it with help of OAuth 2. Here we don\u2019t need to know who the user are, or if he is, who he is or just pretending to be, however we need to access the user\u2019s data, so receive an access to it. As we already know, this is a protocol of authorization and its endpoint is an access token. After receiving a token, the website can access only data, that we allowed it to access, so OAuth use is a brilliant way.<\/p>\n<p>Most of the time clicking the button \u201cSign In with Social Network\u201d on any website, you use OpenID Connect. If you don\u2019t need any authorization, but you need only to \u201cSign In\u201d or \u201cSign Up\u201d you use the authorization with standard OpenID Connect (OIDC).<\/p>\n<h3>Working principles of OAuth 2 and OpenID\u00a0Connect<\/h3>\n<p>To implement OAuth 2 standard on the website, the developer needs to get a <strong>client id<\/strong> and <strong>client secret<\/strong> from the service he uses ( for example, Google, GitHub, LinkedIn, Apple, etc. ). The process of OAuth 2 work is called authorization flow.<\/p>\n<p>OAuth 2 is a standard that establishes the sequence of code commands that developers should write to implement the concept.<\/p>\n<p><strong>Authorization Flow<\/strong><\/p>\n<ol>\n<li>\n<p>The user (Resource Owner) clicks the button \u201cLogin with\u00a0\u2026.\u201d<\/p>\n<\/li>\n<li>\n<p>Client (Developer\u2019s website) redirects the user to a login service using a special link that consists of <strong>client id<\/strong> (always), scope, redirect URI (always), and request type (most equals to \u201ccode\u201d).<\/p>\n<\/li>\n<li>\n<p>The link redirects to the login service, where the user can sign in with \u201clogin service\u201d or allow to use an already signed-in account.<\/p>\n<\/li>\n<li>\n<p>After the sign-in account confirmation with \u201clogin service\u201d (Authorization Server), it redirects the user to \u201credirect URI\u201d (specified by the developer in a link), sending generated authentication code in the response body or \u201credirect URI.\u201d<\/p>\n<\/li>\n<li>\n<p>After receiving a code, the website sends a POST request or redirects to a link, usually consisting of the <strong>client id<\/strong>, <strong>client secret<\/strong>, and authentication code.<\/p>\n<\/li>\n<li>\n<p>The developer should receive a generated access token for a particular user\u2019s account if he did all the steps correctly.<\/p>\n<\/li>\n<li>\n<p>After receiving an access token, the developer can send a POST request to \u201clogin service,\u201d which contains a header with an \u201cAuthorization\u201d field that equals the access token. Then after verification of the access token, the developer will be able to access data (for example, API or another allowed data).<\/p>\n<\/li>\n<\/ol>\n<h4>The practical example of OAuth 2 working principle with GitHub OAuth\u00a0usage<\/h4>\n<p>Now you will see a practical example of OAuth 2 implementation with \u201clogin service\u201d as Github. To implement OAuth 2, developer should stick to rules established  in <a href=\"#ddfb\" rel=\"noopener noreferrer nofollow\">paragraph below<\/a>.<\/p>\n<ol>\n<li>\n<p>Firstly, we need to receive\u00a0<strong>the client id<\/strong>\u00a0and\u00a0<strong>client secret<\/strong>; that&#8217;s why let&#8217;s register our app.\u00a0<\/p>\n<p>\u00a0Enter\u00a0<a href=\"https:\/\/github.com\/settings\/developers\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/settings\/developers<\/a>, log in to your GitHub account, and see a similar menu (shown below); click the &#171;New OAuth App&#187; button.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/21a\/d91\/48e\/21ad9148efd652f46398871dad5787fa.png\" alt=\"Main OAuth Apps menu in GiHub\" title=\"Main OAuth Apps menu in GiHub\" width=\"1592\" height=\"378\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/21a\/d91\/48e\/21ad9148efd652f46398871dad5787fa.png\"\/><figcaption>Main OAuth Apps menu in GiHub<\/figcaption><\/figure>\n<ol start=\"2\">\n<li>\n<p>You&#8217;ll see the form where we register our app and enter (imaginary URL).<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\n<p>Application name: MyApp<\/p>\n<\/li>\n<li>\n<p>Homepage URL:\u00a0<a href=\"http:\/\/mysite\/home\" rel=\"noopener noreferrer nofollow\">http:\/\/myapp\/<\/a><\/p>\n<\/li>\n<li>\n<p>Authorization callback URL:\u00a0<a href=\"http:\/\/mysite\/home\" rel=\"noopener noreferrer nofollow\">http:\/\/myapp\/callback<\/a><\/p>\n<\/li>\n<\/ul>\n<ol start=\"3\">\n<li>\n<p>Then you&#8217;ll receive a <strong>client id<\/strong> and <strong>client secret<\/strong>.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fd7\/fef\/4f1\/fd7fef4f16308911ec59b357a51a12c7.png\" width=\"1502\" height=\"1104\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fd7\/fef\/4f1\/fd7fef4f16308911ec59b357a51a12c7.png\"\/><figcaption><\/figcaption><\/figure>\n<ol start=\"4\">\n<li>\n<p>Then we create a link (paste all data\u00a0<strong>WITHOUT SPACES<\/strong>, it&#8217;s important), using our client id, that the user will receive after clicking the button &#171;Login with GitHub.&#187;<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">https:\/\/github.com\/login\/oauth\/authorize?client_id=your_client_id<\/code><\/pre>\n<p>   Next, we will see the user&#8217;s steps to\u00a0<strong>authorize<\/strong>\u00a0with &#171;login service.&#187;<\/p>\n<ol start=\"5\">\n<li>\n<p>Paste the link below into the search line, and you&#8217;ll see a GitHub login page (if you are not logged in). After account confirmation, you will be redirected to another link. The website is imaginary, and it is only an example, so you will not see a page, but you&#8217;ll see the changed link in\u00a0<strong>the search line<\/strong>, where &#171;home page&#187; changed to &#171;callback&#187; and generated access code before &#171;?code=&#187;.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/071\/808\/c1a\/071808c1a8051cfc5f78c1620bbbe6de.png\" width=\"712\" height=\"50\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/071\/808\/c1a\/071808c1a8051cfc5f78c1620bbbe6de.png\"\/><figcaption><\/figcaption><\/figure>\n<p>    We have just received an authorization code, so the next step we need to obtain an\u00a0<strong>access   token<\/strong>.<\/p>\n<ol start=\"6\">\n<li>\n<p>We create a final link (paste all data\u00a0<strong>WITHOUT SPACES<\/strong>, it&#8217;s important) to receive an\u00a0<strong>access token<\/strong>, so you need to fill it with your data:<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\n<p>client id<\/p>\n<\/li>\n<li>\n<p>client secret<\/p>\n<\/li>\n<li>\n<p>code (received during the prior step)<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"bash\">https:\/\/github.com\/login\/oauth\/access_token?client_id=your_client_id&amp; client_secret=your_client_secret&amp; code=your_authorization_code<\/code><\/pre>\n<ol start=\"7\">\n<li>\n<p>After entering this link into\u00a0<strong>the search line<\/strong>,<strong>\u00a0<\/strong>the txt file will download automatically. If you sticked to all the instructions and pasted all data correctly, you should receive an\u00a0<strong>access token<\/strong>, otherwise you will receive an error.<\/p>\n<\/li>\n<li>\n<p>Using this access token, we can access data using the following:<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\n<p>Application like Postman<\/p>\n<\/li>\n<li>\n<p>Curl command In Terminal<\/p>\n<\/li>\n<\/ul>\n<p>     In Postman, to access a user&#8217;s data, you need to:<\/p>\n<ul>\n<li>\n<p>Enter\u00a0<a href=\"https:\/\/api.github.com\/user\" rel=\"noopener noreferrer nofollow\">https:\/\/api.github.com\/user<\/a>\u00a0in the search<\/p>\n<\/li>\n<li>\n<p>Choose the request method as &#171;GET.&#187;<\/p>\n<\/li>\n<li>\n<p>Open the tab &#171;Headers.&#187;<\/p>\n<\/li>\n<li>\n<p>Write in the first column &#171;Authorization.&#187;<\/p>\n<\/li>\n<li>\n<p>Write in the second column, &#171;Bearer\u00a0<strong>your_access_token<\/strong>.&#187;<\/p>\n<\/li>\n<li>\n<p>Click &#171;Send&#187;<\/p>\n<\/li>\n<\/ul>\n<p>    Then you&#8217;ll see all user&#8217;s data in the response body.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/570\/e48\/ec1\/570e48ec18146112698682ea7c2bb667.png\" width=\"2146\" height=\"1338\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/570\/e48\/ec1\/570e48ec18146112698682ea7c2bb667.png\"\/><figcaption><\/figcaption><\/figure>\n<p>    In the terminal, you need to use the &#171;curl&#187; command (shown below)<\/p>\n<pre><code>curl -H \"Authorization: token your_access_token\" https:\/\/api.github.com\/user<\/code><\/pre>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/693248\/\"> https:\/\/habr.com\/ru\/articles\/693248\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>Author: Denys Zherdetskyi<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>Millions of users daily use features that facilitate their work with web services. The companies implement them to make their websites easy to use and safe. Good examples of those are <strong>OAuth 2 <\/strong> and <strong>OpenID Connect because <\/strong>they<strong> <\/strong>allow them to reach it.<\/p>\n<h4>What we will cover in this\u00a0article:<\/h4>\n<ol>\n<li>\n<p><a href=\"#d916\" rel=\"noopener noreferrer nofollow\">History of OAuth and flaws of prior methods<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#c281\" rel=\"noopener noreferrer nofollow\">OAuth 2 and OpenID Connect (OIDC), and the differences between them<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#c76e\" rel=\"noopener noreferrer nofollow\">Purposes of OAuth 2 and OpenID Connect (OIDC)<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#ddfb\" rel=\"noopener noreferrer nofollow\">Working principles of OAuth 2 and OpenID Connect<\/a><\/p>\n<\/li>\n<li>\n<p>The practical example of OAuth 2 working principle with GitHub OAuth usage.<\/p>\n<\/li>\n<\/ol>\n<h4>History of OAuth and flaws of prior\u00a0methods<\/h4>\n<p>Users always prefer websites full of features that would facilitate their work website. In 2004, as we know, there weren\u2019t any standards or protocols like OAuth 2 and OpenID Connect; that\u2019s why even well-known companies like Yelp implemented them as they could.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>This picture shows a screenshot from an old Yelp website showing us the Yelp feature \u201cto find a friend.\u201d You could say that it is cool till the time when you will see its implementation. You needed to give your email address and PASSWORD (!) to find a friend on Yelp because it would allow the service to log in as you and get emails you wrote often.\u00a0<\/p>\n<p>Some of you would say that it is insane and cannot be accurate; however, it is. In 2004, most internet users didn\u2019t understand the basic rules that you should stick to in the \u201cnetwork\u201d and could give all their data only to use a cool feature. We should notice that, luckily, on Yelp, no one was deceived, and it was the only way for developers to implement this feature at that time. However, through the years, users became more educated, so no one wanted to give their data to anyone without protection. Developers that noticed this security flaw decided to create a standard that would allow users not to worry about their data protection and use such services easily; that\u2019s why the standard of <strong>authorization<\/strong> OAuth 1 was created. This standard still had some flaws, but it significantly shifted the security paradigm and allowed users to use cool features and not worry about their data. However, due to some problems of OAuth 1, like required cryptography, long-term living tokens, or complicated signatures, improved standard OAuth 2 was published in October 2012. It was created to solve all the problems of OAuth 1 and make using the OAuth standard easier and more secure.<\/p>\n<h3>OAuth 2 and OpenID Connect (OIDC), and the differences between\u00a0them<\/h3>\n<p>As you already know, OAuth 2 is an <strong>authorization<\/strong> (!) standard. This standard\u2019s work endpoint is an access token that allows us to manipulate or get users\u2019 data.<\/p>\n<p>Unlike OAuth 2, OpenID Connect (OIDC) is an <strong>authentication<\/strong> (!) standard. As you can see, the purpose of its usage differs from OAuth 2. Moreover, OpenID Connect (OIDC) is a standard built on OAuth 2. Developers of OIDC took the basics of OAuth 2 and expanded it with additional features that changed its shift on <strong>authentication<\/strong> from <strong>authorization<\/strong>.<\/p>\n<p>As you read before, the main difference between these standards is the field of its usage (<strong>authentication<\/strong> or <strong>authorization<\/strong>). Some people don\u2019t distinguish between authentication and authorization, which can cause faulty use of these standards in their projects.<\/p>\n<p><strong>Authorization<\/strong> is a process that gives the right to a website to access some users\u2019 data or even change it if possible and needed.<\/p>\n<p><strong>Authentication<\/strong> is a process by which the website can ensure that you have access to be who you want to be and that you are not pretending to be someone.<\/p>\n<p>Also, the significant difference is \u201cparty sides.\u201d The <strong>authorization<\/strong> is the \u201cthird party\u201d side, while authentication is the \u201cfirst party\u201d side. The difference lies in the purposes of these protocols. In <strong>authorization<\/strong>, you \u201cauthorize\u201d someone to access and manipulate your data freely. You don\u2019t participate directly in this process, so it\u2019s named the \u201cthird party\u201d side. In authentication, you prove to the website that you are someone, and it should or shouldn\u2019t allow you to access some of your data. In this process, you participate directly; that\u2019s why it\u2019s the \u201cfirst party\u201d side.<\/p>\n<h4>Purposes of OAuth 2 and OpenID Connect\u00a0(OIDC)<\/h4>\n<p>Imagine the website, where you would be able to see the alike subscriptions on YouTube with your friend. How would you implement this service? Of course, the best way and most secure way is to implement it with help of OAuth 2. Here we don\u2019t need to know who the user are, or if he is, who he is or just pretending to be, however we need to access the user\u2019s data, so receive an access to it. As we already know, this is a protocol of authorization and its endpoint is an access token. After receiving a token, the website can access only data, that we allowed it to access, so OAuth use is a brilliant way.<\/p>\n<p>Most of the time clicking the button \u201cSign In with Social Network\u201d on any website, you use OpenID Connect. If you don\u2019t need any authorization, but you need only to \u201cSign In\u201d or \u201cSign Up\u201d you use the authorization with standard OpenID Connect (OIDC).<\/p>\n<h3>Working principles of OAuth 2 and OpenID\u00a0Connect<\/h3>\n<p>To implement OAuth 2 standard on the website, the developer needs to get a <strong>client id<\/strong> and <strong>client secret<\/strong> from the service he uses ( for example, Google, GitHub, LinkedIn, Apple, etc. ). The process of OAuth 2 work is called authorization flow.<\/p>\n<p>OAuth 2 is a standard that establishes the sequence of code commands that developers should write to implement the concept.<\/p>\n<p><strong>Authorization Flow<\/strong><\/p>\n<ol>\n<li>\n<p>The user (Resource Owner) clicks the button \u201cLogin with\u00a0\u2026.\u201d<\/p>\n<\/li>\n<li>\n<p>Client (Developer\u2019s website) redirects the user to a login service using a special link that consists of <strong>client id<\/strong> (always), scope, redirect URI (always), and request type (most equals to \u201ccode\u201d).<\/p>\n<\/li>\n<li>\n<p>The link redirects to the login service, where the user can sign in with \u201clogin service\u201d or allow to use an already signed-in account.<\/p>\n<\/li>\n<li>\n<p>After the sign-in account confirmation with \u201clogin service\u201d (Authorization Server), it redirects the user to \u201credirect URI\u201d (specified by the developer in a link), sending generated authentication code in the response body or \u201credirect URI.\u201d<\/p>\n<\/li>\n<li>\n<p>After receiving a code, the website sends a POST request or redirects to a link, usually consisting of the <strong>client id<\/strong>, <strong>client secret<\/strong>, and authentication code.<\/p>\n<\/li>\n<li>\n<p>The developer should receive a generated access token for a particular user\u2019s account if he did all the steps correctly.<\/p>\n<\/li>\n<li>\n<p>After receiving an access token, the developer can send a POST request to \u201clogin service,\u201d which contains a header with an \u201cAuthorization\u201d field that equals the access token. Then after verification of the access token, the developer will be able to access data (for example, API or another allowed data).<\/p>\n<\/li>\n<\/ol>\n<h4>The practical example of OAuth 2 working principle with GitHub OAuth\u00a0usage<\/h4>\n<p>Now you will see a practical example of OAuth 2 implementation with \u201clogin service\u201d as Github. To implement OAuth 2, developer should stick to rules established  in <a href=\"#ddfb\" rel=\"noopener noreferrer nofollow\">paragraph below<\/a>.<\/p>\n<ol>\n<li>\n<p>Firstly, we need to receive\u00a0<strong>the client id<\/strong>\u00a0and\u00a0<strong>client secret<\/strong>; that&#8217;s why let&#8217;s register our app.\u00a0<\/p>\n<p>\u00a0Enter\u00a0<a href=\"https:\/\/github.com\/settings\/developers\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/settings\/developers<\/a>, log in to your GitHub account, and see a similar menu (shown below); click the &#171;New OAuth App&#187; button.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><figcaption>Main OAuth Apps menu in GiHub<\/figcaption><\/figure>\n<ol start=\"2\">\n<li>\n<p>You&#8217;ll see the form where we register our app and enter (imaginary URL).<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\n<p>Application name: MyApp<\/p>\n<\/li>\n<li>\n<p>Homepage URL:\u00a0<a href=\"http:\/\/mysite\/home\" rel=\"noopener noreferrer nofollow\">http:\/\/myapp\/<\/a><\/p>\n<\/li>\n<li>\n<p>Authorization callback URL:\u00a0<a href=\"http:\/\/mysite\/home\" rel=\"noopener noreferrer nofollow\">http:\/\/myapp\/callback<\/a><\/p>\n<\/li>\n<\/ul>\n<ol start=\"3\">\n<li>\n<p>Then you&#8217;ll receive a <strong>client id<\/strong> and <strong>client secret<\/strong>.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<ol start=\"4\">\n<li>\n<p>Then we create a link (paste all data\u00a0<strong>WITHOUT SPACES<\/strong>, it&#8217;s important), using our client id, that the user will receive after clicking the button &#171;Login with GitHub.&#187;<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"bash\">https:\/\/github.com\/login\/oauth\/authorize?client_id=your_client_id<\/code><\/pre>\n<p>   Next, we will see the user&#8217;s steps to\u00a0<strong>authorize<\/strong>\u00a0with &#171;login service.&#187;<\/p>\n<ol start=\"5\">\n<li>\n<p>Paste the link below into the search line, and you&#8217;ll see a GitHub login page (if you are not logged in). After account confirmation, you will be redirected to another link. The website is imaginary, and it is only an example, so you will not see a page, but you&#8217;ll see the changed link in\u00a0<strong>the search line<\/strong>, where &#171;home page&#187; changed to &#171;callback&#187; and generated access code before &#171;?code=&#187;.<\/p>\n<\/li>\n<\/ol>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>    We have just received an authorization code, so the next step we need to obtain an\u00a0<strong>access   token<\/strong>.<\/p>\n<ol start=\"6\">\n<li>\n<p>We create a final link (paste all data\u00a0<strong>WITHOUT SPACES<\/strong>, it&#8217;s important) to receive an\u00a0<strong>access token<\/strong>, so you need to fill it with your data:<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\n<p>client id<\/p>\n<\/li>\n<li>\n<p>client secret<\/p>\n<\/li>\n<li>\n<p>code (received during the prior step)<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"bash\">https:\/\/github.com\/login\/oauth\/access_token?client_id=your_client_id&amp; client_secret=your_client_secret&amp; code=your_authorization_code<\/code><\/pre>\n<ol start=\"7\">\n<li>\n<p>After entering this link into\u00a0<strong>the search line<\/strong>,<strong>\u00a0<\/strong>the txt file will download automatically. If you sticked to all the instructions and pasted all data correctly, you should receive an\u00a0<strong>access token<\/strong>, otherwise you will receive an error.<\/p>\n<\/li>\n<li>\n<p>Using this access token, we can access data using the following:<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\n<p>Application like Postman<\/p>\n<\/li>\n<li>\n<p>Curl command In Terminal<\/p>\n<\/li>\n<\/ul>\n<p>     In Postman, to access a user&#8217;s data, you need to:<\/p>\n<ul>\n<li>\n<p>Enter\u00a0<a href=\"https:\/\/api.github.com\/user\" rel=\"noopener noreferrer nofollow\">https:\/\/api.github.com\/user<\/a>\u00a0in the search<\/p>\n<\/li>\n<li>\n<p>Choose the request method as &#171;GET.&#187;<\/p>\n<\/li>\n<li>\n<p>Open the tab &#171;Headers.&#187;<\/p>\n<\/li>\n<li>\n<p>Write in the first column &#171;Authorization.&#187;<\/p>\n<\/li>\n<li>\n<p>Write in the second column, &#171;Bearer\u00a0<strong>your_access_token<\/strong>.&#187;<\/p>\n<\/li>\n<li>\n<p>Click &#171;Send&#187;<\/p>\n<\/li>\n<\/ul>\n<p>    Then you&#8217;ll see all user&#8217;s data in the response body.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>    In the terminal, you need to use the &#171;curl&#187; command (shown below)<\/p>\n<pre><code>curl -H \"Authorization: token your_access_token\" https:\/\/api.github.com\/user<\/code><\/pre>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/693248\/\"> https:\/\/habr.com\/ru\/articles\/693248\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-407805","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/407805","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=407805"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/407805\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=407805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=407805"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=407805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}