{"id":851,"date":"2024-01-15T13:58:09","date_gmt":"2024-01-15T13:58:09","guid":{"rendered":"https:\/\/olxdoc.wpenginepowered.com\/?p=851"},"modified":"2024-01-29T10:05:13","modified_gmt":"2024-01-29T10:05:13","slug":"grant-type-authorization_code","status":"publish","type":"post","link":"https:\/\/doc.olxgroup.com\/api\/?p=851","title":{"rendered":"Grant type: authorization_code"},"content":{"rendered":"\r\n<h2>Grant type: authorization_code<\/h2>\r\n<p>Client must specify Callback URL. You can specify more than one Callback URL. Please avoid special chars like<strong> &amp;<\/strong>\u00a0(multiple), <strong>#<\/strong>\u00a0in Callback URL.<\/p>\r\n<p><strong>Flow:<\/strong><\/p>\r\n<p>On Application site user clicks on button &#8220;Authenticate with OLX&#8221;.<\/p>\r\n<p>Auth URL: \/oauth\/authorize\/?client_id=XXX&amp;response_type=code&amp;state=XXX&amp;scope=read write v2&amp;redirect_uri=XXX<\/p>\r\n<p>Parameter <strong>state<\/strong>\u00a0is optional. It will be returned in step 4 so application can validate if response is not crafted by someone else.<\/p>\r\n<p>Parameter <strong>redirect_uri<\/strong> is optional if you specified only one Callback URL. If you have more than one Callback URL parameter <strong>redirect_uri<\/strong> is mandatory. Please avoid special chars like <strong>&amp;<\/strong> (multiple),<strong> #<\/strong>\u00a0in redirect_uri.<\/p>\r\n<p>URL will be used in step 4. <strong>redirect_uri<\/strong>\u00a0should base on defined earlier Callback URL.<\/p>\r\n<p>Example:<\/p>\r\n<p>Callback URL:\u00a0<a href=\"http:\/\/myadomain.com\/auth\/connect\">http:\/\/myadomain.com\/auth\/connect<\/a><\/p>\r\n<p>Auth URL:\u00a0<a href=\"https:\/\/www.olx.ro\/oauth\/authorize\/?client_id=123&amp;response_type=code&amp;state=x93ld3v&amp;scope=read+write+v2&amp;redirect_uri=http:\/\/myadomain.com\/auth\/connect\">https:\/\/www.olx.ro\/oauth\/authorize\/?client_id=123&amp;response_type=code&amp;state=x93ld3v&amp;scope=read+write+v2&amp;redirect_uri=http:\/\/myadomain.com\/auth\/connect<\/a><\/p>\r\n<p>Example 2:<\/p>\r\n<p>Callback URL:\u00a0<a href=\"http:\/\/myadomain.com\/auth\/connect\">http:\/\/myadomain.com\/auth\/connect<\/a><\/p>\r\n<p>Auth URL:\u00a0<a href=\"https:\/\/www.olx.ro\/oauth\/authorize\/?client_id=123&amp;response_type=code&amp;state=x93ld3v&amp;scope=read+write+v2\">https:\/\/www.olx.ro\/oauth\/authorize\/?client_id=123&amp;response_type=code&amp;state=x93ld3v&amp;scope=read+write+v2<\/a><\/p>\r\n<p>If you have only one Callback URL you don&#8217;t have to pass <strong>redirect_uri<\/strong>\u00a0parameter.<\/p>\r\n<p>User is redirected to OLX login screen User logs in and authorize client User is redirected back to <strong>redirect_uri<\/strong> with some additional query parameters: <strong>code<\/strong> and <strong>state<\/strong>\u00a0(optional).<\/p>\r\n<p>Example:\u00a0<a href=\"http:\/\/myadomain.com\/auth\/connect?code=d34feg43g456g&amp;state=x93ld3v\">http:\/\/myadomain.com\/auth\/connect?code=d34feg43g456g&amp;state=x93ld3v<\/a><\/p>\r\n<p>Application exchange received <strong>code<\/strong> to access token by grant type <strong>authorization_code<\/strong>.<\/p>\r\n<p>Request to get access token, sent to <strong>\/api\/open\/oauth\/token<\/strong>\u00a0endpoint, should have:<\/p>\r\n<p><code>{\r\n   \"grant_type\" : \"authorization_code\",\r\n   \"client_id\" : \"\",\r\n   \"client_secret\" : \"\",\r\n   \"code\" : \"\",\r\n   \"scope\" : \"v2 read write\",\r\n   \"redirect_uri\" : \"http:\/\/myadomain.com\/auth\/connect\"\r\n}\t\t\t<\/code> <button>Copy<\/button> { &#8220;grant_type&#8221; : &#8220;authorization_code&#8221;, &#8220;client_id&#8221; : &#8220;&#8221;, &#8220;client_secret&#8221; : &#8220;&#8221;, &#8220;code&#8221; : &#8220;&#8221;, &#8220;scope&#8221; : &#8220;v2 read write&#8221;, &#8220;redirect_uri&#8221; : &#8220;http:\/\/myadomain.com\/auth\/connect&#8221; } Copied to clipboard<\/p>\r\n<p>Note: <strong>redirect_uri<\/strong> parameter is optional unless you use parameter <strong>redirect_uri<\/strong> in Auth URL in step 1. If you use <strong>redirect_uri<\/strong> in step 1, then <strong>redirect_uri<\/strong>\u00a0is also mandatory in request in step 5.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Grant type: authorization_code Client must specify Callback URL. You can specify more than one Callback URL. Please avoid special chars like &amp;\u00a0(multiple), #\u00a0in Callback URL. Flow: On Application site user clicks on button &#8220;Authenticate with OLX&#8221;. Auth URL: \/oauth\/authorize\/?client_id=XXX&amp;response_type=code&amp;state=XXX&amp;scope=read write v2&amp;redirect_uri=XXX Parameter state\u00a0is optional. It will be returned in step 4 so application can validate&#8230;  <a href=\"https:\/\/doc.olxgroup.com\/api\/?p=851\" title=\"Read Grant type: authorization_code\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/doc.olxgroup.com\/api\/index.php?rest_route=\/wp\/v2\/posts\/851"}],"collection":[{"href":"https:\/\/doc.olxgroup.com\/api\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/doc.olxgroup.com\/api\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/doc.olxgroup.com\/api\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/doc.olxgroup.com\/api\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=851"}],"version-history":[{"count":0,"href":"https:\/\/doc.olxgroup.com\/api\/index.php?rest_route=\/wp\/v2\/posts\/851\/revisions"}],"wp:attachment":[{"href":"https:\/\/doc.olxgroup.com\/api\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/doc.olxgroup.com\/api\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/doc.olxgroup.com\/api\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}