Visual Code and Openhab 3.0

This is what I am using, but still no luck
:frowning:

And the settings

openhab.host
openhab.port

didn’t change and are properly configured?

It worked in 100% of the questions raised here with this solution.

Hi,
Both the port (which is optional anyway I think) and the host are set.

The configuration used to work properly when I was running 2.5.
It may be easier if I start from a fresh install

Thanks anyway

Why should the port be optional?
I am not really into the codebase now but i would not bet that it can be omitted.

Are you able to get a json response from:

http://openhab.user:openhab.password@openhab.host:openhab.port/rest/things

with your extension config calues filled in, when you execute this in the browser?

About the port:
In the documentation (openhab-vscode/USAGE.md at master · openhab/openhab-vscode · GitHub) it says:
“openhab.port (optional), default: 8080”

Anyway, I have it defined.

When I try

http://openhab.MYUSER:openhab.MYPSWD@192.168.31.2:8080/rest/things

I get
{“error”: {“message”: “Authentication required”,“http-code”: 401}}

(This is still true after a new OH install)

Thanks

1 Like

I think you missunderstood me above.

Should be http://MYUSER:MYPSWD@192.168.31.2:8080/rest/things

I used the config syntax to make cleare that the same values as configured in the extension should be used.
Sorry if this caused some confusion.

Hey there, i had the same Problem.

Please head to API Security, enable “show advanced” disable “Implicit…”, hit “save”, that worked for me

Hi,
fist of all thanks for your help. Really appreciated!

@Dynamyte
No difference for me (I had already tried that, but I gave it another go anyway)

@Confectrician
I have tried the correct syntax and I still get the 401 error code
Just to be clear I used the credentials I use to login as an admin into the new home page.
I have also removed the special characters ($) I was using in my password (just in case)

What I have discovered though that the API do not require authorization eg:
http://192.168.31.2:8080/rest/
shows all the APIs available

Are you using any kind of reverse proxy in your setup?

I have problems accessing the rest api with this user credential link too, when i open it in browser,
because nginx reverse proxy will reqrite my request.

But doing it with a special api client like postman worked for me with basic auth.
I have tested it especially for you before posting the questions above.

I have one last idea to get the problem sorted out a bit at least.
You could temporary disable the whole authentication for rest api via openHAB console.

When you are able to connect this way with the vscode extension (just host and port configured not user and passsword). We have to start looking at the authentication again.
If there is still errors we have to check again in the extension configuration first.

I am running Openhabian which I installed from scratch yesterday morning on pi Pi4.
It is a standard setup and I have not set any reverse proxy (that I know of).

So as I said earlier I realised that I did not need authorization to access the api, therefore I have deleted Username and Password in the VS Code settings and now I can connect (??)
I have Basic Authentication enabled

I am confused but can work for the moment

With the settigns shown above you can access the api via the implicit user role.
There may be api actions that are still restricted since they do not belong to the “user role”

Similar problem here. With the following settings:

"openhab.host": "http://openhab",
"openhab.port": 8080,
"openhab.username": "Admin",
"openhab.password": "iwonttellyoumypassword"

No matter whether implicit user roles are enabled or disabled. Port 5007 (LSP) does not work either, which one should I use? It also does not work with an API token instead of a password (I would usually prefer the first option).

I always receive the following error message from the openHAB extension:

Error while connecting to openHAB REST API. self signed certificate

And loads of ENOTFOUND and parse error in the OH Language Server output in VSC.

I also found this related thread, but it still seems to be unresolved: [OH3] REST API Authentication Help.

So you are using openhab with https?
Probably behind a reverse proxy?

Edit:
Token based authentication won’t work with the extension for now.
I have stated that already somewhere but will add it to my FAQ thread now.

So you are using openhab with https?
Probably behind a reverse proxy?

No, I haven’t set up anything like this. I wish I could, but some months ago this looked far too sophisticated to me.

Any other ideas? So this should work in theory?

In theory it should work with an http connection yes.

Could you please try to remove the http:// from your config for testing in the openhab.host setting.
Second try would be to enter the ip adress directly instead of the hostname.

Alltough i doubt that it will work with a self signed certificate error.

Success! Turns out that you have to reload the VS Code window after every change you have made to the settings. This is a bit counter-intuitive, I have just left an issue for this in the extension repository.

To sum up, the following configuration now works for me:

"openhab.host": "openhab",
"openhab.port": 8080,
"openhab.username": "Admin",
"openhab.password": "iwonttellyoumypassword"

I’m looking forward to the day when you will be able to use tokens for authentication – it feels kind of unsafe to store my password in plain text, especially because I have turned on settings sync via the Microsoft cloud … :slight_smile:

2 Likes

Yeah maybe we could solve that if we reload the window on puprose after a config change.
Maybe we can subscribe to a config change via api and then reload settings.
But cleanest way would probably be to reload the window and activate the extension from scratch.

Anyway huge thanks for bringing it to github directly. :+1:

1 Like

If you create an API token specifically for VS code (that’s the point of these tokens, you dedicate them to specific services so you don’t have to share your master password around), you should be able to use it as your username if you leave the password blank.

2 Likes

Yeah maybe we could solve that if we reload the window on puprose after a config change.

Nah, rather not, there are too many other extensions that do not properly resume after the window has been reloaded. I think the cleanest solution would just be to reload the settings every time manually – how expensive can this be today? However, probably we should move this discussion to GitHub. :slight_smile:

1 Like

Ah, thanks a lot! I very recently found out something similar, see this post:

(However, I don’t understand why you have to specify the access token as user but not as password! I think the common solution is to enter it as password instead. Is OH really following the (in)official standards here?)