cannot read property 'client_secret' of undefined - node.js

I have tried to create a sample program using Node.js, following instructions from https://developers.google.com/google-apps/activity/v1/quickstart/nodejs
I throws an error saying cannot read property 'client_secret' of undefined when trying to run it.
Looking for your valuable suggestions.
Thanks in advance.

var clientSecret = credentials.installed.client_secret;
In this line credentials is pointing to client_secret.json so the first key has to be "installed". In my case the key was "web" and that was causing the error. I just renamed the key "web" to "installed".

Since there is no key named "installed", it's parsing it to be undefined.
In credentials.json change the key "web" to "installed". Probably the docs need to change from Google's side.
Before
After

It seems you have missed Step 1: Turn on the Google Apps Activity API.
After creating the Credentials:
f. Click the file_download (Download JSON) button to the right of the
client ID.
g. Move this file to your working directory and rename it
client_secret.json. Put it in your project folder.

Your client_secret.json file needs to have the line below:
"redirect_uris": ["urn:ietf:wg:oauth:2.0:oob", "http://localhost"]
instead of the lines like below:
"javascript_origins":
[
"http://localhost:8080",
"http://localhost:1453",
"http://127.0.0.1:1453",
"http://localhost"
]
Also you may want to change chain head in client_secret.json from web to installed, or vise versa.

I had this problem, but I had the wrong type of credentials file. I initially used "Web Server (Nodejs)...", and it had the "web" heading instead of the "installed", but when I did it again, and selected "Windows UI (cmd line)", I got the file with the correct format.

Try selecting the application type "Other".
Select the "Help me choose" option and there you can chose other application type.
That way your client_secret.json will have the variable named "installed".

The recent version of Google Drive API will have a Desktop client option while creating OAuth API Key. Do select that, it will have all required information to access Google drive from Script.

Related

Error running Vorto Dashboard for Bosch iot suite

I am trying to run Vorto dashboard on Raspberry Pi to visualize my Bosch IoT "things" data.
In order to run the Vorto Dashboard, I installed npm and nodejs and created the config.json file.
I am getting the below error whenever I try to run the dashboard using the command: sudo vorto-dashboard config.json, knowing that I already added the OAuth2 Client credentials.
No credentials given, can not get things
Could not get the token with given credentials. - StatusCodeError: 400 -
{"error":"unauthorized_client","error_description":"INVALID_CREDENTIALS:
Invalid client credentials"}
I am currently contributing the Vorto Project as an Intern at Bosch. Due to changes in the Vorto-Dashboard we combined and merged the functionality of a previous dashboard with another coexisting updated UI, providing advanced ways to visualize the existing devices.
As the uploaded state was work in progress, we temporarily disabled the config.json methodology and removed existing references from the documentation. Apparently, the reference in the tutorial you found was omitted, sorry for that!
Today, I deployed a new version 0.5.0 of the vorto-dashboard which should work as usual. You are now able to work with either process.env.[...] varibales or a config.json file. Thank you Mena for the quick response!
Feel free to let me know if you need any further help or have additional feedback.
TL;DR
To resolve your issue, store your OAUth credentials as environmental variables.
E.g. in debian et al., export BOSCH_CLIENT_ID=... etc., then start the dashboard in the same terminal.
Context
I was about to ask the same question, as I got the same error message no matter how I referenced the config.json file (relative path, absolute path, no reference, etc.).
For clarification, the tutorial pointing to a config.json resource for storing OAuth credentials is here.
Quoting:
While the dependencies are being installed, create the config.json file and insert client_id, secret and scope from your Already created
OAuth2 Client. The content of the file has to look like this:
{
"client_id": "<YOUR_CLIENT_ID>",
"client_secret": "<YOUR_CLIENT_SECRET",
"scope": "<YOUR_SCOPE>",
"intervalMS": 10000
}
The reference to the config.json file has been removed from the README.md resource in the vorto-dashboard module of vorto-examples.
The latest README.md suggests providing the OAuth credentials through environmental variables:
You can provide your OAuth2 credentials through environment variables.
The three environment variables you have to provide are:
BOSCH_CLIENT_ID
BOSCH_CLIENT_SECRET
BOSCH_SCOPE
[...]
Looking at the source, I can only find an explicit reference to a config.json in the start script entry for package_for_deployment.json (nor anything around the source seems to be consuming, say, argv[2] for that matter).
The AuthToken.js resource in charge of handling OAuth credentials only seems to reference environmental variables through the process.env.[...] references.
Elaboration
This is only speculation at the time of writing, but I suspect the reason why the config.json methodology has been abandoned might have something to do with strengthening security, i.e. not storing OAuth credentials permanently in a file.
If that much is true, then the tutorial page should probably be amended with the latest instructions from the README.md.

NSBluetoothPeripheralUsageDescription missing, but present

After successful upload I get:
This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSBluetoothPeripheralUsageDescription key with a string value explaining to the user how the app uses this data.
This is in the .plist:
NSBluetoothPeripheralUsageDescription 'MyApp' would
like to use Bluetooth
What is here wrong? In other App's it was working.
The problem was, that there were two .plist files in the project directory.
The used .plist file is defined here: "TARGETS", "Build settings", "Packaging", "INFOPLIST_FILE".
find the info.plist file of your project and add the NSBluetoothPeripheralUsageDescription key the value it is string whatever you like. this feature is request on iOS 10.enter image description here

Why do I get "Invalid token" unless I invert projectId and clientId?

In order to setup Google Identity Toolkit for my Website I started with the Quick-start App for Node.js.
It worked fine on localhost.
But when I moved it to an actual app-engine instance it did not work anymore.
I got this error returned by gitkitClient.verifyGitkitToken():
Invalid token: Unable to verify the ID Token: Wrong recipient, payload
audience != requiredAudience
I found a very helpful post on stackoverflow about more or less the same issue, for Java instead of node.js: It looks like there is a mismatch between projectId and clientId.
I changed my gitkit-server-config.json file to swap the projectId and clientId values and it worked!
This sound very much like a major bug on google side, doesn't it?
Why does it work on localhost?
Will this be changed/fixed in the future?
Maybe the problem is in the tutorial?
I have a working solution for now, but I do not feel safe to keep it like that...
I hope a googler will read this!
[EDIT]
Following wyhao31's comment I had a closer look at the gitkitclient.js source code and both projectId and clientId are added to the same audiences array.
After more test I found out that you must only put the project ID ('my-project-name') in the gitkit-server-config.json file.
The nasty thing is that if you add it with a 'clientId' property name it is also working...
Based on your description, and if you read gitkit-server-config.json file like this
var gitkitClient = new GitkitClient(JSON.parse(fs.readFileSync('./gitkit-server-config.json')));
I think the problem might caused by using old nodejs client lib. Could you try to update your client lib to latest version(0.0.6)? Or you can use the code directly.

SendGrid API Key is not working. "The provided authorization grant is invalid, expired or revoked"

SendGrid seems to be preventing my node js server from sending emails.
I get this error message in the response on sending off an email:
The provided authorization grant is invalid, expired or revoked
I have an API key setup as well and have followed the documentation.
You need to use the API KEY GENERATED
DO NOT USE the API KEY ID
Sendgrid only displays the generated key once when you create it.
If you didn't record it somewhere when you created the key you'll need to create a new key and then you'll probably want to delete the old key since it would be useless if you don't know what it is.
FYI: The API key in the screenshot above is already deleted. I deleted it right away so please don't worry about me leaking that key.
This is a late answer and JAVA oriented.. But I simply copied the docs and didn't notice..
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
I just put my key in there and didn't see the getEnv. Silly of course.. but when trying to get things to work quickly...
For me I just had to generate a new API key. For some weird reason the former API key has become invalid, so I also added an alert for this case
In Sendgrid v3, I had the similar issue when using env variable in Node JS. If I use env variable, I get the above issue. But if I drop the string into the require process, it works.
Doesn't Work:
SENDGRID_API_KEY=SG.XXXXXXXXXXXXXXXXXXX
var sg = require('sendgrid')(process.env.SENDGRID_API_KEY);
Works
var sg = require('sendgrid')('SG.XXXXXXXXXXXXXXXXXXX');
Replace SG.XXXXXXXXXXXXXXXXXXX with API Key Generated (which you can only see once during key generation).
EDIT
Note : Make sure you don't save this to public repository. If you do anyone can use your API Key and also your account will be suspended by Sendgrid team temporarily until you remove it from repository.
In my case I was trying to debug the connection by using telnet and kept getting rejected.
Turns out that these two are not equivalent, echo will include \n in the encoded string.
echo 'apikey' | base64
printf 'apikey' | base64
So yeah, make sure you don't include the newline in the API key.
If you are using node js,
make sure you have the require('dotenv').config()line inside the file that needs the sendgrid/nodemailer module.
Without it, the sendgrid transporter will have an undefined value instead of the api_key.
Here's my solution:
Install the dotenv package: npm i dotenv
Go to the earliest entry point of your application(i.e index.js) and put this at the top:
const dotenv = require('dotenv').config();
Create a .env file and add SENDGRID_API_KEY=<YOUR_API_KEY>. NO quotes '' or "".
In your file which you use sendgrid, add this to the top:
const sgMail = require('#sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
Done.
It might be late for an answer but for people who are getting the same problem in spring boot
it might be caused at initialization when you are using env or property value
i was initializing the variable in the constructor before the value was loaded by spring and it was giving the same output. so either initialize it in the method you are calling the SendGrid function or do it after values are loaded
Instead of using,
api_key: ${process.env.SENDGRIDAPIKEY}
try,
api_key: "" + ${process.env.SENDGRIDAPIKEY} + ""
worked for me,
For me; I've just created a new API key and then it works again.
I'm %100 sure it was working with no any code change.
Maybe it is an issue with SendGrid or some sort of security action from SendGrid.
I had the same issue, it disappeared after I verified my email address and enabled 2FA.

Spotify Folder in "My Documents"

I'm trying to make an app for Spotify, but I can't get the first step to work. I have made a folder named 'Spotify' in 'My Documents' (I use Windows 7 64 Bit), and made a folder inside it named 'test'. In 'test' I put a file 'index.html' to test if I can open it in Spotify, but I can't. I have a developer account, so that can't be a problem. When I type 'spotify:app:test' in the search bar, I get something like this:
(Note, in the screenshot it says spotify:app:tutorial, but I get the exact same result as displayed when I type spotify:app:test, saying failed to load application)
Also, I use Spotify version 0.8.7.111.gaf8d06ed-245
Spotify cannot load an application unless it has a valid manifest file. The manifest documentation can be found here.
Alternatively, see the Spotify Apps Tutorial app for a working example of a valid manifest. Note that you at least need an identifier, version and name for a manifest to be considered valid.

Resources