sbanik
sbanik

Reputation: 33

Google cloud scheduler http post error 415 FAILED_PRECONDITION

I have created an ASP.NET Core Web API. The method in the API controller is decorated like this:

[HttpPost]
public async Task Post([FromBody] string value)

Then I scheduled a job from google cloud scheduler to call this job with OIDC token for auth. Problem is, it's returning 415 FAILED_PRECONDITION error every time.

I tried invoking the published job (in the server) with fake auth header from postman and it's throwing error as expected that the token is not formatted correctly. However, google scheduler is not even hitting the endpoint because I have step by step logging inside the task.

I was verifying the token like below

string token = Request.Headers["Authorization"].ToString().Remove(0, 7); //remove Bearer 
var payload = await VerifyGoogleTokenId(token);

private async Task<GoogleJsonWebSignature.Payload> VerifyGoogleTokenId(string token){
GoogleJsonWebSignature.Payload payload = await GoogleJsonWebSignature.ValidateAsync(token);
}

Interestingly, when I removed the token checking, i.e. commented below line and used a random string in the value field of the request body - google is reaching the endpoint and invoking the job.

string token = Request.Headers["Authorization"].ToString().Remove(0, 7)

Note that above line is inside try catch block so any error will be logged, just in case.

So my questions are:

  1. Can I see the raw log of the http request google is sending?
  2. What am I missing so that google is not even reaching the endpoint?

Upvotes: 0

Views: 147

Answers (0)

Related Questions