hanayo/routers/oauth/client_sha256.go
2019-02-23 13:29:15 +00:00

34 lines
637 B
Go

package oauth
import (
"crypto/sha256"
"fmt"
"github.com/RangelReale/osin"
"github.com/felipeweb/osin-mysql"
)
// storage is a custom type of storage that implements client secrets saved in the dabase as sha256 hashes
type storage struct {
*mysql.Storage
}
func (s storage) GetClient(id string) (osin.Client, error) {
cl, err := s.Storage.GetClient(id)
return client{cl}, err
}
func (s storage) Clone() osin.Storage {
return s
}
type client struct {
osin.Client
}
func (c client) ClientSecretMatches(i string) bool {
a := c.GetSecret() == fmt.Sprintf("%x", sha256.Sum256([]byte(i)))
//fmt.Println("SES", a)
return a
}