Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication Problem #1

Open
koileLab opened this issue May 10, 2020 · 2 comments
Open

Authentication Problem #1

koileLab opened this issue May 10, 2020 · 2 comments

Comments

@koileLab
Copy link

koileLab commented May 10, 2020

Hey,
I tried this with the same device.
[Edit: moved /dev/input/eventN-Thing to an own issue #https://github.com//issues/2]

But the https://github.com/sbender9/signalk-anchoralarm-plugin Log just returned a 401 Error

There might be some layer of Authentication I don't get...
https://signalk.org/specification/1.3.0/doc/security.html

@bergie
Copy link
Member

bergie commented May 10, 2020

Do you have security enabled on Signal K? I haven't tested the software with that. But would be very happy to help you figure that one out, or to get a PR adding that feature

@koileLab
Copy link
Author

koileLab commented May 21, 2020

I have it up running!
I came from a fresh install of Signalk via Openplotter2 stable. I can't see the security option signalk nor in the security.json. @sbender9 mentioned in signalk slack the posibility to exclude it in the security.json, mine looks like

{

  "allow_readonly": true,
  "expiration": "1d",
  "allowNewUserRegistration": true,
  "allowDeviceAccessRequests": true,
  "users": [
    {
      "username": "Alice",
      "type": "admin",
      "password": "12345678"
    }
  ],
  "devices": [],
  "secretKey": "12345678"
}

Changingallow_readonly": true to false just changed the style of the 401...

We changed the listener.py to handle the authentification

...
dev = InputDevice('/dev/input/event0')
print("Connected to button")

session = requests.Session()

clicks = 0
timer = None
def count_clicks():
    global clicks, timer
    session.post('http://localhost:3000/signalk/v1/auth/login', data={'username': 'Alice', 'password': '12345678'})
    if clicks > 1:
        print("Double click, raise anchor")
        response = session.post('http://localhost:3000/plugins/anchoralarm/raiseAnchor', data = {})
        print(response.text)
    else:
        print("Click, drop anchor")
        response = session.post('http://localhost:3000/plugins/anchoralarm/dropAnchor', data = {})
        print(response.text)
    clicks = 0
    timer = None
...

What are the chnages:

  • Change r to response for a better overview ;)
  • Added in the global layer a Session Thingi for handling the Authetification by Cockies acording to Signalk Specs
  • We added a login in the routine via session.post('http://localhost:3000/signalk/v1/auth/login', data={'username': 'Alice', 'password': '12345678'})
  • In generel it would be also possible or even recommended(?) to do it with a token vor not having the pwd hardcoded in the script...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants