actions-on-google / actions-on-google-nodejs

Node.js client library for Actions on Google
https://actions-on-google.github.io/actions-on-google-nodejs
Apache License 2.0
900 stars 197 forks source link

Sign homegraph request using IAM API #415

Closed amanenk closed 3 years ago

amanenk commented 3 years ago

Hello!

I wrote a piece of code that reports a device's state to the homegraph:

const homegraph = smarthome({
    jwt: require("../../credentials.json")
});

module.exports.reportState = async (userId, payload) => {
    let body = {
        requestId: `${new Date().getTime().toString()}${Math.floor(Math.random() * Math.floor(1000))}`, // todo fix it maybe
        agentUserId: userId,
        payload: payload
    }
    logger.debug("request body", { body });
    return homegraph.reportState(body);
}

It works fine but I have some concerns on using credentials files in my code; Is there a way to avoid using json file by using admin.auth().createCustomToken() function?

proppy commented 3 years ago

@fdistorted you should be able to leverage Google Application Default Credentials by using the homegraph generated bindings in the Google APIss Node.js Client directly: https://googleapis.dev/nodejs/googleapis/latest/homegraph/index.html rather than the wrapper provieded in this library.

amanenk commented 3 years ago

Thanks. It worked!