"invalid_client" when exchanging for access token - spring

I've run the demo at https://github.com/lspil/youtubechannel/tree/master/ss_2022_c12_e1
of Laur Spilca.
curl --location --request POST 'http://localhost:8080/oauth2/token?client_id=client&redirect_uri=https://springone.io/authorized&grant_type=authorization_code&code=6HcAPusDMgl7x-qk1GqZ7S1c7m1iVbhBJtrUb1dvu8PlHK21EKkzUaVqZBOctiM85ZTNV4yH6Un1WuPmQiOj2DyTCEdobolknefO3l4WIFRZ3A7sznvHYpmoZnC2r34k&code_verifier=qPsH306-ZDDaOE8DFzVn05TkN3ZZoVmI_6x4LsVglQI'
Response
{
"error": "invalid_client"
}
Any idea how to fix this?

Related

How to add Supabase Order by in get request using Postman

I need to add order in supabase result while calling the supabase bash in postman.
I am doing same in flutter like below
Future getPropertiesFromBirmingham() async {
var response = await client
.from('properties')
.limit(10)
.order('created_at', ascending: false);
return response;
}
Need to use same in postman but not getting anything on this.
I didn't find much on this topic, Tried using order in params but it didn't work.
You can get examples of cURL requests directly in Supabase API docs.
You can also check for more documentation directly in the PostgREST website.
curl 'https://supabase_project_ref.supabase.co/rest/v1/properties?limit=10&order=created_at.desc' \
-H "apikey: SUPABASE_KEY" \
-H "Authorization: Bearer SUPABASE_KEY"
You can also control where the NULLs will be (if any) by adding either of the following:
nullslast
nullsfirst
curl 'https://supabase_project_ref.supabase.co/rest/v1/properties?order=created_at.desc.nullslast' \
-H "apikey: SUPABASE_KEY" \
-H "Authorization: Bearer SUPABASE_KEY"

Spring GraphQL returns 400(Bad Request) with curl for missing post request body

I wonder how 400 status code can be returned for POST requests with missing/empty body to GraphQL server?
I am using SpringBoot(v2.6.6) application with GraphQL starter(v1.0.0-M4).
Query definition for GraphQL is pretty simple:
type Query {
assetClasses(name: String!): [AssetClass]
}
type AssetClass {
name: String
}
Query mapper is
#Controller
#RequiredArgsConstructor
class AssetController {
private final AssetService assetService;
#QueryMapping
Flux<AssetClass> assetClasses(#Argument String name) {
return assetService.getAssets(name);
}
}
When executing query with an empty body from GraphiQL UI I see 400. Browser console reveals an empty query body in Graphiql is actually replaced with {"query": ""} that is sent to GrahQL server.
This is the curl analog of the GraphiQL request:
$ curl -X POST 'http://localhost:8088/graphql' -H "Content-Type: application/json" -d '{"query": ""}'
{"timestamp":"2022-09-05T14:42:33.060+00:00","path":"/graphql","status":400,"error":"Bad Request","requestId":"cf1b0107-4"}
However if the body is not initialized, the status code is 200:
$ curl -X POST 'http://localhost:8088/graphql' -H "Content-Type: application/json" -i
HTTP/1.1 200 OK
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
content-length: 0
I want to make the server consider requests with missing/empty boby as a bad request and return status code 400. What should be done for that?

Laravel API: validate doesn't access the PUT request data in my API

Context
I am implementing a user information update using a PUT request in Laravel 8. I use Postman to send the request and see the results.
Expected behavior
My PUT request reaches the controller's function that is censed to update the authenticated user. The latter is updated successfully. So the validate call is executed succesfully and finds the data in the request.
Actual behavior
My PUT request reaches the controller's function that is censed to update the authenticated user. The latter is not updated successfully. In fact, the validate call is executed succesfully but doesn't find the data in the request.
Instead, data validation says:
{
"message": "The given data was invalid.",
"errors": {
"email": [
"The email field is required."
],
"name": [
"The name field is required."
]
}
}
The route & The request
Postman request
curl --location --request PUT 'https://XYZ/api/set_user_data' \
--header 'X-Requested-With: XMLHttpRequest' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer 12|leRLA5yopCLIxe0oN9MMThctqD78iJDjZdZQkcgs' \
--data-urlencode 'email=XYZ#XYZ.FR' \
--data-urlencode 'name=test2'
It means in Postman terminology that no "Params" are sent, an Authorization Bearer token is sent, some Headers are sent and some Body's x-www-form-urlencoded data are sent.
API Route
In routes/api.php:
Route::put('/set_user_data', [UserController::class, 'setUserData'])->name('set_user_data');
UserController::setUserData:
public function setUserData(Request $request) {
if(!Auth::check()) {
return 'unauthenticated.';
}
$request->validate([
'email' => 'required|email',
'name' => 'required|string'
]);
// ... update user here but out of topic
}
What I tried to do... or to not do
Some Stackoverflow answers are: send a POST request and send in the body _method=PUT. I don't want to do this. I really prefer to send a PUT request. Because I am developing an API. It totally justifies the fact that I must use a PUT request and not a PUT one.
Some Stackoverflow answers are: use x-www-form-urlencoded not a simple form. It doesn't fix the problem; moreover it's already the case. Maybe it could help with images sending. (notice I don't want to send any image here).
Question
Why Laravel's validate don't find the data of my request and how to fix it?
You are sending the request as "Content-type: application/json", but you are not sending the body as valid JSON.
You are sending this:email=XYZ#XYZ.FR&name=test2
You should send this:
{"email":"XYZ#XYZ.FR", "name": "test2"}
a valid JSON object

Sending a POST request with RestClient and Authentication headers

I have the following curl request that I would like to translate into a RestClient API request.
curl -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Token user_token="tokenhere", email="email#myemail.com"' -X POST "https://api.myapi.io/reports?start_date=2016-05-10&end_date=2016-05-12" -v
I tried the following as a RestClient POST but I keep getting a 401. When I do the curl request I get a response.
url = "https://api.myapi.io/reports?start_date=2016-05-10&end_date=2016-05-12"
RestClient.post(url, :authorization => 'Token email="email#myemail.com" user_token="tokenhere"', :content_type => 'application/json', :accept => 'application/json')
Any ideas?
The string you're expecting is:
'Token user_token="tokenhere", email="email#myemail.com"'
The line you're sending is:
'Token email="email#myemail.com" user_token="tokenhere"'
The parameters are flipped around. :) If that doesn't work, I'd check and make sure that the curl request is expecting escaped characters. You could be effectively sending this:
"Token email=\"email#myemail.com\" user_token=\"tokenhere\""

Parse Cloud - make a GET endpoint

I have made simple cloud function:
Parse.Cloud.define("clientsnames", function(request, response) {
var query = new Parse.Query("Clients");
query.select('name')
query.find({
success: function(results) {
response.success(results)
},
error: function() {
response.error("Failed");
}
})
});
But to call it I always must use POST
curl -s -X POST \
-H "X-Parse-Application-Id: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "X-Parse-REST-API-Key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "Content-Type: application/json" \
-d "{}" \
https://api.parse.com/1/functions/clients
Which is, of course, a bad idea, and the request itself is obviously should be GET. But when I use GET with this request, I just get 404 (Document not found).
Is it possible to define a GET endpoint using Parse Cloud?
You can use Express js hosted on Parse CloudCode to setup custom endpoints
That way you can configure GET, POST without even using the Parse keys in the headers.
Head over to
https://www.parse.com/docs/cloud_code_guide#webhooks for detailed example

Resources