mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
25 lines
469 B
Go
25 lines
469 B
Go
package auth
|
|
|
|
import (
|
|
"github.com/nats-io/gnatsd/server"
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
type Token struct {
|
|
Token string
|
|
}
|
|
|
|
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
|
|
}
|