curl failing to authenticate to ServiceNow

deon2
Kilo Contributor

Hey guys,

Having some trouble authenticating to our instance using wget/curl.

I'm trying to automatically fetch a report each morning. The built-in email feature won't suffice as I can't easily make the jump from 'email attachment' to 'file saved in a shared location'.

I tried using the code from a blog post I found. My output is below:

curl --cookie-jar cjar -k -o output1.log --location "https://(myinstancename).service-now.com"

Running this returns:

              <html>

      <head>

              <META HTTP-EQUIV="expires" CONTENT="0">

      </head>

      <body>

              <form method="POST" enctype="application/x-www-form-urlencoded" action="(link to single-sign on page)"></form>

              <script>

                      <!--

                              document.forms[0].submit();

                      -->

              </script>

      </body>

</html>

then I pass my credentials to the login page using curl:

curl --cookie cjar --cookie-jar cjar -k -o output2.log --data user_name=admin --data user_password=admin --data ni.nolog.user_password=true --data ni.noecho.user_name=true --data ni.noecho.user_password=true --data remember_me=true --data screensize=1920x1080 --data sys_action=sysverb_login --location "https://(myinstancename).service-now.com/login.do"

The output of which is a login page containing an authentication error:

<img class="outputmsg_image" title="Error Message" src="images/outputmsg_error_24.gifx"></img><div class="outputmsg_text">User name or password invalid</div>

I can login without issue using http://myinstancename.service-now.com/login.do in IE but am pulling my hair out trying to work out why this keeps rejecting the login when POSTing the data to login.do from curl.

Any guidance is appreciated... of course if there is another way I can have a report saved to a folder automatically (or programmatically, rather) - that solution would fit fine too!

Cheers,

Deon.

1 REPLY 1

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hi Deon,



It works on my own test instance, without issues:



sergiu.panaite ~ $ curl --cookie cjar --cookie-jar cjar -k -o output2.log --data user_name=XXXXX --data user_password=XXXXX --data ni.nolog.user_password=true --data ni.noecho.user_name=true --data ni.noecho.user_password=true --data remember_me=true --data screensize=1920x1080 --data sys_action=sysverb_login --location "https://empspanaite.service-now.com/login.do"


  % Total       % Received % Xferd   Average Speed     Time       Time         Time   Current


                                                                Dload   Upload     Total     Spent       Left   Speed


100     184       0         0   100     184           0       519 --:--:-- --:--:-- --:--:--     519


  0         0       0 23160       0         0   34535           0 --:--:-- --:--:-- --:--:-- 34535


sergiu.panaite ~ $


Are you using single sign on? If yes, then you should maybe try authenticating via side_door.do rather than login.do:



External Authentication (Single Sign-On - SSO) - ServiceNow Wiki



Regards,


Sergiu