github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/auth/noop/noop.go (about) 1 // Copyright 2020 Asim Aslam 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // Original source: github.com/micro/go-micro/v3/auth/noop/noop.go 16 17 package noop 18 19 import ( 20 "github.com/google/uuid" 21 "github.com/tickoalcantara12/micro/v3/service/auth" 22 ) 23 24 func NewAuth(opts ...auth.Option) auth.Auth { 25 var options auth.Options 26 for _, o := range opts { 27 o(&options) 28 } 29 30 return &noop{ 31 opts: options, 32 } 33 } 34 35 type noop struct { 36 opts auth.Options 37 } 38 39 // String returns the name of the implementation 40 func (n *noop) String() string { 41 return "noop" 42 } 43 44 // Init the auth 45 func (n *noop) Init(opts ...auth.Option) { 46 for _, o := range opts { 47 o(&n.opts) 48 } 49 } 50 51 // Options set for auth 52 func (n *noop) Options() auth.Options { 53 return n.opts 54 } 55 56 // Generate a new account 57 func (n *noop) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) { 58 options := auth.NewGenerateOptions(opts...) 59 name := options.Name 60 if name == "" { 61 name = id 62 } 63 return &auth.Account{ 64 ID: id, 65 Secret: options.Secret, 66 Metadata: options.Metadata, 67 Scopes: options.Scopes, 68 Issuer: n.Options().Issuer, 69 Name: name, 70 }, nil 71 } 72 73 // Grant access to a resource 74 func (n *noop) Grant(rule *auth.Rule) error { 75 return nil 76 } 77 78 // Revoke access to a resource 79 func (n *noop) Revoke(rule *auth.Rule) error { 80 return nil 81 } 82 83 // Rules used to verify requests 84 func (n *noop) Rules(opts ...auth.RulesOption) ([]*auth.Rule, error) { 85 return []*auth.Rule{}, nil 86 } 87 88 // Verify an account has access to a resource 89 func (n *noop) Verify(acc *auth.Account, res *auth.Resource, opts ...auth.VerifyOption) error { 90 return nil 91 } 92 93 // Inspect a token 94 func (n *noop) Inspect(token string) (*auth.Account, error) { 95 return &auth.Account{ID: uuid.New().String(), Issuer: n.Options().Issuer}, nil 96 } 97 98 // Token generation using an account id and secret 99 func (n *noop) Token(opts ...auth.TokenOption) (*auth.AccountToken, error) { 100 return &auth.AccountToken{}, nil 101 }