micro/auth/default.go

89 lines
1.6 KiB
Go
Raw Permalink Normal View History

package auth
import (
"github.com/google/uuid"
"github.com/micro/go-micro/v2/auth/provider/basic"
)
var (
DefaultAuth = NewAuth()
)
func NewAuth(opts ...Option) Auth {
options := Options{
Provider: basic.NewProvider(),
}
for _, o := range opts {
o(&options)
}
return &noop{
opts: options,
}
}
type noop struct {
opts Options
}
// 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)
}
}
// Options set for auth
func (n *noop) Options() Options {
return n.opts
}
// Generate a new account
2020-04-01 19:20:02 +03:00
func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) {
options := NewGenerateOptions(opts...)
return &Account{
ID: id,
Secret: options.Secret,
Metadata: options.Metadata,
Scopes: options.Scopes,
2020-05-22 14:24:37 +03:00
Issuer: n.Options().Namespace,
}, nil
}
// Grant access to a resource
2020-05-20 13:59:01 +03:00
func (n *noop) Grant(rule *Rule) error {
return nil
}
// Revoke access to a resource
2020-05-20 13:59:01 +03:00
func (n *noop) Revoke(rule *Rule) error {
return nil
}
2020-05-20 13:59:01 +03:00
// Rules used to verify requests
2020-05-26 17:52:21 +03:00
func (n *noop) Rules(opts ...RulesOption) ([]*Rule, error) {
2020-05-20 13:59:01 +03:00
return []*Rule{}, nil
}
// Verify an account has access to a resource
2020-05-20 18:49:52 +03:00
func (n *noop) Verify(acc *Account, res *Resource, opts ...VerifyOption) error {
return nil
}
// Inspect a token
func (n *noop) Inspect(token string) (*Account, error) {
2020-05-22 14:40:34 +03:00
return &Account{ID: uuid.New().String(), Issuer: n.Options().Namespace}, nil
}
// Token generation using an account id and secret
2020-04-01 16:25:00 +03:00
func (n *noop) Token(opts ...TokenOption) (*Token, error) {
return &Token{}, nil
}