<?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>question OAuth 2.0 grant authorization_code redirects to oauth_login.do in Community Central forum</title>
    <link>https://www.servicenow.com/community/community-central-forum/oauth-2-0-grant-authorization-code-redirects-to-oauth-login-do/m-p/3284877#M3343</link>
    <description>&lt;P&gt;I am very new to servicenow and if I need to post this somewhere else please let me know.&amp;nbsp; I am trying to create an OAuth code flow from an external service.&amp;nbsp; This is how I have my servicenow application registry configured:&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025-06-09 12_28_13-Application-Registries.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/447624i7AA5AD1A9F2C109D/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="2025-06-09 12_28_13-Application-Registries.png" alt="2025-06-09 12_28_13-Application-Registries.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;When I make the OAuth code grant flow request everything works as expected and I receive the authorization code.&amp;nbsp; However, when I grant type authorization_code request I am redirected to&amp;nbsp;&lt;A href="https://dev#.service-now.com/oauth_login.do" target="_blank"&gt;https://dev#.service-now.com/oauth_login.do&lt;/A&gt;&amp;nbsp;URL and I do not receive an access token as expected.&lt;BR /&gt;&lt;BR /&gt;I am making this request from a Laravel PHP controller so there is no user to complete the login page.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a snippet of my PHP code:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;       $fields = [
                'grant_type'  =&amp;gt; 'authorization_code',
                'client_id' =&amp;gt; $fields-&amp;gt;client,
                'client_secret' =&amp;gt; $fields-&amp;gt;secret,
                'code' =&amp;gt; $q['code'],
                'redirect_uri'  =&amp;gt; "$hostUrl/externalurl/oauth/response",
                'response_type' =&amp;gt; 'code',
                'state' =&amp;gt; $q['state']
            ];

            //url-ify the data for the POST
            $fields_string = http_build_query($fields);

            //open connection
            $ch = curl_init();

            //set the url, number of POST vars, POST data
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'cache-control: no-cache',
                'content-type: application/x-www-form-urlencoded'
            ));
            curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

            $result = curl_exec($ch);&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Jun 2025 17:44:08 GMT</pubDate>
    <dc:creator>rerogers</dc:creator>
    <dc:date>2025-06-09T17:44:08Z</dc:date>
    <item>
      <title>OAuth 2.0 grant authorization_code redirects to oauth_login.do</title>
      <link>https://www.servicenow.com/community/community-central-forum/oauth-2-0-grant-authorization-code-redirects-to-oauth-login-do/m-p/3284877#M3343</link>
      <description>&lt;P&gt;I am very new to servicenow and if I need to post this somewhere else please let me know.&amp;nbsp; I am trying to create an OAuth code flow from an external service.&amp;nbsp; This is how I have my servicenow application registry configured:&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025-06-09 12_28_13-Application-Registries.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/447624i7AA5AD1A9F2C109D/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="2025-06-09 12_28_13-Application-Registries.png" alt="2025-06-09 12_28_13-Application-Registries.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;When I make the OAuth code grant flow request everything works as expected and I receive the authorization code.&amp;nbsp; However, when I grant type authorization_code request I am redirected to&amp;nbsp;&lt;A href="https://dev#.service-now.com/oauth_login.do" target="_blank"&gt;https://dev#.service-now.com/oauth_login.do&lt;/A&gt;&amp;nbsp;URL and I do not receive an access token as expected.&lt;BR /&gt;&lt;BR /&gt;I am making this request from a Laravel PHP controller so there is no user to complete the login page.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a snippet of my PHP code:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;       $fields = [
                'grant_type'  =&amp;gt; 'authorization_code',
                'client_id' =&amp;gt; $fields-&amp;gt;client,
                'client_secret' =&amp;gt; $fields-&amp;gt;secret,
                'code' =&amp;gt; $q['code'],
                'redirect_uri'  =&amp;gt; "$hostUrl/externalurl/oauth/response",
                'response_type' =&amp;gt; 'code',
                'state' =&amp;gt; $q['state']
            ];

            //url-ify the data for the POST
            $fields_string = http_build_query($fields);

            //open connection
            $ch = curl_init();

            //set the url, number of POST vars, POST data
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'cache-control: no-cache',
                'content-type: application/x-www-form-urlencoded'
            ));
            curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

            $result = curl_exec($ch);&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jun 2025 17:44:08 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/oauth-2-0-grant-authorization-code-redirects-to-oauth-login-do/m-p/3284877#M3343</guid>
      <dc:creator>rerogers</dc:creator>
      <dc:date>2025-06-09T17:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: OAuth 2.0 grant authorization_code redirects to oauth_login.do</title>
      <link>https://www.servicenow.com/community/community-central-forum/oauth-2-0-grant-authorization-code-redirects-to-oauth-login-do/m-p/3285058#M3345</link>
      <description>&lt;P&gt;I figured out what I was doing wrong, I was reusing the authentication code route instead of the oauth token route.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jun 2025 23:10:12 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/oauth-2-0-grant-authorization-code-redirects-to-oauth-login-do/m-p/3285058#M3345</guid>
      <dc:creator>rerogers</dc:creator>
      <dc:date>2025-06-09T23:10:12Z</dc:date>
    </item>
  </channel>
</rss>

