How do I make OmniAuth Identity accept JSON post data? - ruby-on-rails

I'm using OmniAuth-Identity for log ins, and logging in using Ajax calls. Attempts to log in passing JSON data don't work.
For instance this works:
curl -i -H "Accept: application/json" -d "auth_key=joe#example.com&password=cheesestix" "http://0.0.0.0:3000/auth/identity/callback"
This doesn't, it returns "invalid credentials"
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -d '{"auth_key":"joe#example.com","password":"cheesestix"}' "http://0.0.0.0:3000/auth/identity/callback"
Is this a known issue? Form encoding my data will be difficult as I'm using AngularJS.
UPDATE:
One of the rails guys fixed it by backporting JSON support into Rack.
gem 'rack', git: 'https://github.com/ssoroka/rack.git', branch: '1.5.2-json-support-backport'
I'm hesitant to post that as an answer becase I don't understand the details of Rack well enough to explain anything. But the relevant diff is here: https://github.com/ssoroka/rack/commit/d8e2e2af6da57805d2f0906ce925ea150def31a0

Related

Swagger UI generating wrong Curl command

Swagger UI generating wrong Curl command as pasted below and due to this query string truncating
curl -X GET http://domain:8080/v1/endpoint?access_token=affsfafasfa&type=1 -H "accept: application/json" -H "content-type: application/json"
the correct Curl command should be like this
curl -X GET 'http://domain:8080/v1/endpoint?access_token=affsfafasfa&type=1' -H "accept: application/json" -H "content-type: application/json"
the difference between above two command is quote around http url . So please tell me how to achieve this in swagger ui ?
I guess you found a bug in the new version. The very latest code already contains a fix for it.
Its an bug in swagger ui version 3.0.2 and swagger support team has fixed this bug now https://github.com/swagger-api/swagger-ui/issues/2839

Getting Issues via REST API but not all

I currently trying to get the issues from JIRA via REST API via this:
curl -D- -u USERNAME -X GET -H "Content-Type: application/json" \
https://issues.apache.org/jira/rest/api/2/search? jql=project%20%3D%20MNG%20AND%20fixVersion%20%3D%203.4.0 \
-o release.json
But unfortunately i don't get all issues. Only 50 instead of 59. I already checked if all the issues have the correct fixVersion set to 3.4.0.
But via browser:
https://issues.apache.org/jira/issues/?jql=project%20%3D%20MNG%20AND%20fixVersion%20%3D%203.4.0
I got all the issues.
Do i oversight something ? Some idea hint ?
50 is a default value for "maxResults" parameter. Here's API documentation https://docs.atlassian.com/jira/REST/latest/#api/2/search-search

Spring Boot and XMLHttpRequest

I am having a hard time understanding how Spring Boot (v1.3.3) handles the X-Requested-With: XMLHttpRequest header. My understanding is that this header tells Spring Boot to return, for requests without an authenticated session, a 401-Unauthorized error rather than a 302-Found with a location to the login page.
I have set up my AngularJS client to send this header for any routing, and then configured an $http interceptor to act on the 401 error by displaying a dialog. Doesn't work for me, with a Spring Boot server with no additional security configuration.
With some investigation with CURL:
It seems that the -H "Accept: application/json" header also needs to be provided.
curl -v -H "X-Requested-With: XMLHttpRequest" localhost:9080/ returns a 302, while curl -v -H "X-Requested-With: XMLHttpRequest" -H "Accept: application/json" localhost:9080/ returns a 401.
Questions: Why is the application/json header required as well? Can I configure it differently (i.e. not require application/json header)? Should I configure it this way, or take another approach? The reason I don't want to require the application/json header is because I am not allowing public access to some resources, such as HTML templates and JS code, and want a 401 returned for these resources as well.
It seems that the JSESSIONID cookie may be affecting the response.
curl -v -H "X-Requested-With: XMLHttpRequest" -H "Accept: application/json" localhost:9080/ returns a 401, while curl -v -H "X-Requested-With: XMLHttpRequest" -H "Accept: application/json" -H "Cookie: JSESSIONID=63EA6E09F64B98938E4495DF9898323A" localhost:9080/' returns a 302.
Questions: Why does the presence of the (valid) JSESSIONID cookie make any difference?
I have looked at the source code for Spring Security and Spring Boot and I just cannot put together the pieces. Any help is much appreciated.

API documentation RAILS

For my first API documentation (very simple API, only one method) I have more or less this structure:
API documentation
1.Disclaimer
2. Using the API
2.1 Input data -> Here I explain how should be the input data, JSON
2.2 Output data > Here I explain which data should be obtained and in JSON
2.3 Example -> I am giving an example of my input and output
In 2.3 I explain that the output (real example in my documentation, I post here only a structure of how it looks) should look like this:
{"message":"Succesful ","data":{"batt1":{"value1":977.48279000017,"value2":977.4208279000022,"value3":1034.9372639500002,"value4":2534.854048049996,"value5":2465.145176450681,"value6":2465.1451764508347},"batt2":{}...}
But its missing me how to put the request in this example.
Until now I have been using/ testing my API with this command: curl -i -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '#alldata.json' http://localhost:3000/api/v1/namecontroller
Should I put in my documentaion in 2.3 something like this:
In this example I used the cURL command in the following form: curl -i -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '#alldata.json' http://localhost:3000/api/v1/namecontroller
Sorry I am very new to all this, RoR,API etc...
Do you have any idea?
I think you can show it in below format so that will be easy to understand
url: http://localhost:3000/api/v1/namecontroller
method: POST
Body : #alldata.json

curl - request with json object and file to Rails API

I need post file and JSON object to API (Ruby On Rails) by curl in one request.
My request looks like this:
curl --data #file.pdf -H "Accept: application/json" -H "Content-Type: multipart/form-data" -X POST -d '{"document":{"name":"file name"}}' http://localhost:3000/api/documents
But Rails parse it bad. Params on the server:
Parameters: {"{\"document\":{\"name\":\"file name\"}}"=>nil}
Where is problem?
You should pass multipart/form-data (as you specify), not a JSON string. Try this:
-d 'document[name]=file name'
Result on my machine:
Parameters: {"document"=>{"name"=>"file name"}}

Resources