/drivers/<driver_id>/driver.compose.json
{
"name": { "en": "My Driver" },
"images": {
"small": "/drivers/my_driver/assets/images/small.png",
"large": "/drivers/my_driver/assets/images/large.png"
},
"pair": [
{
"id": "login_oauth2",
"template": "login_oauth2",
"options": {
"hint": "Login with your credentials",
"button": "Log-in"
}
},
{
"id": "list_devices",
"template": "list_devices",
"navigation": { "next": "add_devices" }
},
{
"id": "add_devices",
"template": "add_devices"
}
]
}
/drivers/<driver_id>/driver.js
const Homey = require("homey");
const API_URL = "https://api.myservice.com/oauth2/authorise?response_type=code";
const CALLBACK_URL = "https://callback.athom.com/oauth2/callback/";
const CLIENT_ID = Homey.env.CLIENT_ID;
const OAUTH_URL = `${API_URL}&client_id=${CLIENT_ID}&redirect_uri=${CALLBACK_URL}`;
class Driver extends Homey.Driver {
async onPair(session) {
const myOAuth2Callback = await this.homey.cloud.createOAuth2Callback(OAUTH_URL);
myOAuth2Callback
.on("url", (url) => {
// dend the URL to the front-end to open a popup
session.emit("url", url);
})
.on("code", (code) => {
// ... swap your code here for an access token
// tell the front-end we're done
session.emit("authorized");
});
}
}
module.exports = Driver;