OAuth2 Login

"template": "login_oauth2"

This view can be used for devices that need OAuth2 authorization. When it's successful, it will automatically proceed to the next view.

Options

hint (i18n object)

When either hint or button are set to a value, a button will appear and wait for the user to click it before opening the popup.

Setting this option will overwrite the text of the hint (default: "").

button (i18n object)

When either hint or button are set to a value, a button will appear and wait for the user to click it before opening the popup.

Setting this option will overwrite the text on the button (default: Log-in).

Example

/app.json

{
    "id": "com.athom.testsuite",
    "drivers": [
        {
            "id": "my_driver",
            "pair": [
                {
                    "id": "login_oauth2",
                    "template": "login_oauth2"
                },
                {
                    "id": "list_devices",
                    "template": "list_devices_singular",
                    "navigation": {
                        "next": "add_devices"
                    }
                },
                {
                    "id": "add_devices",
                    "template": "add_devices"
                }
            ]
        },
        ...

/drivers/<driver_id>/driver.js

const Homey = require('homey');

class MyDriver extends Homey.Driver {

    onPair( socket ) {

        let apiUrl = 'https://api.myservice.com/oauth2/authorise?response_type=code&client_id=' + Homey.env.CLIENT_ID + '&redirect_uri=https://callback.athom.com/oauth2/callback/'

        let myOAuth2Callback = new Homey.CloudOAuth2Callback(apiUrl)
            myOAuth2Callback
                .on('url', url => {

                    // dend the URL to the front-end to open a popup
                    socket.emit('url', url);

                })
                .on('code', code => {

                    // ... swap your code here for an access token

                    // tell the front-end we're done                        
                    socket.emit('authorized');
                })
                .generate()
                .catch( err => {
                    socket.emit('error', err);
                })

    }

}