"error": "invalid_client" while using Django OAuth toolkit - django

I was following the steps mentioned in the documentation for django rest framework.
I'm not able to proceed from step 4.
As mentioned in the documentation,
curl -X POST -d "grant_type=password&username=<user_name>&password=<password>" -u"<client_id>:<client_secret>" http://localhost:8000/o/token/
I have changed the above variables with my values.
curl -X POST -d "grant_type=password&username=admin&password=admin123" -u "5hKeHNtF3EKy3uCpJqaAe3mU2bGZTgJhsKKxIuAQ:pbkdf2_sha256$390000$VFcCOjIZkBFObellddDgKA$DXovC1UiuxRQ0KN/lARIdQmXcj8dnoJofkznmkkqsZY=" http://localhost:8000/o/token/
I tried to import the curl on postman and Im getting this error
Then I tried running the curl on Insomnia testing tool, and I got the request configured as in the screenshot.
Then I click send and I got an error
SO i changed 'Content-Type' to 'Form URL Encoded'
Now I'm geting an error
{
"error": "invalid_client"
}
I tried running the curl in shell also, and I'm getting an invalid syntax error
I'm stuck with this and don't know how to proceed with this. Please lend me a hand.
Thanks in advance...

I was using the hashed value for client_secret instead of the actual value.
How to get actual client_secret actual value?
Answer:
While creating new application, copy the Client secret before saving
the values
https://github.com/jazzband/django-oauth-toolkit/issues/1193

Related

CSRF Token error when attempting to post from CURL to an API endpoint I control. How do I write the request?

I have not utilized this part of Django before, but I have an endpoint which is giving me a 403 error and is telling me that my request needs a csrf token. I was trying to figure out how best to get this since I was attempting to set up a bunch of curl requests to handle some simple queries to the endpoint. Likewise, I was thinking to also use POSTman, but I was not sure where documentation is to handle these request.
I have seen the cookie csrftoken, but when I was attempting to curl with it, it was still giving me a 403. thought it would looking something like this:
curl -d #profilepicturev2.png -b "csrftoken=Ebfn2OlfhSwFjAEQdoQon7wUjbynFoJqrtHMNPla3cy7ZfCMT9cxZ3OQHsbaedam" http://127.0.0.1:8000/api/files/uploader
Maybe I am mistaken? I am trying to send a photo to the server, so i was thinking that this would be correct and wasnt sure if i needed to add additional params in order to append additional data information.
i need to see your code, but i think you need to install "pillow" to send pictures in django !

Error code 500 while uploading the file on Box Drive

I'm trying to upload file on Box using rest API and getting 500 Internal Server Error.
URL: https://upload.box.com/api/2.0/files/content
Header :- "Authorization: Bearer XYZ"
Body(form-data) : attributes='{"name":"test.png", "parent":{"id":""498765432099}}'
file=file will be here
Postman screenshot are following:-
Thank you guys problem is resolved,
I was using the postman from google chrome extension to check the API
and getting 500 in response.
But now I had tested it on postman official application (https://www.getpostman.com/apps) Now it's working fine.
As postman extension is deprecated it still gives me error but on official application its working fine.

How to test OpenIm (ForgeRock) Request on Postman?

I have openIdm ForgeRock installed locally and I'am trying to go through the API Explorer etc. in order to see how to use the endpoints and the available endpoints.
From localhost:8080 where ForgeRock is running I can run/try a request. It works fine and I see the Response with Status 200 and its details.
When I try same Request URL on Postman, I get:
{
"code": 401,
"reason": "Unauthorized",
"message": "Access Denied"
}
In a way this makes sense for me as I'am not logged in in this case as directly via ForgeRock Server on localhost:8080. So how can I work around this to be able to run my tests also on Postman.
I tried the parameters username=xxx and password=xxx to the Request on Postman, but it keeps throwing the same error.
I also tried it on Postman as CURL request exactly how ForgeRock is using it, but it seems to have an issue with Authorization.
curl -X GET --header 'Accept: application/json' --header 'X-Requested-With: Swagger-UI' 'http://localhost:8080/openidm/managed/user?_queryId=query-all'
Any Idea please?
Fixed. Was actually simple... Had to add the following in the headers:
X-OpenIDM-Username
X-OpenIDM-Password
Value is by default: opendidm-admin for both.

REST API URL for VMC PUSH

This question is regarding REST API URL for use with curl equivalent to VMC push for a new application.
I have referred the api documentation of cloud foundry at http://apidocs.cloudfoundry.com/http-apps for various REST API URL mapping to vmc commands. However, I did not find a REST API URL for pushing a new application. I have tried deploying a new application with the POST html request but that returns a 504 BAD GATEWAY response. below is the curl command:
curl --request POST http://api.cloudfoundry.com/apps --data #data.json --header "Authorization: bearer token"
Content of data.json are as follows:
{"name": "mywebapp45", "staging": {"model": "spring","stack": "java"}, "uris": [ "mywebapp45.cloudfoundry.com"], "instances": 1, "resources": {"memory": 256},"state": "STARTED"}`
and the web app archive is in the same directory from where I execute the curl command.
Any insight on this is much appreciated. Thanks a lot for the help in advance
Based on the language, I'd like you to try the cfoundry ruby client: rubygems.org/gems/cfoundry, the java client: github.com/cloudfoundry/vcap-java-client, or the Node.js client which can also be found in github.

appending multiple querystring variables with curl

I keep getting a 401 response when I try to use authentication = ApiKeyAuthentication() in my ModelResource.
I looked at Django Tastypie: How to Authenticate with API Key and he uses the get parameters to solve his issue. If I try use get parameters it picks up username but not api_key!
This works in browser
http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50
Sending via curl in terminal doesn't pickup api_key parameter
curl --dump-header - http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50
Why when using curl and appending 2 querystring parameters like ?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50 does it only pickup the first one. Is this not the correct way?
Typing & in the command line means run the preceding command in the background (thanks #Maccesch), because of this anything after the & is being treated as a new command.
Try wrapping the url in quotes.
curl --dump-header - "http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50"