2020-02-03 11:16:02 +03:00
|
|
|
package auth
|
|
|
|
|
2020-02-26 16:42:32 +03:00
|
|
|
import (
|
2020-03-23 19:19:30 +03:00
|
|
|
"github.com/google/uuid"
|
2020-02-26 16:42:32 +03:00
|
|
|
)
|
|
|
|
|
2020-02-03 11:16:02 +03:00
|
|
|
var (
|
2020-02-24 18:07:27 +03:00
|
|
|
DefaultAuth = NewAuth()
|
2020-02-03 11:16:02 +03:00
|
|
|
)
|
|
|
|
|
2020-02-24 18:07:27 +03:00
|
|
|
func NewAuth(opts ...Option) Auth {
|
2020-07-19 13:37:40 +03:00
|
|
|
var options Options
|
2020-04-09 16:10:17 +03:00
|
|
|
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &noop{
|
|
|
|
opts: options,
|
|
|
|
}
|
2020-02-03 11:16:02 +03:00
|
|
|
}
|
|
|
|
|
2020-03-23 19:19:30 +03:00
|
|
|
type noop struct {
|
2020-02-26 01:15:44 +03:00
|
|
|
opts Options
|
|
|
|
}
|
2020-02-03 11:16:02 +03:00
|
|
|
|
2020-03-23 19:19:30 +03:00
|
|
|
// String returns the name of the implementation
|
|
|
|
func (n *noop) String() string {
|
|
|
|
return "noop"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init the auth
|
|
|
|
func (n *noop) Init(opts ...Option) {
|
2020-02-26 01:15:44 +03:00
|
|
|
for _, o := range opts {
|
|
|
|
o(&n.opts)
|
|
|
|
}
|
2020-02-03 11:16:02 +03:00
|
|
|
}
|
|
|
|
|
2020-03-23 19:19:30 +03:00
|
|
|
// Options set for auth
|
|
|
|
func (n *noop) Options() Options {
|
2020-02-26 01:15:44 +03:00
|
|
|
return n.opts
|
2020-02-10 11:26:28 +03:00
|
|
|
}
|
|
|
|
|
2020-03-23 19:19:30 +03:00
|
|
|
// Generate a new account
|
2020-04-01 19:20:02 +03:00
|
|
|
func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) {
|
2020-03-23 19:19:30 +03:00
|
|
|
options := NewGenerateOptions(opts...)
|
2020-02-26 16:42:32 +03:00
|
|
|
|
2020-03-23 19:19:30 +03:00
|
|
|
return &Account{
|
2020-05-19 20:17:17 +03:00
|
|
|
ID: id,
|
|
|
|
Secret: options.Secret,
|
|
|
|
Metadata: options.Metadata,
|
|
|
|
Scopes: options.Scopes,
|
2020-06-17 14:26:27 +03:00
|
|
|
Issuer: n.Options().Issuer,
|
2020-03-23 19:19:30 +03:00
|
|
|
}, nil
|
2020-02-03 11:16:02 +03:00
|
|
|
}
|
|
|
|
|
2020-03-23 19:19:30 +03:00
|
|
|
// Grant access to a resource
|
2020-05-20 13:59:01 +03:00
|
|
|
func (n *noop) Grant(rule *Rule) error {
|
2020-02-03 11:16:02 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-03-23 19:19:30 +03:00
|
|
|
// Revoke access to a resource
|
2020-05-20 13:59:01 +03:00
|
|
|
func (n *noop) Revoke(rule *Rule) error {
|
2020-03-23 19:19:30 +03:00
|
|
|
return nil
|
|
|
|
}
|
2020-02-26 16:42:32 +03:00
|
|
|
|
2020-05-20 13:59:01 +03:00
|
|
|
// Rules used to verify requests
|
2020-05-26 17:52:21 +03:00
|
|
|
func (n *noop) Rules(opts ...RulesOption) ([]*Rule, error) {
|
2020-05-20 13:59:01 +03:00
|
|
|
return []*Rule{}, nil
|
|
|
|
}
|
|
|
|
|
2020-03-23 19:19:30 +03:00
|
|
|
// Verify an account has access to a resource
|
2020-05-20 18:49:52 +03:00
|
|
|
func (n *noop) Verify(acc *Account, res *Resource, opts ...VerifyOption) error {
|
2020-03-23 19:19:30 +03:00
|
|
|
return nil
|
|
|
|
}
|
2020-02-26 16:42:32 +03:00
|
|
|
|
2020-03-23 19:19:30 +03:00
|
|
|
// Inspect a token
|
|
|
|
func (n *noop) Inspect(token string) (*Account, error) {
|
2020-06-17 14:26:27 +03:00
|
|
|
return &Account{ID: uuid.New().String(), Issuer: n.Options().Issuer}, nil
|
2020-02-03 11:16:02 +03:00
|
|
|
}
|
2020-02-24 18:07:27 +03:00
|
|
|
|
2020-03-31 12:06:13 +03:00
|
|
|
// Token generation using an account id and secret
|
2020-04-01 16:25:00 +03:00
|
|
|
func (n *noop) Token(opts ...TokenOption) (*Token, error) {
|
2020-03-23 19:19:30 +03:00
|
|
|
return &Token{}, nil
|
2020-02-24 18:07:27 +03:00
|
|
|
}
|