Reputation: 4963
With Hubot I am trying to access specific issues through JIRA REST api.
url = http://myserver.com/jira/rest/api/2/search?jql=status="open"+AND+assignee=null
robot.http(url).get() (err, res, body) ->
# some code
Hubot fails to reach the server. Proxies are all set properly. The REST api works as expected through the browser once logged in.
Thus I need to specify authentication.
What I tried so far (plain basic authentication):
robot.http(url).auth('user', 'pass'). ...
robot.http(url).header('Authentication', 'user:password'). ...
robot.http('http://user:password@someurl'). ...
Hubot keeps telling me that the server was not found. How do I properly pass authentication through http?
Upvotes: 0
Views: 1877
Reputation: 345
you need to get the basic auth creds in the right format I think.
user = process.env.DNSIMPLE_USERNAME
pass = process.env.DNSIMPLE_PASSWORD
auth = 'Basic ' + new Buffer(user + ':' + pass).toString('base64')
then you need to pass the auth
variable in
robot.http(url)
.headers(Authorization: auth, Accept: 'application/json')
.get() (err, res, body) ->
#some code
Upvotes: 0
Reputation: 105
This is a snippet from hubot-confluence plugin It should be the same for authenticating with Jira. This is basic access authentication. You can look up the btoa method but what is does is convert binary to base64 encoded ascii. As far as I know there are already lots of scripts for connecting to Jira with hubot.
make_headers = ->
user = nconf.get("HUBOT_CONFLUENCE_USER")
password = nconf.get("HUBOT_CONFLUENCE_PASSWORD")
auth = btoa("#{user}:#{password}")
ret =
Accept: "application/json"
Authorization: "Basic #{auth}"
And you have it correct for making the robot.http call
headers = make_headers()
robot.http(url)
.headers(headers)
.get() (error, response, body) ->
Upvotes: 1