Logging firebase warnings - node.js

I am getting the following warning on the console of my nodejs app:
FIREBASE WARNING: Provided authentication credentials for the app
named "[DEFAULT]" are invalid. This usually indicates your app was not
initialized correctly. Make sure the "credential" property provided to
initializeApp() is authorized to access the specified "databaseURL"
and is from the correct project.
Is there a way to send this kind of warnings to a logger?
I don't find nothing of the kind for nodeJs Admin SDK
Just to make absolutely clear, i am not concert with the error itself, only how to log all relevant problems, occurred on my code or on the library code, into one single file that i can look at.
Also, the warning is not possible to log by the api caller because it is not send it back to the caller.

Specify a custom log function via admin.database().enableLogging(). See the examples in the reference docs.

Related

How do i use the Kenitco API from a Console App

I'm using Kentico V10 and I can run the website locally. However, when i try to use the API from a console app, i'm getting the following error.
{"Object type 'cms.class' not found."}
The stackTrace has a call to check license. I'm following this page, and it says you have to add a license for your domain, but what domain is used when you are running from a console app?
https://docs.kentico.com/k10/integrating-3rd-party-systems/using-the-kentico-api-externally
I'm using this code from taken from this page.
https://docs.kentico.com/k10/managing-users/user-registration-and-authentication/configuring-single-sign-on
CMS.DataEngine.CMSApplication.Init();
string userName = "myuser";
// Gets the user with the specified user name
UserInfo userInfo = UserInfoProvider.GetUserInfo(userName);
// Gets the authentication URL for a specified user and target URL
string url = AuthenticationHelper.GetUserAuthenticationUrl(userInfo, "SecuredSurvey");
If that was available via the REST API, i'd be happy to get the URL that way, but from what i can see, it's not available.
-Randy
Kentico has some good documentation on how to use the API in an external application, specifically a console library here.
Very notable steps are:
Connecting to the database; make sure you use the same connection string as in your web.config
Install the Kentico.Libraries NuGet package
Initialize Kentico in your application in the Global.asax file.
Write custom code all day long.

getting error : Your client does not have permission to get URL in firebase functions

i am new in firebase, i have deploy one function, and it is using get method,
https://us-central******.cloudfunctions.net/addMessage
when i try to run this api, i am getting below error
Error: Forbidden
Your client does not have permission to get URL /addMessage from this server.
Can anyone please help me to resolve this issue ?
exports.addMessage = functions.https.onRequest(async (req, res) => {
// Grab the text parameter.
const original = req.query.text;
// Push the new message into the Realtime Database using the Firebase Admin SDK.
const snapshot = await admin.database().ref('/messages').push({ original: original });
// Redirect with 303 SEE OTHER to the URL of the pushed object in the Firebase console.
res.redirect(303, snapshot.ref.toString());
});
From the doc, argument --allow-unauthenticated:
Specifies that the function does not require authentication to invoke. By default HTTP functions require authentication. If you do not include this flag the first time you deploy an HTTP function, you are prompted to allow unauthenticated invocations. You are not prompted on subsequent invocations.
So, you need to deploy the cloud functions with this argument if you don't need authentication. E.g.
A simple cloud function, index.js:
exports.helloHttp = (req, res) => {
res.send(`Hello ${req.body.name || 'World'}!`);
};
Deploy without --allow-unauthenticated:
gcloud beta functions deploy helloHttp --trigger-http --runtime nodejs10
When you access the endpoint of this cloud function: https://us-central1-xxxx-218801.cloudfunctions.net/helloHttp. You will get this 403 Forbidden error:
Error: Forbidden
Your client does not have permission to get URL /helloHttp from this server.
Deploy with --allow-unauthenticated:
gcloud beta functions deploy helloHttp --trigger-http --runtime nodejs10 --allow-unauthenticated
You will get access the endpoint without authentication.
Hello World!
I ran into this (or a very similar problem) today. When I invoked one of my functions from Postman, I got:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>401 Unauthorized</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Unauthorized</h1>
<h2>Your client does not have permission to the requested URL
<code>/myApi/somePath?</code>.</h2>
<h2></h2>
</body>
</html>
I try redeploying the functions but that didn't work.
Solution: Delete your functions and deploy them again.
What I did was:
Exported a single dummy function from functions/index.ts and removed my original functions.
Deployed. That deleted my original functions.
Verified that the dummy function worked well.
Restored my original functions and deployed again.
Verified that my original functions worked.
Background and possible cause
I had a new Firebase project and I tried to deploy my functions many times but got some errors related to permissions. I guess that left the functions in a weird state...
I managed to deploy the functions successfully later, but they were not in a good state and I got that error response from Postman when I called one of them.
The errors I got were the following:
Error 1:
Error: Missing permissions required for functions deploy. You must have permission iam.serviceAccounts.ActAs on service account some-sa#appspot.gserviceaccount.com.
Error 2:
Error: Missing permissions required for functions deploy. You must have permission iam.serviceAccounts.ActAs on service account some-sa#appspot.gserviceaccount.com.
Error 3:
Unable to set the invoker for the IAM policy on the following functions:
someFunction1(us-central1)
someFunction2(us-central1)
Some common causes of this:
- You may not have the roles/functions.admin IAM role. Note that roles/functions.developer does not allow you to change IAM policies.
After trying to delete individualy functions and uploading them again ultimately i had to delete all of the previously deployed functions and deploy them all.
Once i'd done that a couple of times, the functions deployed.
There are two possible causes i can think of that was causing this, both very ambiguous.
I found that there was one offending file, and the only thing that fixed the deploy was to change the length of the file name. Yes, the length of the filename. One character too long and the deployment failed. If this was a windows 95 machine i'd have said the inheritance chain path was too long for the compiler. However, compiliation and running on the emulator worked fine. So who knows.
I had tried to set up cloud build, and left that part half finished. I had updated the .firebaserc as a part of that. Perhaps, just perhaps, the deployment didn't like the fact the default projects list had changed, and didn't match the existing functions.
I'm totally guessing as to the cause, but because the error is so ambiguous, with no apparent cause, figued this might help people find the cause.
It can also happen, if you use the wrong subpath. For me the url was somehow wrong, instead of resendConfirmEmail it tried to call resendConfirmEmail%20. That function didn't exist and google responded with 403:
https://europe-west1-my-project.cloudfunctions.net/resendConfirmEmail%20?userId=imFeBoV...&email=gr...%40...com
when it should have been:
https://europe-west1-my-project.cloudfunctions.net/resendConfirmEmail?userId=imFeBoV...&email=gr...%40...com

Is it possible to use dialogflow-nodejs-client-v2 in front-end (Angular)?

I built an app a long time ago using Firebase and dialogflow-javascript-client.
Now, dialogflow-javascript-client is deprecated. Since dialogflow-nodejs-client-v2 is a node.js client, it is not supposed to run on Angular. Did they drop the javascript support? I can't get any answer from the devs, they just seem to avoid it.
If it is not possible, my only solution is to drop support of Dialogflow in my app.
There is absolutely not documentation or info for users migrating from Javascript, here is the only thing they give you:
Off course I tried to run it anyway, thinking it was also built to run on javascript...
But here is what I get:
WARNING in
./node_modules/google-gax/node_modules/grpc/node_modules/node-pre-gyp/lib/util/versioning.js
17:20-67 Critical dependency: the request of a dependency is an
expression
WARNING in
./node_modules/google-gax/node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js
20:22-48 Critical dependency: the request of a dependency is an
expression
WARNING in
./node_modules/google-gax/node_modules/grpc/src/grpc_extension.js
32:12-33 Critical dependency: the request of a dependency is an
expression
WARNING in
./node_modules/google-gax/node_modules/grpc/node_modules/minimatch/minimatch.js
Module not found: Error: Can't resolve 'path' in
'D:\ng\ww-app\node_modules\google-gax\node_modules\grpc\node_modules\minimatch'
WARNING in ./node_modules/minimatch/minimatch.js Module not found:
Error: Can't resolve 'path' in 'D:\ng\ww-app\node_modules\minimatch'
ERROR in ./node_modules/dialogflow/src/v2/agents_client.js Module not
found: Error: Can't resolve './agents_client_config' in
'D:\ng\ww-app\node_modules\dialogflow\src\v2'
.... (many more following)
The dialogflow-nodejs-client-v2 only supports a node.js environment. To update your agent to V2, you should create a Cloud Function for Firebase that sends requests to dialogflow-nodejs-client-v2, then call that Cloud Function from your Angular code rather than calling the API directly.
There is a major benefit of this approach: you will no longer have your API credentials exposed on the client side, which is a security risk.
I read a tutorial once with Node.js, maybe you can migrate your data from angular to Node.js like in this question anwered before.
I found another solution:
I've created a javascript client... and I get token from nodejs api getToken endpoint when it expires (that is every hour)... I have restricted the getToken endpoint to the same domain.

Precompiled Azure Function and SOAP endpoints

I'm writing a precompiled Azure function that will perform a SOAP call to ServiceNow. The code works as a standalone exe but I can't seem to get it converted to a precompiled function. In know it's because my DLL can't find the app.config file but what's the best way to get around it. Error message below. ServiceNow requires I set certain bindings and endpoint configuration. The other contractors for their ServiceNowSoapClient class allow me to specify a url directly but don't seem to allow me to get to the binding settings.
Exception while executing function: Functions.TimerTriggerCSharp.
System.ServiceModel: Could not find endpoint element with name
'ServiceNowSoapDev' and contract 'ServiceNowReference.ServiceNowSoap'
in the ServiceModel client configuration section. This might be
because no configuration file was found for your application, or
because no endpoint element matching this name could be found in the
client element.
In WCF you can define your client binding and endpoint programmatically instead of using app.config. Use the constructor of the generated client with two parameters:
new ServiceNowSoapClient(binding, remoteAddress);
See more code here.

How to debug a '4005 Path Not Found' error?

I am trying to integrate Pusher with my web application that uses backbone.js. I'm following the Pusher with Backbone guide in the Pusher docs.
So I'm seeing this error pop up in the web console on application start up
Pusher : Error : {"type":"PusherError","data":{"code":4005,"message":"Path not found"}}
What is this 'path' that cannot be found? I found nothing in the Pusher docs.
A 4005 error generally means that the WebSocket URL you are using doesn't identify an application to connect to.
In terms of usage of the Pusher JavaScript library this means you've likely supplied an empty string as the app_key to the Pusher constructor.
var pusher = new Pusher('');
You can see this in action here:
http://jsbin.com/evulaj/1/edit
Open the JavaScript console to see the error. You can also check the app_key value set by checking pusher.key.
Note: I appreciate this error is a bit cryptic. I'll see if we can remedy this
in my case, wsHost: process.env.MIX_PUSHER_WS_HOST was giving an empty value, and fixed it by changing .env file.
PUSHER_WS_HOST=my.host.com
MIX_PUSHER_WS_HOST="${PUSHER_WS_HOST}"
or you can do:
wsHost: window.location.hostname

Resources