Files
go-micro/auth/default.go
T

71 lines
1.3 KiB
Go
Raw Normal View History

2020-02-03 08:16:02 +00:00
package auth
2020-02-26 13:42:32 +00:00
import (
2020-03-23 16:19:30 +00:00
"github.com/google/uuid"
2020-02-26 13:42:32 +00:00
)
2020-02-03 08:16:02 +00:00
var (
DefaultAuth = NewAuth()
2020-02-03 08:16:02 +00:00
)
func NewAuth(opts ...Option) Auth {
2020-03-23 16:19:30 +00:00
return &noop{}
2020-02-03 08:16:02 +00:00
}
2020-03-23 16:19:30 +00:00
type noop struct {
opts Options
}
2020-03-23 16:19:30 +00:00
// String returns the name of the implementation
func (n *noop) String() string {
return "noop"
}
// Init the auth
func (n *noop) Init(opts ...Option) {
for _, o := range opts {
o(&n.opts)
}
}
2020-03-23 16:19:30 +00:00
// Options set for auth
func (n *noop) Options() Options {
return n.opts
}
2020-03-23 16:19:30 +00:00
// Generate a new account
func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) {
options := NewGenerateOptions(opts...)
2020-02-26 13:42:32 +00:00
return &Account{
2020-03-23 16:19:30 +00:00
ID: id,
Roles: options.Roles,
Metadata: options.Metadata,
2020-02-26 13:42:32 +00:00
}, nil
}
2020-03-23 16:19:30 +00:00
// Grant access to a resource
func (n *noop) Grant(role string, res *Resource) error {
return nil
}
// Revoke access to a resource
func (n *noop) Revoke(role string, res *Resource) error {
return nil
}
// Verify an account has access to a resource
func (n *noop) Verify(acc *Account, res *Resource) error {
return nil
}
// Inspect a token
func (n *noop) Inspect(token string) (*Account, error) {
return &Account{ID: uuid.New().String()}, nil
}
// Refresh an account using a secret
func (n *noop) Refresh(secret string, opts ...RefreshOption) (*Token, error) {
return &Token{}, nil
2020-02-03 08:16:02 +00:00
}