{"id":1551,"date":"2022-07-25T09:08:25","date_gmt":"2022-07-24T21:08:25","guid":{"rendered":"https:\/\/www.ronella.xyz\/?p=1551"},"modified":"2024-04-11T14:23:21","modified_gmt":"2024-04-11T02:23:21","slug":"authorization-code-grant-type","status":"publish","type":"post","link":"https:\/\/www.ronella.xyz\/?p=1551","title":{"rendered":"Authorization Code Grant Type"},"content":{"rendered":"<p>The authorization code grant type is designed for <strong>confidential clients<\/strong> <em>(e.g. websites with a server back end)<\/em> that can keep a secret. This type can request for <strong>offline_access<\/strong> scope <em>(i.e. to request for refresh token)<\/em>.<\/p>\n<ol>\n<li>\n<p>Use the authorization end point to <strong>request the authorization code<\/strong> with the following query parameters:<\/p>\n<pre><code>response_type = code \nclient_id = the client unique code\nredirect_uri = redirection URL.\nstate = (Optional) value to echo to us.\nscope = (Optional) what permision wanted. If not specified, default permission will be given.\nresponse_mode = (Optional) query<\/code><\/pre>\n<blockquote>\n<p>A login form will be displayed if not yet filled-up before.<\/p>\n<\/blockquote>\n<p><strong>Expected Response<\/strong><\/p>\n<p>The redirect_uri with the following query parameters:<\/p>\n<pre><code>code = The authorization code\nstate = state value if given.<\/code><\/pre>\n<\/li>\n<li>\n<p>Use the token end point to do <strong>post request for the access token<\/strong> with the following headers:<\/p>\n<pre><code>Content-Type = application\/x-www-form-urlencoded\nAuthorization = Basic &lt;CREDENTIAL&gt;<\/code><\/pre>\n<p>And with the following parameters:<\/p>\n<pre><code>grant_type = authorization_code.\ncode = The authorization code from step 1.\nredirect_uri = The used from step 1.<\/code><\/pre>\n<p><strong>Expected Response<\/strong><\/p>\n<p>Header<\/p>\n<pre><code>Content-Type: application\/json\n\n{\n\"access_token\" : &lt;ACCESS_TOKEN&gt;,\n\"token_type\" : \"Bearer\",\n\"expires_in\" : 3600,\n\"scope\" : &lt;The scope allowed by the server&gt;\n}<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>Call the API<\/strong> with the authorization header like the following syntax:<\/p>\n<pre><code>Bearer &lt;ACCESS_TOKEN&gt;<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>Sample implementation can be found <a href=\"https:\/\/github.com\/rcw3bb\/sample-auth-code-grant\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The authorization code grant type is designed for confidential clients (e.g. websites with a server back end) that can keep a secret. This type can request for offline_access scope (i.e. to request for refresh token). Use the authorization end point to request the authorization code with the following query parameters: response_type = code client_id = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[77,23],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1551"}],"collection":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1551"}],"version-history":[{"count":5,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1551\/revisions"}],"predecessor-version":[{"id":1766,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1551\/revisions\/1766"}],"wp:attachment":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}