2020-09-10 00:06:29 +03:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
2020-10-16 09:38:57 +03:00
|
|
|
type NoopAuth struct {
|
2020-09-10 00:06:29 +03:00
|
|
|
opts Options
|
|
|
|
}
|
|
|
|
|
|
|
|
// String returns the name of the implementation
|
2020-10-16 09:38:57 +03:00
|
|
|
func (n *NoopAuth) String() string {
|
2020-09-10 00:06:29 +03:00
|
|
|
return "noop"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init the auth
|
2020-10-16 09:38:57 +03:00
|
|
|
func (n *NoopAuth) Init(opts ...Option) {
|
2020-09-10 00:06:29 +03:00
|
|
|
for _, o := range opts {
|
|
|
|
o(&n.opts)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Options set for auth
|
2020-10-16 09:38:57 +03:00
|
|
|
func (n *NoopAuth) Options() Options {
|
2020-09-10 00:06:29 +03:00
|
|
|
return n.opts
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a new account
|
2020-10-16 09:38:57 +03:00
|
|
|
func (n *NoopAuth) Generate(id string, opts ...GenerateOption) (*Account, error) {
|
2020-09-10 00:06:29 +03:00
|
|
|
options := NewGenerateOptions(opts...)
|
|
|
|
|
|
|
|
return &Account{
|
|
|
|
ID: id,
|
|
|
|
Secret: options.Secret,
|
|
|
|
Metadata: options.Metadata,
|
|
|
|
Scopes: options.Scopes,
|
|
|
|
Issuer: n.Options().Issuer,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Grant access to a resource
|
2020-10-16 09:38:57 +03:00
|
|
|
func (n *NoopAuth) Grant(rule *Rule) error {
|
2020-09-10 00:06:29 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Revoke access to a resource
|
2020-10-16 09:38:57 +03:00
|
|
|
func (n *NoopAuth) Revoke(rule *Rule) error {
|
2020-09-10 00:06:29 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rules used to verify requests
|
2020-10-16 09:38:57 +03:00
|
|
|
func (n *NoopAuth) Rules(opts ...RulesOption) ([]*Rule, error) {
|
2020-09-10 00:06:29 +03:00
|
|
|
return []*Rule{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify an account has access to a resource
|
2020-10-16 09:38:57 +03:00
|
|
|
func (n *NoopAuth) Verify(acc *Account, res *Resource, opts ...VerifyOption) error {
|
2020-09-10 00:06:29 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inspect a token
|
2020-10-16 09:38:57 +03:00
|
|
|
func (n *NoopAuth) Inspect(token string) (*Account, error) {
|
2020-09-10 00:06:29 +03:00
|
|
|
uid, err := uuid.NewRandom()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &Account{ID: uid.String(), Issuer: n.Options().Issuer}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Token generation using an account id and secret
|
2020-10-16 09:38:57 +03:00
|
|
|
func (n *NoopAuth) Token(opts ...TokenOption) (*Token, error) {
|
2020-09-10 00:06:29 +03:00
|
|
|
return &Token{}, nil
|
|
|
|
}
|