Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httr: authentication issue to access JIRA API #584

Closed
fm555 opened this issue Apr 3, 2019 · 2 comments
Closed

httr: authentication issue to access JIRA API #584

fm555 opened this issue Apr 3, 2019 · 2 comments

Comments

@fm555
Copy link

fm555 commented Apr 3, 2019

I am trying to access a JIRA API with httr in R and I am having authentication issues.
I am also using proxy at work, but I found this link (#417) very useful (thank you!), because I could solve the proxy authentication error (407),.. but now I have error 401.

I am using the following code:

library(httr)
library(jsonlite)

url_jira_ini<-"https://jira.host/jira/rest/auth/1/session"
url_jira<-"https://jira.host/jira/rest/api/2/long_name"

credentials<-"username:password"
credentials <- base64_enc(credentials)
header_auth <- paste0("Basic ",credentials)

GET(url_jira,
add_headers(Authorization = header_auth),
set_cookies(atlassian.xsrf.token = "long_cookie_1",
JSESSIONID = "long_cookie_2"),
authenticate(user = "myusername",password = "mypassword",type="basic"),use_proxy("proxy.host",8080,username="myusername",password="mypassword", auth="basic"),verbose(),accept_json())

But after that I am getting error 401. I have tried without adding add_headers and set_cookies, but it still gives the same error.

I have tried to modify the use_proxy username and password and gives proxy authentication error (407) when I am using the wrong username and password (401 if they are correct).

But if I modify the username and password in the authenticate section, when I use wrong password and username it still gives error 401 (if the use_proxy section is using the correct username and password). When I use the correct password and username in authenticate also gives error 401.

In the first lines of the verbose output, it says 200 connection established, but in the following lines it appears status 401.

I could access to the JIRA API successfully using Postman (not the latest official Postman release, but a beta version, Postman Canary, which allowed to configure proxy with authentication). To access with Postman I had to first send a POST to url_jira_ini (the authentication site), and after that it generates 2 cookies (atlassian.xsrf.token and JSESSIONID), then I could send a GET to url_jira (the JIRA API that I want to access), which is using basic authentication and the cookie JSESSIONID to access the JIRA API.

In Postman, I have to add the following line in the body (raw):

{"username": "myusername" , "password" : "mypassword" }

Would it be possible to add a body in httr, keeping exactly the same line above used in Postman?
I tried to create a body (list) with that line, but it gives error. Any suggestions?

In case it may be useful, to access the JIRA API in Postman Canary (after configuring the proxy for authentication), I followed the next steps:

  • Delete all cookies previously generated by JIRA.
  • In the Authorization section, add Authorization "BasicAuth", and include username and password.
  • In the Body section, select "Raw" and "JSON (application/json)". And in the Body add the following text:
    {"username": "myusername" , "password" : "mypassword" }
  • Send a POST to the JIRA API authentication (url_jira_ini)
  • Check if it gives 200, and that it gives a JSESSIONID in the cookies (token needed to access the JIRA API).
  • Send a GET to the JIRA API (url_jira)

What should I do to access the JIRA API with httr?
Should I add additional headers in httr?

Please let me know if you need more information.
I need to solve this issue as soon as possible.
Thank you.

@cderv
Copy link
Contributor

cderv commented Apr 4, 2019

For reference, this question is also on the community website
https://community.rstudio.com/t/httr-authentication-issue-to-access-jira-api/27685/2

@hadley
Copy link
Member

hadley commented Apr 28, 2019

This seems like a community question, not a github issue.

@hadley hadley closed this as completed Apr 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants