{"id":1474,"date":"2021-03-25T15:52:46","date_gmt":"2021-03-25T15:52:46","guid":{"rendered":"https:\/\/blog.samarthya.me\/wps\/?p=1474"},"modified":"2021-03-25T15:52:56","modified_gmt":"2021-03-25T15:52:56","slug":"oauth-2-0","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2021\/03\/25\/oauth-2-0\/","title":{"rendered":"oAuth: 2.0"},"content":{"rendered":"<h1>What is OAuth?<\/h1>\n<p>From the official <a href=\"https:\/\/oauth.net\/2\/\">definition<\/a><\/p>\n\n\n<figure class=\"wp-block-pullquote has-background has-luminous-vivid-orange-background-color is-style-solid-color\"><blockquote class=\"has-text-color has-white-color\"><p>It is protocol for Authorization<\/p><\/blockquote><\/figure>\n\n\n\n<p>It allows authorization flows for web applications, desktop applications, mobile apps etc.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"550\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-8.51.28-PM-1024x550.png\" alt=\"\" class=\"wp-image-1479\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-8.51.28-PM-1024x550.png 1024w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-8.51.28-PM-300x161.png 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-8.51.28-PM-768x412.png 768w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-8.51.28-PM.png 1214w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Protocol flow<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Key components<\/h2>\n\n\n\n<p>The 3 key components of OAuth are as under<\/p>\n\n\n\n<h3 class=\"has-black-color has-vivid-green-cyan-background-color has-text-color has-background wp-block-heading\">A. Roles\/Actors<\/h3>\n\n\n\n<p>oAuth RFC defines 4 roles<\/p>\n\n\n\n<h4 class=\"has-pale-pink-background-color has-background has-large-font-size wp-block-heading\">1. resource owner       <\/h4>\n\n\n\n<p class=\"has-white-background-color has-background has-medium-font-size\">An entity capable of granting access to a protected resource. When the resource owner is a person, it is referred to as an end-user.  It can be a company as well.<\/p>\n\n\n\n<h4 class=\"has-black-color has-pale-pink-background-color has-text-color has-background has-large-font-size wp-block-heading\">2. resource server       <\/h4>\n\n\n\n<p class=\"has-white-background-color has-background has-medium-font-size\">The server hosting the protected resources, capable of accepting       and responding to protected resource requests using access tokens.    <\/p>\n\n\n\n<h3 class=\"has-pale-pink-background-color has-background has-large-font-size wp-block-heading\">3. client<\/h3>\n\n\n\n<p class=\"has-white-background-color has-background has-medium-font-size\">An application making protected resource requests on behalf of the resource owner and with its <em><code>authorization<\/code><\/em>.  The term &#8220;client&#8221; does not imply any particular implementation characteristics (e.g., whether the application executes on a server, a desktop, or other devices).    <\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p class=\"has-drop-cap has-black-color has-white-background-color has-text-color has-background has-medium-font-size\">OAuth defines two client types, based on their ability to authenticate securely with the <code>authorization server<\/code> (i.e., ability to maintain the confidentiality of their client credentials):    <\/p>\n\n\n\n<h4 class=\"has-medium-font-size wp-block-heading\">confidential       <\/h4>\n\n\n\n<p class=\"has-white-background-color has-background has-medium-font-size\">Clients capable of maintaining the confidentiality of their credentials (e.g., client implemented on a secure server with restricted access to the client credentials), or capable of secure client authentication using other means.  <\/p>\n\n\n\n<h4 class=\"has-medium-font-size wp-block-heading\"> public       <\/h4>\n\n\n\n<p class=\"has-white-background-color has-background has-medium-font-size\">Clients incapable of maintaining the confidentiality of their credentials (e.g., clients executing on the device used by the resource owner, such as an installed native application or a web browser-based application), and incapable of secure client       authentication via any other means.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/d33wubrfki0l68.cloudfront.net\/21d485e203c19fedeae1bc4142f2f056b577c0fb\/c3cdb\/assets-jekyll\/blog\/oauth\/oauth-clients-93fc6cc8e83fa7d885c9daa0ed88007fc44780b99682dcfa580af319894870c7.png\" alt=\"\"\/><\/figure>\n<\/div><\/div>\n\n\n\n<h4 class=\"has-black-color has-pale-pink-background-color has-text-color has-background has-large-font-size wp-block-heading\">4. authorization server       <\/h4>\n\n\n\n<p class=\"has-white-background-color has-background has-medium-font-size\">The server issuing access tokens to the client after successfully       authenticating the resource owner and obtaining <code>authorization<\/code>.<\/p>\n\n\n\n<h3 class=\"has-vivid-green-cyan-background-color has-background wp-block-heading\">B. Scopes and Consent<\/h3>\n\n\n\n<p>Scopes is what you see when you are shown a confirmation dialog while requesting service from a provider that initiates the flow. These are coded by the application developer when writing the application. Scopes decouple <code>authorization<\/code> policy decisions from <code>enforcement<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/d33wubrfki0l68.cloudfront.net\/99bea281c4d8758b97fe07ded0136019b0ed75f6\/3da15\/assets-jekyll\/blog\/oauth\/oauth-actors-cd8b4861e839037400d8521e97c5d8cf0cb029add65d1036488991c7e85dcb72.png\" alt=\"\"\/><\/figure>\n\n\n\n<h3 class=\"has-vivid-green-cyan-background-color has-background wp-block-heading\">C. Tokens<\/h3>\n\n\n\n<p>To request an access token, the client obtains <code>authorization<\/code> from the <code>resource owner<\/code>.  The authorization is expressed in the form of an <code>authorization grant<\/code>, which the client uses to request the <code>access token<\/code>.  OAuth defines four grant types: <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>authorization code<\/code>, <\/li><li><code>implicit<\/code>, <\/li><li><code>resource owner<\/code> <code>password credentials<\/code> <\/li><li><code>client credentials<\/code>.<\/li><\/ul>\n\n\n\n<p>It also provides an extension mechanism for defining additional <code>grant types<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" width=\"1024\" height=\"543\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-8.16.07-PM-1-1024x543.png\" alt=\"\" class=\"wp-image-1477\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-8.16.07-PM-1-1024x543.png 1024w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-8.16.07-PM-1-300x159.png 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-8.16.07-PM-1-768x407.png 768w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-8.16.07-PM-1.png 1048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>From the official documentation<\/figcaption><\/figure>\n\n\n\n<h4 class=\"has-pale-cyan-blue-background-color has-background wp-block-heading\">Access tokens<\/h4>\n\n\n\n<p class=\"has-black-color has-white-background-color has-text-color has-background has-medium-font-size\">Access tokens are credentials used to access protected resources.<\/p>\n\n\n\n<p class=\"has-white-background-color has-background has-medium-font-size\">An access token is a string representing an <code>authorization<\/code> issued to the client. Tokens represent specific <code>scopes<\/code> and <code>durations<\/code> of access, granted by the resource owner, and enforced by the resource server and authorization server. The access token provides an abstraction layer, replacing different <code>authorization<\/code> constructs (e.g., username and password) with a single token understood by the resource server. <\/p>\n\n\n\n<h4 class=\"has-pale-cyan-blue-background-color has-background wp-block-heading\">Refresh Tokens<\/h4>\n\n\n\n<p class=\"has-white-background-color has-background has-medium-font-size\">Refresh tokens are credentials used to obtain access tokens.<\/p>\n\n\n\n<p class=\"has-white-background-color has-background has-medium-font-size\">Refresh tokens are issued to the client by the <code>authorization server<\/code> and are used to obtain a new access token when the current access token becomes invalid or expires, or to obtain additional access tokens with identical or narrower scope.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" src=\"https:\/\/d33wubrfki0l68.cloudfront.net\/ae5a3d0fc17cec4af40096e6f67b7b93d02dcdab\/17da8\/assets-jekyll\/blog\/oauth\/authorization-server-99a4ad01368a4c8e407917358d4394d573a6c0e3c9fa10c01a59d1a54c4938cf.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Flows<\/h2>\n\n\n\n<p>Obtaining authorization and subsequent token has 4 main flows<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Implicit flow\/grant<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>All communication happens through browser<\/li><li>Optimized for public clients<\/li><li>An access token is returned directly from the <code>authorization request<\/code> (front channel only).<\/li><li>Does not support issuance of refresh tokens.<\/li><li>These clients are typically implemented in a browser using a scripting language such as <code>JavaScript<\/code>. (SPA&#8217;s)<\/li><li>The implicit grant type does not include <code>client authentication<\/code> and relies on the presence of the <code>resource owner<\/code> and the registration of the <code>redirection URI<\/code>.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img decoding=\"async\" width=\"1024\" height=\"878\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-9.02.32-PM-1024x878.png\" alt=\"\" class=\"wp-image-1478\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-9.02.32-PM-1024x878.png 1024w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-9.02.32-PM-300x257.png 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-9.02.32-PM-768x658.png 768w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-9.02.32-PM.png 1150w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Authorization code flow\/3 legged flow<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"700\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-9.02.06-PM-1024x700.png\" alt=\"\" class=\"wp-image-1480\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-9.02.06-PM-1024x700.png 1024w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-9.02.06-PM-300x205.png 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-9.02.06-PM-768x525.png 768w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-9.02.06-PM.png 1152w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>The authorization code grant type is used to obtain both <code>access tokens<\/code> and <code>refresh tokens<\/code> and is optimized for <code>confidential clients<\/code>.<\/li><li>Uses the front channel for <code>authorization<\/code> and the <code>back channel<\/code> for <code>tokens<\/code>.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Client credential flow<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"239\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-9.13.43-PM-1024x239.png\" alt=\"\" class=\"wp-image-1481\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-9.13.43-PM-1024x239.png 1024w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-9.13.43-PM-300x70.png 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-9.13.43-PM-768x179.png 768w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2021\/03\/Screenshot-2021-03-25-at-9.13.43-PM.png 1064w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>For server to server scenarios<\/li><li>Client is confidential<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Resource Owner Password flow<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>The resource owner password credentials is suitable in cases where the resource owner has a trust relationship with the client, such as the device operating system or a highly privileged application<\/li><li>It is suitable for clients capable of obtaining the resource owner&#8217;s credentials (username and password, typically using an interactive form).<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Help<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" href=\"https:\/\/tools.ietf.org\/html\/rfc6749\" target=\"_blank\">https:\/\/tools.ietf.org\/html\/rfc6749<\/a><\/li><li><a href=\"https:\/\/developer.okta.com\/blog\/2017\/06\/21\/what-the-heck-is-oauth\">https:\/\/developer.okta.com\/blog\/2017\/06\/21\/what-the-heck-is-oauth<\/a><\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is OAuth? From the official definition It is protocol for Authorization It allows authorization flows for web applications, desktop applications, mobile apps etc. Key components The 3 key components of OAuth are as under A. Roles\/Actors oAuth RFC defines 4 roles 1. resource owner An entity capable of granting access to a protected resource. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1476,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[34],"tags":[177],"class_list":["post-1474","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-technical","tag-oauth","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/1474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=1474"}],"version-history":[{"count":0,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/1474\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media\/1476"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=1474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=1474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=1474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}