e0e77f3983
* Updated auth interface * Add Rule * Remove Rule * Return token from Renew * Renew => Refresh * Implement Tokens & Default Auth Implementation * Change default auth to noop * Change default auth to noop * Move token.Token to auth.Token * Remove Token from Account * Auth service implementation * Decode JWT locally * Cookie for secret * Move string to bottom of interface definition * Depricate auth_exclude * Update auth wrappers * Update go.sum Co-authored-by: Ben Toogood <ben@micro.mu>
71 lines
1.3 KiB
Go
71 lines
1.3 KiB
Go
package auth
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
var (
|
|
DefaultAuth = NewAuth()
|
|
)
|
|
|
|
func NewAuth(opts ...Option) Auth {
|
|
return &noop{}
|
|
}
|
|
|
|
type noop struct {
|
|
opts Options
|
|
}
|
|
|
|
// String returns the name of the implementation
|
|
func (n *noop) String() string {
|
|
return "noop"
|
|
}
|
|
|
|
// Init the auth
|
|
func (n *noop) Init(opts ...Option) {
|
|
for _, o := range opts {
|
|
o(&n.opts)
|
|
}
|
|
}
|
|
|
|
// Options set for auth
|
|
func (n *noop) Options() Options {
|
|
return n.opts
|
|
}
|
|
|
|
// Generate a new account
|
|
func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) {
|
|
options := NewGenerateOptions(opts...)
|
|
|
|
return &Account{
|
|
ID: id,
|
|
Roles: options.Roles,
|
|
Metadata: options.Metadata,
|
|
}, nil
|
|
}
|
|
|
|
// Grant access to a resource
|
|
func (n *noop) Grant(role string, res *Resource) error {
|
|
return nil
|
|
}
|
|
|
|
// Revoke access to a resource
|
|
func (n *noop) Revoke(role string, res *Resource) error {
|
|
return nil
|
|
}
|
|
|
|
// Verify an account has access to a resource
|
|
func (n *noop) Verify(acc *Account, res *Resource) error {
|
|
return nil
|
|
}
|
|
|
|
// Inspect a token
|
|
func (n *noop) Inspect(token string) (*Account, error) {
|
|
return &Account{ID: uuid.New().String()}, nil
|
|
}
|
|
|
|
// Refresh an account using a secret
|
|
func (n *noop) Refresh(secret string, opts ...RefreshOption) (*Token, error) {
|
|
return &Token{}, nil
|
|
}
|