1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-30 10:10:44 +02:00
go-micro/auth/noop.go

92 lines
1.6 KiB
Go
Raw Normal View History

package auth
import (
"github.com/google/uuid"
)
var (
DefaultAuth = NewAuth()
)
func NewAuth(opts ...Option) Auth {
2020-12-12 21:06:43 +02:00
options := Options{}
for _, o := range opts {
o(&options)
}
return &noop{
opts: options,
}
}
2020-12-12 22:08:39 +02:00
func NewRules() Rules {
return new(noopRules)
}
type noop struct {
opts Options
}
2020-12-12 22:08:39 +02:00
type noopRules struct{}
2022-09-30 16:27:07 +02:00
// String returns the name of the implementation.
func (n *noop) String() string {
return "noop"
}
2022-09-30 16:27:07 +02:00
// Init the auth.
func (n *noop) Init(opts ...Option) {
for _, o := range opts {
o(&n.opts)
}
}
2022-09-30 16:27:07 +02:00
// Options set for auth.
func (n *noop) Options() Options {
return n.opts
}
2022-09-30 16:27:07 +02:00
// Generate a new account.
2020-04-01 18:20:02 +02: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 13:24:37 +02:00
Issuer: n.Options().Namespace,
}, nil
}
2022-09-30 16:27:07 +02:00
// Grant access to a resource.
2020-12-12 22:08:39 +02:00
func (n *noopRules) Grant(rule *Rule) error {
return nil
}
2022-09-30 16:27:07 +02:00
// Revoke access to a resource.
2020-12-12 22:08:39 +02:00
func (n *noopRules) Revoke(rule *Rule) error {
return nil
}
2020-05-20 12:59:01 +02:00
// Rules used to verify requests
2022-09-30 16:27:07 +02:00
// Verify an account has access to a resource.
2020-12-12 22:08:39 +02:00
func (n *noopRules) Verify(acc *Account, res *Resource, opts ...VerifyOption) error {
return nil
}
2020-12-12 22:08:39 +02:00
func (n *noopRules) List(opts ...ListOption) ([]*Rule, error) {
return []*Rule{}, nil
}
2022-09-30 16:27:07 +02:00
// Inspect a token.
func (n *noop) Inspect(token string) (*Account, error) {
2020-05-22 13:40:34 +02:00
return &Account{ID: uuid.New().String(), Issuer: n.Options().Namespace}, nil
}
2022-09-30 16:27:07 +02:00
// Token generation using an account id and secret.
2020-04-01 15:25:00 +02:00
func (n *noop) Token(opts ...TokenOption) (*Token, error) {
return &Token{}, nil
}