refreshToken() {
        let options = {
            method: "POST",
            headers: {
                "Content-Type": "application/x-www-form-urlencoded",
            },
            form: {
                grant_type: "refresh_token", refresh_token: this.token.refresh_token,
                client_secret: this.token.client_secret
            }
        };
        let self = this;
        request("https://api.home-connect.com/security/oauth/token", options, (err, res, body) => {
            if (err) {
                self.log("Could not refresh token..." + err);
            }
            this.log("Token refresh received code: " + res.statusCode + (res.statusCode >= 300 ? ". Returning." : "."));
            if (res.statusCode >= 300) return;
            let new_token = JSON.parse(body);
            this.token.access_token = new_token.access_token;
            this.token.refresh_token = new_token.refresh_token;
            this.token.timestamp = (new Date()).getTime() / 1000;
            this.token.expires_in = new_token.expires_in;
            fs.writeFile(self.config.tokenPath, JSON.stringify(this.token), 'utf8', (err) => {
                if (err) {
                    this.log("An error occured while writing JSON Object to File.");
                    return this.log(err);
                }
                this.log("Token has been refreshed.");
            });
        });
    }
/**
     * Refreshes token and stores new token in the supplied tokenPath file
     * */
Refreshes token and stores new token in the supplied tokenPath file
Refreshes token and stores new token in the supplied tokenPath file
refreshToken() {
        let options = {
            method: "POST",
            headers: {
                "Content-Type": "application/x-www-form-urlencoded",
            },
            form: {
                grant_type: "refresh_token", refresh_token: this.token.refresh_token,
                client_secret: this.token.client_secret
            }
        };
        let self = this;
        request("https://api.home-connect.com/security/oauth/token", options, (err, res, body) => {
            if (err) {
                self.log("Could not refresh token..." + err);
            }
            this.log("Token refresh received code: " + res.statusCode + (res.statusCode >= 300 ? ". Returning." : "."));
            if (res.statusCode >= 300) return;
            let new_token = JSON.parse(body);
            this.token.access_token = new_token.access_token;
            this.token.refresh_token = new_token.refresh_token;
            this.token.timestamp = (new Date()).getTime() / 1000;
            this.token.expires_in = new_token.expires_in;
            fs.writeFile(self.config.tokenPath, JSON.stringify(this.token), 'utf8', (err) => {
                if (err) {
                    this.log("An error occured while writing JSON Object to File.");
                    return this.log(err);
                }
                this.log("Token has been refreshed.");
            });
        });
    }
refreshToken ( ) { let options = { method : "POST" , headers : { "Content-Type" : "application/x-www-form-urlencoded" , } , form : { grant_type : "refresh_token" , refresh_token : this . token . refresh_token , client_secret : this . token . client_secret } } ; let self = this ; request ( "https://api.home-connect.com/security/oauth/token" , options , ( err , res , body ) => { if ( err ) { self . log ( "Could not refresh token..." + err ) ; } this . log ( "Token refresh received code: " + res . statusCode + ( res . statusCode >= 300 ? ". Returning." : "." ) ) ; if ( res . statusCode >= 300 ) return ; let new_token = JSON . parse ( body ) ; this . token . access_token = new_token . access_token ; this . token . refresh_token = new_token . refresh_token ; this . token . timestamp = ( new Date ( ) ) . getTime ( ) / 1000 ; this . token . expires_in = new_token . expires_in ; fs . writeFile ( self . config . tokenPath , JSON . stringify ( this . token ) , 'utf8' , ( err ) => { if ( err ) { this . log ( "An error occured while writing JSON Object to File." ) ; return this . log ( err ) ; } this . log ( "Token has been refreshed." ) ; } ) ; } ) ; }
Refreshes token and stores new token in the supplied tokenPath file
Refreshes token and stores new token in the supplied tokenPath file