Homey Community Forum

Web API issue when trying to utilize createOAuth2Callback to get authorization code for Homey

I know that Web API is work in progress but not sure if I am doing something wrong or it is API issue.

I am trying to authenticate as me in homey app. Since homey app is not exposed I can’t redirect to anything to get the authorization code so createOAuth2Callback seemed like perfect candidate. I am trying to do this authorisation on settings page so I simply emit event to settings script once createOAuth2Callback prepares url. So it looks like something similar to this:

const athomApi = new AthomCloudAPI({
    clientId: "5a8d4ca6eb9f7a2c9d6ccf6d",
    clientSecret: ""e3ace394af9f615857ceaa61b053f966ddcfb12a"",
    redirectUrl: "https://callback.athom.com/oauth2/callback/"
});

async startAuthorisation() {

        this.log("Authorization started");

        const oauth2 = await this.homey.cloud.createOAuth2Callback(athomApi .getLoginUrl());

        oauth2.on("url", (url) => {
            this.log(url);
            this.homey.api.realtime("authorisation-url", url);
        })
        .on("code", (code) => {
            this.log(code);
            this.homey.api.realtime("authorised-response", `Authorization was success! Code is: ${code}.`);
        });
    }

However this does not work as i am getting error message in settings popup: redirect url is not matching. As far as I understand createOAuth2Callback shoud create request on my behalf and return me the code.
https://callback.athom.com/oauth2/callback/” is the link that shoud do that for me and redirect URL is that one. I only made it go to actual authentication page if I use localhost as redirect page but then I can not get to authorization code.

Not sure if I don’t understand how this suppose to work or API is not working.

I know how to do it with user name and password but I wanted the way where I don’t need to know user credentials.

My guess is that Athom allows only for localhost with this client id (5a8d4ca6eb9f7a2c9d6ccf6d) but then how to test it in homey app. For example HomeyApi ZwaveManager can not be used without user been authenticated. I was planning on listening log updates so I can react to node reports but for that homey:manager:api is not sufficient.