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

How to use auth? #20

Open
iMiMx opened this issue May 10, 2021 · 3 comments
Open

How to use auth? #20

iMiMx opened this issue May 10, 2021 · 3 comments

Comments

@iMiMx
Copy link

iMiMx commented May 10, 2021

I wonder if someone could perhaps point me in the right direction? I seem to be stumbling around in circles. Essentially, trying to use auth - 'WithAuth' I believe.

Running (suspect documentation is out of date, since the old knq repo was archived):

go get -u github.com/knq/hilink

Produces:

go: downloading github.com/knq/hilink v0.1.0
go get: github.com/knq/hilink@none updating to
        github.com/knq/[email protected]: parsing go.mod:
        module declares its path as: github.com/kenshaw/hilink
                but was required as: github.com/knq/hilink

So I change to:

go get -u github.com/kenshaw/hilink

Then, in:

~/go/pkg/mod/github.com/kenshaw/[email protected]/cmd/hlcli

Edit main.go change:

        opts := []hilink.ClientOption{
                hilink.WithURL(*endpoint),

To:

        opts := []hilink.ClientOption{
                hilink.WithURL(*endpoint),
                hilink.WithAuth("admin", "password"),

Run 'go build' in the above directory... seems to build ok...

If I run the binary, I don't see any 'POST' to attempt to log the user in:

./hlcli SmsList -v
2021/05/10 12:01:51 -> POST /api/sms/sms-list HTTP/1.1
-> Host: 192.168.8.1
-> User-Agent: Go-http-client/1.1
-> Content-Length: 228
-> Content-Type: application/x-www-form-urlencoded; charset=UTF-8
-> __requestverificationtoken:
-> Accept-Encoding: gzip

Within client.go it mentions:

// WithAuth is a client option specifying the identifier and password to use.
// The option is ignored if id is an empty string.

... so is it being ignored, because it thinks the id is an empty string?

@iMiMx
Copy link
Author

iMiMx commented May 10, 2021

I must be missing something simple, just not sure what or where.

./hlcli LogInfo -v
2021/05/10 12:11:21 -> GET /api/device/logsetting HTTP/1.1
-> Host: 192.168.8.1
-> User-Agent: Go-http-client/1.1
-> Accept-Encoding: gzip
->
->

2021/05/10 12:11:21 <- HTTP/1.1 200 OK
<- Content-Length: 88
<- Cache-Control: no-cache, no-store, max-age=0, must-revalidate
<- Content-Security-Policy: default-src 'self' 'unsafe-inline' 'unsafe-eval'
<- Pragma: no-cache
<- X-Content-Type-Options: nosniff
<- X-Download-Options: noopen
<- X-Frame-Options: SAMEORIGIN
<- X-Xss-Protection: 1; mode=block
<-
<- <?xml version="1.0" encoding="UTF-8"?>
<- <error>
<- <code>100003</code>
<- <message/>
<- </error>
<-

error: hilink error 100003: unauthorized

@kenshaw
Copy link
Owner

kenshaw commented May 10, 2021

I would suggest disabling authentication on your device. Unfortunately, the Hilink devices that I have work just fine with this package. I'm happy to accept a PR that fixes this issue, but since the device I'm using is different than what you're likely using, I'm not sure I can directly help.

@GattoMeo
Copy link

I've same problem: my E8372 (I have before an E3531 3G, but now no 3G network more available, only 4g here) has the login (admin:admin) but isn't option to disabling from the web configuration. Is possible only to change password, but no empty. I need the hlcli to active automatically with a script and send SSM from a linux server.
I've add in the "main.go" :

opts := []hilink.ClientOption{
hilink.WithURL(*endpoint),
hilink.WithAuth("admin", "admin"),

but same "unauthorized" issue. Another file to edit/fill to have the correct login?

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

No branches or pull requests

3 participants