github.com/micro/go-micro/v2@v2.9.1/auth/default.go (about) 1 package auth 2 3 import ( 4 "github.com/google/uuid" 5 "github.com/micro/go-micro/v2/auth/provider/basic" 6 ) 7 8 var ( 9 DefaultAuth = NewAuth() 10 ) 11 12 func NewAuth(opts ...Option) Auth { 13 options := Options{ 14 Provider: basic.NewProvider(), 15 } 16 17 for _, o := range opts { 18 o(&options) 19 } 20 21 return &noop{ 22 opts: options, 23 } 24 } 25 26 type noop struct { 27 opts Options 28 } 29 30 // String returns the name of the implementation 31 func (n *noop) String() string { 32 return "noop" 33 } 34 35 // Init the auth 36 func (n *noop) Init(opts ...Option) { 37 for _, o := range opts { 38 o(&n.opts) 39 } 40 } 41 42 // Options set for auth 43 func (n *noop) Options() Options { 44 return n.opts 45 } 46 47 // Generate a new account 48 func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) { 49 options := NewGenerateOptions(opts...) 50 51 return &Account{ 52 ID: id, 53 Secret: options.Secret, 54 Metadata: options.Metadata, 55 Scopes: options.Scopes, 56 Issuer: n.Options().Namespace, 57 }, nil 58 } 59 60 // Grant access to a resource 61 func (n *noop) Grant(rule *Rule) error { 62 return nil 63 } 64 65 // Revoke access to a resource 66 func (n *noop) Revoke(rule *Rule) error { 67 return nil 68 } 69 70 // Rules used to verify requests 71 func (n *noop) Rules(opts ...RulesOption) ([]*Rule, error) { 72 return []*Rule{}, nil 73 } 74 75 // Verify an account has access to a resource 76 func (n *noop) Verify(acc *Account, res *Resource, opts ...VerifyOption) error { 77 return nil 78 } 79 80 // Inspect a token 81 func (n *noop) Inspect(token string) (*Account, error) { 82 return &Account{ID: uuid.New().String(), Issuer: n.Options().Namespace}, nil 83 } 84 85 // Token generation using an account id and secret 86 func (n *noop) Token(opts ...TokenOption) (*Token, error) { 87 return &Token{}, nil 88 }