nats.go: BUG: a Client can't authorize by a token

I’ve tried a client authorization by token and always get the error:

sergey@debian:~/go/src/gitlab.com/sarbash/tms-notifyd$ go run main.go 
2017/08/19 21:52:45 nats: authorization violation
exit status 1

The code is as follows:

const (
	natsServer = `nats://xxxxxx.yyyyyyyy.ru:4222`
	orderSubj  = `orders.Update`
	natsToken  = "$xx$xx$XXxXXXXXXXxXxxxxXXXxXXXxXXxxXxXXxXXXXXXxXXxX/XxxxXXxX"
)

func main() {
	natsConnection, err := nats.Connect(natsServer, nats.Token(natsToken))
	if err != nil {
		log.Fatalln(err)
	}
	log.Println("Connected to NATS")

	// Subscribe to subject
	cb := msgHandler
	log.Printf("Subscribing to subject '%s'\n", orderSubj)
	natsConnection.Subscribe(orderSubj, cb)

	// Keep the connection alive
	runtime.Goexit()
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

The following configuration works for me with nats-server version 1.0.0:

$ go run mkpasswd.go
pass: RPsTaOgu054hJSAhXa2rhd
bcrypt hash: $2a$11$v0wp3xFBbdhRoMTg4PMx6ON2qnm4gImadS8Of3cneUAbUZbXsScC.
port: 4222

authorization {
  token: $2a$11$v0wp3xFBbdhRoMTg4PMx6ON2qnm4gImadS8Of3cneUAbUZbXsScC.
  timeout:  1
}
package main

import (
        "fmt"
        "github.com/nats-io/go-nats"
)

func main() {
        conn, err := nats.Connect(nats.DefaultURL, nats.Token("RPsTaOgu054hJSAhXa2rhd"))
        if err != nil {
                panic(err)
        }
        defer conn.Close()
        fmt.Println("connected")
}
$ go run main.go
connected