Reputation: 33
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:
Upvotes: 0
Views: 147