@@ -19,7 +19,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
DefaultAuth Auth = &NoopAuth{opts: NewOptions()}
|
||||
DefaultAuth Auth = NewAuth()
|
||||
// ErrInvalidToken is when the token provided is not valid
|
||||
ErrInvalidToken = errors.New("invalid token provided")
|
||||
// ErrForbidden is when a user does not have the necessary scope to access a resource
|
||||
|
27
auth/noop.go
27
auth/noop.go
@@ -4,29 +4,29 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type NoopAuth struct {
|
||||
type noopAuth struct {
|
||||
opts Options
|
||||
}
|
||||
|
||||
// String returns the name of the implementation
|
||||
func (n *NoopAuth) String() string {
|
||||
func (n *noopAuth) String() string {
|
||||
return "noop"
|
||||
}
|
||||
|
||||
// Init the auth
|
||||
func (n *NoopAuth) Init(opts ...Option) {
|
||||
func (n *noopAuth) Init(opts ...Option) {
|
||||
for _, o := range opts {
|
||||
o(&n.opts)
|
||||
}
|
||||
}
|
||||
|
||||
// Options set for auth
|
||||
func (n *NoopAuth) Options() Options {
|
||||
func (n *noopAuth) Options() Options {
|
||||
return n.opts
|
||||
}
|
||||
|
||||
// Generate a new account
|
||||
func (n *NoopAuth) Generate(id string, opts ...GenerateOption) (*Account, error) {
|
||||
func (n *noopAuth) Generate(id string, opts ...GenerateOption) (*Account, error) {
|
||||
options := NewGenerateOptions(opts...)
|
||||
|
||||
return &Account{
|
||||
@@ -39,27 +39,27 @@ func (n *NoopAuth) Generate(id string, opts ...GenerateOption) (*Account, error)
|
||||
}
|
||||
|
||||
// Grant access to a resource
|
||||
func (n *NoopAuth) Grant(rule *Rule) error {
|
||||
func (n *noopAuth) Grant(rule *Rule) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Revoke access to a resource
|
||||
func (n *NoopAuth) Revoke(rule *Rule) error {
|
||||
func (n *noopAuth) Revoke(rule *Rule) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Rules used to verify requests
|
||||
func (n *NoopAuth) Rules(opts ...RulesOption) ([]*Rule, error) {
|
||||
func (n *noopAuth) Rules(opts ...RulesOption) ([]*Rule, error) {
|
||||
return []*Rule{}, nil
|
||||
}
|
||||
|
||||
// Verify an account has access to a resource
|
||||
func (n *NoopAuth) Verify(acc *Account, res *Resource, opts ...VerifyOption) error {
|
||||
func (n *noopAuth) Verify(acc *Account, res *Resource, opts ...VerifyOption) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Inspect a token
|
||||
func (n *NoopAuth) Inspect(token string) (*Account, error) {
|
||||
func (n *noopAuth) Inspect(token string) (*Account, error) {
|
||||
uid, err := uuid.NewRandom()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -68,6 +68,11 @@ func (n *NoopAuth) Inspect(token string) (*Account, error) {
|
||||
}
|
||||
|
||||
// Token generation using an account id and secret
|
||||
func (n *NoopAuth) Token(opts ...TokenOption) (*Token, error) {
|
||||
func (n *noopAuth) Token(opts ...TokenOption) (*Token, error) {
|
||||
return &Token{}, nil
|
||||
}
|
||||
|
||||
// NewAuth returns new noop auth
|
||||
func NewAuth(opts ...Option) Auth {
|
||||
return &noopAuth{opts: NewOptions(opts...)}
|
||||
}
|
||||
|
Reference in New Issue
Block a user