<?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 Re: Passing Cookies From Custom Auth Handler In REST Modular Input in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204168#M21599</link>
    <description>&lt;P&gt;Are you also using a custom response handler in responsehandlers.py ? The default response handler is supposed to persist cookies for you.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Sep 2015 00:59:36 GMT</pubDate>
    <dc:creator>Damien_Dallimor</dc:creator>
    <dc:date>2015-09-03T00:59:36Z</dc:date>
    <item>
      <title>Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204163#M21594</link>
      <description>&lt;P&gt;&lt;STRONG&gt;FULL DISCLOSURE:  I have asked REST questions before, this is for a completely separate array vendor than my previous questions&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I have a SAN that requires an api token to be posted to a URL to initiate a session before a REST query will run. &lt;/P&gt;

&lt;P&gt;I have a custom authentication module configured.  And if I dump the response value, I can see that it is initiating the session correctly.  (I get a response 200 and the username of the token I supplied, which is what is expected)&lt;/P&gt;

&lt;P&gt;However, I get a "401 Unauthorized" when I enable the input.  So it looks like the authentication module is not passing the session cookie back to the modular input itself.&lt;/P&gt;

&lt;P&gt;Here is what my auth module looks like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;class PureSessionKeyAuth(AuthBase):

        def __init__(self,**args):
                self.auth_url = args['auth_url']
                self.api_token= args['api_token']
                pass

        def __call__(self, r):

                #perform auth
                headers = {'content-type': 'application/json'}
                token = {"api_token":self.api_token}
                req_args = {"verify" : False}
                auth_response = requests.post(self.auth_url,data=json.dumps(token),headers=headers,**req_args)
                response_json = json.loads(auth_response.text)

#  Use this to dump the values to validate if it is working correctly
#               f = open( 'values.dump', 'w' )
#               f.write( 'dict = ' + repr(token)+ '\n' + repr(auth_response) + '\n' + repr(response_json)    +'\n' )
#               f.close()

# I have tried the below code send the cookies back, with no luck.
                cookies = auth_response.cookies
                if cookies:
                        r.cookies = cookies
                return r
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I do not get any errors on run other than the "401 Unauthorized" in splunkd when the input is enabled.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2015 20:19:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204163#M21594</guid>
      <dc:creator>david_rose</dc:creator>
      <dc:date>2015-09-02T20:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204164#M21595</link>
      <description>&lt;P&gt;Are you sure you have the right permissions setup in the target system? Just the fact that login work, does not guarantee access to a specific resource.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2015 21:35:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204164#M21595</guid>
      <dc:creator>mreynov_splunk</dc:creator>
      <dc:date>2015-09-02T21:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204165#M21596</link>
      <description>&lt;P&gt;Yes.  I can duplicate the steps in Postman which I use to validate my REST calls.  It is not a permissions issue.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2015 21:37:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204165#M21596</guid>
      <dc:creator>david_rose</dc:creator>
      <dc:date>2015-09-02T21:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204166#M21597</link>
      <description>&lt;P&gt;Are you sure you aren't supposed to be sending that token as a header?&lt;/P&gt;

&lt;P&gt;Here is an example of a working token auth handler I've written:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;class TokenAuth(AuthBase):
  def __init__(self, username, password, domain, url, **kwargs):
    headers={'Content-Type':'application/json'}
    body=json.dumps({'userName':username, 'password':password, 'authLoginDomain': domain})
    r = requests.post(verify=False, url=url, headers=headers, data=body)
    if r.status_code==200 and 'sessionID' in r.json():
      self.sessionID = r.json()['sessionID']
    else:
      raise RequestException('Could not authenticate')
    pass

  def __call__(self, r):
    r.headers.update({'auth':self.sessionID, 'Content-Type':'application/json'})
    return r
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Sep 2015 21:58:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204166#M21597</guid>
      <dc:creator>rmdfrb</dc:creator>
      <dc:date>2015-09-02T21:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204167#M21598</link>
      <description>&lt;P&gt;Yes Im sure its not added as a header.  When you post with the api token in the body, it replies with a cookie with a 30 minute expiration which contains the session information.  I need to forward that cookie back to the input from the custom auth handler.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2015 22:01:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204167#M21598</guid>
      <dc:creator>david_rose</dc:creator>
      <dc:date>2015-09-02T22:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204168#M21599</link>
      <description>&lt;P&gt;Are you also using a custom response handler in responsehandlers.py ? The default response handler is supposed to persist cookies for you.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2015 00:59:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204168#M21599</guid>
      <dc:creator>Damien_Dallimor</dc:creator>
      <dc:date>2015-09-03T00:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204169#M21600</link>
      <description>&lt;P&gt;One idea, have you tried wiring Splunk and Postman up to make requests through a recording HTTP reverse proxy (such as &lt;A href="http://www.charlesproxy.com/"&gt;Charles Proxy&lt;/A&gt; ) to compare the actual over the wire requests and responses from both? I wonder if that could confirm if no cookie is being added, or maybe something is getting garbled in translation.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2015 01:13:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204169#M21600</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-09-03T01:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204170#M21601</link>
      <description>&lt;P&gt;Not using a custom response handler.  &lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2015 02:23:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204170#M21601</guid>
      <dc:creator>david_rose</dc:creator>
      <dc:date>2015-09-03T02:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204171#M21602</link>
      <description>&lt;P&gt;Ahh thats a good idea.  I will give that a shot.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2015 02:24:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204171#M21602</guid>
      <dc:creator>david_rose</dc:creator>
      <dc:date>2015-09-03T02:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204172#M21603</link>
      <description>&lt;P&gt;Is my custom auth configured correctly for returning the cookie?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2015 22:01:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204172#M21603</guid>
      <dc:creator>david_rose</dc:creator>
      <dc:date>2015-09-08T22:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204173#M21604</link>
      <description>&lt;P&gt;Looks fine to me.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2015 23:23:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204173#M21604</guid>
      <dc:creator>Damien_Dallimor</dc:creator>
      <dc:date>2015-09-08T23:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204174#M21605</link>
      <description>&lt;P&gt;Looking at my inputs.conf, the cookie is not getting written back.  There is no cookie field at all for this particular rest endpoint.  I do see a cookie entry for other endpoints that don't require a custom auth handler.&lt;/P&gt;

&lt;P&gt;The cookie I captured is in the following format if it helps.  I'll keep trying in the mean time:&lt;/P&gt;

&lt;P&gt;eJxFjMsKgzAQAH-l7NnDqlVqwEuhv9AeJftoKRgjm3gS_71WCj0OM8wKw6wW_KRTBpdt0QJGn_KgZtHA4Q9NOZocbHFUcCucCBzcH41R6Gp69T1sBaS3HG7ZXHrlXEqWqlE-Iz4JywqlrYUaj9x1335JapMP_yFXt8z1Nck-hm37ACghMaA.CNH60A.OfsdfgghosQol-GjpfDncvj5YuVs&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:11:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204174#M21605</guid>
      <dc:creator>david_rose</dc:creator>
      <dc:date>2020-09-29T07:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204175#M21606</link>
      <description>&lt;P&gt;PROGRESS!&lt;/P&gt;

&lt;P&gt;While I could never get the cookie to pass back with the code above, i was able to get it by manually passing the cookie back in the header via this code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def __call__(self, r):

        #perform auth
        headers = {'content-type': 'application/json'}
        token = {"api_token":self.api_token}
        req_args = {"verify" : False}
        s=requests.session()
        auth_response = s.post(self.auth_url,data=json.dumps(token),headers=headers,**req_args)
        cookieheader = 'session=' + auth_response.cookies['session']
        r.headers['Cookie'] = cookieheader
        return r
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I get the response indexed just fine, BUT, it runs every second, which of course is a no go.  Looking at the splunkd log, the output looks similar to when you save changes to the input.  &lt;/P&gt;

&lt;P&gt;Any Thoughts?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2015 02:15:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204175#M21606</guid>
      <dc:creator>david_rose</dc:creator>
      <dc:date>2015-09-10T02:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204176#M21607</link>
      <description>&lt;P&gt;I have locked down the issue to the &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;cookieheader = "session=" + auth_response.cookies['session']
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Section of my code.  If i change the first session to an invalid value, i get an unauthorized.  If I leave it as is, it gets stuck in a loop.&lt;/P&gt;

&lt;P&gt;I also noticed these in splunkd.log:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sNS/nobody/search/data/inputs/rest/Pure%20Test%20DAL/: Broken pipe
09-11-2015 15:15:42.295 -0500 WARN  HttpListener - Socket error from 127.0.0.1 while accessing /servicesNS/nobody/search/data/inputs/rest/Pure%20Test%20DAL/: Broken pipe
09-11-2015 15:15:42.924 -0500 WARN  HttpListener - Socket error from 127.0.0.1 while accessing /services/data/inputs/ta_ontap_collection_worker/Pure%20Test%20DAL: Broken pipe
09-11-2015 15:16:04.290 -0500 WARN  HttpListener - Socket error from 127.0.0.1 while accessing /servicesNS/nobody/search/data/inputs/rest/Pure%20Test%20DAL/: Broken pipe
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Especially strange is the listener warning that references ta-ontap-collection-worker.  That seams to change.  It said snmp earlier...&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2015 20:21:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204176#M21607</guid>
      <dc:creator>david_rose</dc:creator>
      <dc:date>2015-09-11T20:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204177#M21608</link>
      <description>&lt;P&gt;I was able to get around this issue excessive restarting issue by creating my own python script utilizing the Requests library outside of splunk and monitoring the output folder.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2015 22:27:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204177#M21608</guid>
      <dc:creator>david_rose</dc:creator>
      <dc:date>2015-09-29T22:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Cookies From Custom Auth Handler In REST Modular Input</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204178#M21609</link>
      <description>&lt;P&gt;I have just been looking at an issue to fetch data from an endpoint that requires this approach. What I found is that setting the r.cookies values does NOT work, but setting the cookie directly in the header does...&lt;/P&gt;

&lt;P&gt;e..g: This doesn't work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if cookies:
   r.cookies = cookies
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but this does:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if cookies and "myauthcookiename" in cookies:
  r.headers['Cookie'] = "myauthcookiename=" + cookies["myauthcookiename"])
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Sep 2018 05:02:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Passing-Cookies-From-Custom-Auth-Handler-In-REST-Modular-Input/m-p/204178#M21609</guid>
      <dc:creator>datasearchninja</dc:creator>
      <dc:date>2018-09-19T05:02:21Z</dc:date>
    </item>
  </channel>
</rss>

