#Unauthorized API query request 401 unauthorized
1 messages · Page 1 of 1 (latest)
Hello! I'm SmithBot, your Appsmith support bot. Let's work through the issue with your Firestore API queries together.
When facing unauthorized errors with Firestore API queries, here's a checklist to help troubleshoot the issue:
- Ensure that the Firebase rules are indeed set to allow public access. Although you mentioned they're public, double-checking the rules directly in the Firebase console might help identify any discrepancies.
- Confirm that the
idTokenyou are using is correct. Even though you stated it's a fresh token, there might be issues with how it's generated or being passed. - Make sure the
idTokenis included in the API request headers correctly. The header name and format should match what Firestore expects. - Review the network requests from the browser's developer tools to confirm that the
idTokenis being sent with the request and that no other errors are occurring.
Please verify these points, and if you continue to have issues or have checked all of the above, I can help further diagnose the problem. You can also share your API query configuration in Appsmith, ensuring you remove any sensitive information before sharing.
If you don't find my response helpful, you can request to speak to a human agent
This is copied from the error log in Appsmith:
- 23:09:53 v Execution failed with status 401 UNAUTHORIZED ® Арі3
{"error":{"code":401,"message": "Request had invalid authentication credentials. Expected Auth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/
devconsole-project.", "status":"UNAUTHENTICATED"}}
"actionld" : "6630e14bd4c17c152778bb44"
"requestedAt" : 1714770592968
"body" : "'
• "headers" : [
• 0 : {
"Authorization": "****"
• 1 : 4.
"content-type" : "application/json"
]
"httpMethod" : "GET"
"url" : "https://firestore.googleapis.com/v1beta1/projects/lazic-dental-Oesket/databases/(default)/documents/dentists/"
Based on the error message, it appears that the API request to Firestore is not being authenticated correctly. Although you are supplying an idToken, Firestore is expecting an OAuth 2.0 access token, which is different.
To resolve this issue:
-
Make sure that you are using the correct type of token. Firestore typically expects an OAuth 2.0 token for authenticating API requests, not just an ID token.
-
If you are using a service account to interact with Firestore, ensure that you have generated an access token from the service account's credentials and that you are including this token in your API request headers.
-
If you are authenticating user requests, ensure that you are obtaining the OAuth 2.0 access token as part of the user's authentication flow and that the token is still valid when making the request.
-
Review the OAuth 2.0 setup in your Google Cloud project to ensure that it aligns with Firestore's requirements for API authentication.
If you have already verified these points and are still facing issues, please provide more details about how you are acquiring the idToken and where it is being used in your API request. Remember to redact any sensitive information before sharing your API configuration details.
If you don't find my response helpful, you can request to speak to a human agent
How do I set up OAuth 2.0 between Google and Appsmith
How do I perform OAuth in Appsmith for Google Cloud Platform?