<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic 403 error receiving the OAuth token in ArcGIS Online Developers Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-developers-questions/403-error-receiving-the-oauth-token/m-p/1322892#M1267</link>
    <description>&lt;P&gt;I'm developing an add-on for the django library-allauth 0.54.0 (&lt;A href="https://www.intenct.nl/projects/django-allauth/" target="_blank"&gt;https://www.intenct.nl/projects/django-allauth/&lt;/A&gt;).&amp;nbsp;I want to add an ArcGIS account authentication module to this library.&lt;BR /&gt;&lt;BR /&gt;I've read your OAuth integration documentation carefully&lt;BR /&gt;(&lt;A href="https://developers.arcgis.com/documentation/mapping-apis-and-services/security/oauth-2.0/" target="_blank"&gt;https://developers.arcgis.com/documentation/mapping-apis-and-services/security/oauth-2.0/&lt;/A&gt;)&lt;BR /&gt;&lt;BR /&gt;I created an account, created an application. Received the public and secret keys. Added the necessary redirect urls :&lt;BR /&gt;1. local - &lt;A href="http://127.0.0.1:8000/accounts/arcgis/login/callback/," target="_blank"&gt;http://127.0.0.1:8000/accounts/arcgis/login/callback/&lt;/A&gt;&lt;BR /&gt;2. local + ngrok - &lt;A href="https://….ngrok-free.app/accounts/arcgis/login/callback/" target="_blank"&gt;https://….ngrok-free.app/accounts/arcgis/login/callback/&lt;/A&gt;&lt;BR /&gt;3. prodaction -&amp;nbsp;https://...io/accounts/arcgis/login/callback/&lt;BR /&gt;&lt;BR /&gt;Currently, I have this module ready. It works well locally,&amp;nbsp;locally + ngrok and didn't give any crashes. But prodaction often has&amp;nbsp;questions when receiving a token.&lt;BR /&gt;&lt;BR /&gt;Here is my part of the code where the error occurs:&lt;BR /&gt;&lt;BR /&gt;resp = requests.request(&lt;BR /&gt;&amp;nbsp; &amp;nbsp;self.access_token_method,&lt;BR /&gt;&amp;nbsp; &amp;nbsp;url,&lt;BR /&gt;&amp;nbsp; &amp;nbsp;data=data,&lt;BR /&gt;&amp;nbsp; &amp;nbsp;auth=auth,&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;self.access_token_method = ‘POST’&lt;BR /&gt;url = '&lt;A href="https://www.arcgis.com/sharing/rest/oauth2/token" target="_blank"&gt;https://www.arcgis.com/sharing/rest/oauth2/token&lt;/A&gt;'&lt;BR /&gt;data = {&lt;BR /&gt;&amp;nbsp; &amp;nbsp;'redirect_uri': 'https://…/accounts/arcgis/login/callback/'&lt;BR /&gt;&amp;nbsp; &amp;nbsp;'grant_type': 'authorization_code',&lt;BR /&gt;&amp;nbsp; &amp;nbsp;'code':&lt;BR /&gt;'o9DGl2OY7JRDSwvinUTRJy7jSHy3D9p-ftLIPNiWXgMDtA-JcsQ3cucXm1V-OcoJCrB0G05CX_iErKl9TK2LsYC-bf5eDcRa5O88heoxvwpWRnBuLoVpx1Bw8FPZ8QqBVVmu4lhN-C4I3f&lt;BR /&gt;uSe6sZEvyQ3jGTa7V1xcbhxELw02S96t-yO_8ZAJhZ-WQg_Jybzq3s3LsBM0EQe7r9301JE1&lt;BR /&gt;W5-sLQd-YrKkjc909t4d5zrUi-XzMNyUtD4v-KD5fc',&lt;BR /&gt;&amp;nbsp; &amp;nbsp;'client_id': &amp;lt;my_client_app_id&amp;gt;,&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;P.S. I get the ‘code’ parameter from the redirect url. Example:&lt;BR /&gt;&amp;lt;WSGIRequest: GET&lt;BR /&gt;'/accounts/arcgis/login/callback/?code='o9DGl2OY7JRDSwvinUTRJy7jSHy3D9p-ftLIPNiWX&lt;BR /&gt;gMDtA-JcsQ3cucXm1V-OcoJCrB0G05CX_iErKl9TK2LsYC-bf5eDcRa5O88heoxvwpWRnBu&lt;BR /&gt;LoVpx1Bw8FPZ8QqBVVmu4lhN-C4I3fuSe6sZEvyQ3jGTa7V1xcbhxELw02S96t-yO_8ZAJhZ&lt;BR /&gt;-WQg_Jybzq3s3LsBM0EQe7r9301JE1W5-sLQd-YrKkjc909t4d5zrUi-XzMNyUtD4v-KD5fc&amp;amp;st&lt;BR /&gt;ate=YcoUuwg0Nvni'&amp;gt;&lt;BR /&gt;&lt;BR /&gt;For this request (locally and locally + ngrok), I get a response with the status 200 and&lt;BR /&gt;the following data:&lt;BR /&gt;{&lt;BR /&gt;'access_token': 'Nn35y22fGaSqrrzkkbGQp…',&lt;BR /&gt;'expires_in': 1800,&lt;BR /&gt;'username': 'username',&lt;BR /&gt;'ssl': True,&lt;BR /&gt;'refresh_token': '53Anf42u0nwrDCGgm…',&lt;BR /&gt;'refresh_token_expires_in': 1209599,&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;BUT when a similar situation occurs on prodaction&amp;nbsp;(https://...io/), I get a response with the status 403, with&lt;BR /&gt;the following data:&lt;BR /&gt;&lt;BR /&gt;raise OAuth2Error("Error retrieving access token: %s" % resp. content)&lt;BR /&gt;oauthlib. oauth2. rfc6749. errors. OAuth2Error: (None) Error retrieving access token:&lt;BR /&gt;b'&amp;lt;html&amp;gt;\r\n&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;403 Forbidden&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;\r\n&amp;lt;body&amp;gt;\r\n&amp;lt;center&amp;gt;&amp;lt;h1&amp;gt;403&lt;BR /&gt;Forbidden&amp;lt;/h1&amp;gt;&amp;lt;/center&amp;gt;\r\n&amp;lt;hr&amp;gt;&amp;lt;center&amp;gt;nginx&amp;lt;/center&amp;gt;\r\n&amp;lt;/body&amp;gt;\r\n&amp;lt;/html&amp;gt;\r\n'&lt;BR /&gt;&lt;BR /&gt;10.42.2.48 - - [24/Aug/2023:11:57:45 -0400] "GET&lt;BR /&gt;/accounts/arcgis/login/callback/?code=JiYZNXrTrbg8_o7f0o7QY3blC_T34SoxubESKNpBr3z&lt;BR /&gt;9pxKFb5m5J0oxwbW4yNDRdVuVt-ZGL3gmIo349zpLQDEqm1Lf2rRbnK2MTQMPKl6Of3-n&lt;BR /&gt;WLO8BBsNOYaZQ37LfP6PZ0SIkcrHkgJ7ESgALlMKA7mRilHiCSPF-R9UwSqJfww_tOiQCS&lt;BR /&gt;KEhbVwrWhuKDcFly9QGh4SWlTRNFgdOmimaXyuDwwkdcRFDiIa6dGWyPi9pcoqVhrzNG&lt;BR /&gt;YQw2Xx835nG5yela53XT73nj7-mg&amp;amp;state=BujTt0IhiPDX HTTP/1.1" 302 0&lt;BR /&gt;"&lt;A href="https://www.arcgis.com/" target="_blank"&gt;https://www.arcgis.com/&lt;/A&gt;" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,&lt;BR /&gt;like Gecko) Chrome/116.0.0.0 Safari/537.36"&lt;BR /&gt;&lt;BR /&gt;PS&lt;BR /&gt;it also often happens on prodaction that I get the parameter ‘code’ at the end of which&lt;BR /&gt;there are two dots. For example:?code=YQw2Xx835nG5yela53XT73nj7-mg..&lt;BR /&gt;Sometimes, if you delete these points, you will receive a 200 response with&lt;BR /&gt;the desired token later. (this doesn't always happen). An error was excluded when extracting this&lt;BR /&gt;parameter in our code. This ‘code ' comes from your server.&lt;BR /&gt;&lt;BR /&gt;Also, if I get a 403 response to prodaction, I quickly send the same&lt;BR /&gt;request with the same data via Postman and get a 200 response.I.e. the problem occurs exactly on prodaction.&lt;BR /&gt;&lt;BR /&gt;Please, tell me what the problem may be and how to fix it?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 28 Aug 2023 08:25:42 GMT</pubDate>
    <dc:creator>AdamKuc</dc:creator>
    <dc:date>2023-08-28T08:25:42Z</dc:date>
    <item>
      <title>403 error receiving the OAuth token</title>
      <link>https://community.esri.com/t5/arcgis-online-developers-questions/403-error-receiving-the-oauth-token/m-p/1322892#M1267</link>
      <description>&lt;P&gt;I'm developing an add-on for the django library-allauth 0.54.0 (&lt;A href="https://www.intenct.nl/projects/django-allauth/" target="_blank"&gt;https://www.intenct.nl/projects/django-allauth/&lt;/A&gt;).&amp;nbsp;I want to add an ArcGIS account authentication module to this library.&lt;BR /&gt;&lt;BR /&gt;I've read your OAuth integration documentation carefully&lt;BR /&gt;(&lt;A href="https://developers.arcgis.com/documentation/mapping-apis-and-services/security/oauth-2.0/" target="_blank"&gt;https://developers.arcgis.com/documentation/mapping-apis-and-services/security/oauth-2.0/&lt;/A&gt;)&lt;BR /&gt;&lt;BR /&gt;I created an account, created an application. Received the public and secret keys. Added the necessary redirect urls :&lt;BR /&gt;1. local - &lt;A href="http://127.0.0.1:8000/accounts/arcgis/login/callback/," target="_blank"&gt;http://127.0.0.1:8000/accounts/arcgis/login/callback/&lt;/A&gt;&lt;BR /&gt;2. local + ngrok - &lt;A href="https://….ngrok-free.app/accounts/arcgis/login/callback/" target="_blank"&gt;https://….ngrok-free.app/accounts/arcgis/login/callback/&lt;/A&gt;&lt;BR /&gt;3. prodaction -&amp;nbsp;https://...io/accounts/arcgis/login/callback/&lt;BR /&gt;&lt;BR /&gt;Currently, I have this module ready. It works well locally,&amp;nbsp;locally + ngrok and didn't give any crashes. But prodaction often has&amp;nbsp;questions when receiving a token.&lt;BR /&gt;&lt;BR /&gt;Here is my part of the code where the error occurs:&lt;BR /&gt;&lt;BR /&gt;resp = requests.request(&lt;BR /&gt;&amp;nbsp; &amp;nbsp;self.access_token_method,&lt;BR /&gt;&amp;nbsp; &amp;nbsp;url,&lt;BR /&gt;&amp;nbsp; &amp;nbsp;data=data,&lt;BR /&gt;&amp;nbsp; &amp;nbsp;auth=auth,&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;self.access_token_method = ‘POST’&lt;BR /&gt;url = '&lt;A href="https://www.arcgis.com/sharing/rest/oauth2/token" target="_blank"&gt;https://www.arcgis.com/sharing/rest/oauth2/token&lt;/A&gt;'&lt;BR /&gt;data = {&lt;BR /&gt;&amp;nbsp; &amp;nbsp;'redirect_uri': 'https://…/accounts/arcgis/login/callback/'&lt;BR /&gt;&amp;nbsp; &amp;nbsp;'grant_type': 'authorization_code',&lt;BR /&gt;&amp;nbsp; &amp;nbsp;'code':&lt;BR /&gt;'o9DGl2OY7JRDSwvinUTRJy7jSHy3D9p-ftLIPNiWXgMDtA-JcsQ3cucXm1V-OcoJCrB0G05CX_iErKl9TK2LsYC-bf5eDcRa5O88heoxvwpWRnBuLoVpx1Bw8FPZ8QqBVVmu4lhN-C4I3f&lt;BR /&gt;uSe6sZEvyQ3jGTa7V1xcbhxELw02S96t-yO_8ZAJhZ-WQg_Jybzq3s3LsBM0EQe7r9301JE1&lt;BR /&gt;W5-sLQd-YrKkjc909t4d5zrUi-XzMNyUtD4v-KD5fc',&lt;BR /&gt;&amp;nbsp; &amp;nbsp;'client_id': &amp;lt;my_client_app_id&amp;gt;,&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;P.S. I get the ‘code’ parameter from the redirect url. Example:&lt;BR /&gt;&amp;lt;WSGIRequest: GET&lt;BR /&gt;'/accounts/arcgis/login/callback/?code='o9DGl2OY7JRDSwvinUTRJy7jSHy3D9p-ftLIPNiWX&lt;BR /&gt;gMDtA-JcsQ3cucXm1V-OcoJCrB0G05CX_iErKl9TK2LsYC-bf5eDcRa5O88heoxvwpWRnBu&lt;BR /&gt;LoVpx1Bw8FPZ8QqBVVmu4lhN-C4I3fuSe6sZEvyQ3jGTa7V1xcbhxELw02S96t-yO_8ZAJhZ&lt;BR /&gt;-WQg_Jybzq3s3LsBM0EQe7r9301JE1W5-sLQd-YrKkjc909t4d5zrUi-XzMNyUtD4v-KD5fc&amp;amp;st&lt;BR /&gt;ate=YcoUuwg0Nvni'&amp;gt;&lt;BR /&gt;&lt;BR /&gt;For this request (locally and locally + ngrok), I get a response with the status 200 and&lt;BR /&gt;the following data:&lt;BR /&gt;{&lt;BR /&gt;'access_token': 'Nn35y22fGaSqrrzkkbGQp…',&lt;BR /&gt;'expires_in': 1800,&lt;BR /&gt;'username': 'username',&lt;BR /&gt;'ssl': True,&lt;BR /&gt;'refresh_token': '53Anf42u0nwrDCGgm…',&lt;BR /&gt;'refresh_token_expires_in': 1209599,&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;BUT when a similar situation occurs on prodaction&amp;nbsp;(https://...io/), I get a response with the status 403, with&lt;BR /&gt;the following data:&lt;BR /&gt;&lt;BR /&gt;raise OAuth2Error("Error retrieving access token: %s" % resp. content)&lt;BR /&gt;oauthlib. oauth2. rfc6749. errors. OAuth2Error: (None) Error retrieving access token:&lt;BR /&gt;b'&amp;lt;html&amp;gt;\r\n&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;403 Forbidden&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;\r\n&amp;lt;body&amp;gt;\r\n&amp;lt;center&amp;gt;&amp;lt;h1&amp;gt;403&lt;BR /&gt;Forbidden&amp;lt;/h1&amp;gt;&amp;lt;/center&amp;gt;\r\n&amp;lt;hr&amp;gt;&amp;lt;center&amp;gt;nginx&amp;lt;/center&amp;gt;\r\n&amp;lt;/body&amp;gt;\r\n&amp;lt;/html&amp;gt;\r\n'&lt;BR /&gt;&lt;BR /&gt;10.42.2.48 - - [24/Aug/2023:11:57:45 -0400] "GET&lt;BR /&gt;/accounts/arcgis/login/callback/?code=JiYZNXrTrbg8_o7f0o7QY3blC_T34SoxubESKNpBr3z&lt;BR /&gt;9pxKFb5m5J0oxwbW4yNDRdVuVt-ZGL3gmIo349zpLQDEqm1Lf2rRbnK2MTQMPKl6Of3-n&lt;BR /&gt;WLO8BBsNOYaZQ37LfP6PZ0SIkcrHkgJ7ESgALlMKA7mRilHiCSPF-R9UwSqJfww_tOiQCS&lt;BR /&gt;KEhbVwrWhuKDcFly9QGh4SWlTRNFgdOmimaXyuDwwkdcRFDiIa6dGWyPi9pcoqVhrzNG&lt;BR /&gt;YQw2Xx835nG5yela53XT73nj7-mg&amp;amp;state=BujTt0IhiPDX HTTP/1.1" 302 0&lt;BR /&gt;"&lt;A href="https://www.arcgis.com/" target="_blank"&gt;https://www.arcgis.com/&lt;/A&gt;" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,&lt;BR /&gt;like Gecko) Chrome/116.0.0.0 Safari/537.36"&lt;BR /&gt;&lt;BR /&gt;PS&lt;BR /&gt;it also often happens on prodaction that I get the parameter ‘code’ at the end of which&lt;BR /&gt;there are two dots. For example:?code=YQw2Xx835nG5yela53XT73nj7-mg..&lt;BR /&gt;Sometimes, if you delete these points, you will receive a 200 response with&lt;BR /&gt;the desired token later. (this doesn't always happen). An error was excluded when extracting this&lt;BR /&gt;parameter in our code. This ‘code ' comes from your server.&lt;BR /&gt;&lt;BR /&gt;Also, if I get a 403 response to prodaction, I quickly send the same&lt;BR /&gt;request with the same data via Postman and get a 200 response.I.e. the problem occurs exactly on prodaction.&lt;BR /&gt;&lt;BR /&gt;Please, tell me what the problem may be and how to fix it?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2023 08:25:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-developers-questions/403-error-receiving-the-oauth-token/m-p/1322892#M1267</guid>
      <dc:creator>AdamKuc</dc:creator>
      <dc:date>2023-08-28T08:25:42Z</dc:date>
    </item>
  </channel>
</rss>

