Constructor
new OAuth2Driver()
Example
const OAuth2Driver = require('homey-wifidriver').OAuth2Driver;
const ExampleAPI = require('example-api');
const oauth2ClientConfig = {
url: `https://api.example.com/authorize?response_type=code&client_id=${Homey.env.API_CLIENT_ID}&redirect_uri=https://callback.athom.com/oauth2/callback/`,
tokenEndpoint: 'https://api.example.com/token',
key: Homey.env.API_CLIENT_ID,
secret: Homey.env.API_CLIENT_SECRET,
allowMultipleAccounts: false,
};
class myDriver extends OAuth2Driver { // Which extends WebAPIDriver
onInit(){
// This will override onPair() to handle OAuth2 pairing
super.onInit({oauth2ClientConfig});
}
// This method will be called if a oauth2ClientConfig is provided onInit. The data object contains
// an authenticated OAuth2Account instance which will be destroyed automatically after pairing
// has ended.
onPairOAuth2ListDevices() {
// API calls will be injected with 'Authorization: Bearer <access_token>' from OAuth2Account instance
this.apiGetCall({uri: 'http://example.api.com/list/devices'})
.then(devices => {
this.log(devices);
return devices;
});
}