dd9309c15e
Initial vendor list validated with empty $GOPATH and only master checked out; followed by `make` and verified that all binaries build properly. Updates require github.com/LK4D4/vndr tool. Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
26 lines
568 B
Go
26 lines
568 B
Go
package auth
|
|
|
|
import (
|
|
"github.com/nats-io/gnatsd/server"
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
// Token holds a string token used for authentication
|
|
type Token struct {
|
|
Token string
|
|
}
|
|
|
|
// Check authenticates a client from a token
|
|
func (p *Token) Check(c server.ClientAuth) bool {
|
|
opts := c.GetOpts()
|
|
// Check to see if the token is a bcrypt hash
|
|
if isBcrypt(p.Token) {
|
|
if err := bcrypt.CompareHashAndPassword([]byte(p.Token), []byte(opts.Authorization)); err != nil {
|
|
return false
|
|
}
|
|
} else if p.Token != opts.Authorization {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|