Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Unable to call the Authenticated Cloudfunctions (.NET) on Cloud Run .NET Application

I want to run the authenticated .net cloudfunction on .net aplication . I have applied  all possible solution , That is I have access the bearer token using service account key .json and passed to HTTPclient header . I can access the token ,But still getting 401.  Error: Response status code does not indicate success: 401 (Unauthorized) .   I have given required  permissions for the task  . Also When I run same cloudfunction url and access token on postman , getting same 401 error 

0 2 260
2 REPLIES 2

Hi @Jiji_Biju ,

Welcome to Google Cloud Community!

There are several reasons behind the 401 Unauthorized error; it may probably be because there is a discrepancy between the token or permissions and what the Cloud Function requires.

Here are some things you may check:

  • Verify that the audience specified in the token (aud claim) aligns with the URL of the Cloud Function.
  • Check if the token has the correct scope, such as https://www.googleapis.com/auth/cloud-platform, in order to call Cloud Functions.
  • Identify the right permissions for IAM: Make sure the service account is assigned the Cloud Functions Invoker role for the Cloud Function.
  • Verify token expiration before making the request.
  • Troubleshoot the Token: You may use a decrypting tool, e.g., jwt.io (Use it at your own risk) to verify the fields such aud, exp, and iat if accurate.

This may assist you in identifying the source of the 401 error.
I hope the above information is helpful.

Thank you for your response . I have checked your points and seems , my token in invalid structure in which generated via Outh2.0 . Why this happening ??