Update interface to add provider and make secret optional

This commit is contained in:
Ben Toogood 2020-03-31 19:01:43 +01:00
parent cffb0a1eae
commit 82bc3cbf8d
6 changed files with 153 additions and 79 deletions

View File

@ -32,9 +32,9 @@ type Auth interface {
// Options set for auth
Options() Options
// Generate a new account
Generate(id, secret string, opts ...GenerateOption) (*Account, error)
Generate(id string, opts ...GenerateOption) (*Account, error)
// Login to an existing account
Login(id, secret string) (*Account, error)
Login(id string, opts ...LoginOption) (*Account, error)
// Grant access to a resource
Grant(role string, res *Resource) error
// Revoke access to a resource
@ -61,10 +61,12 @@ type Resource struct {
// Account provided by an auth provider
type Account struct {
// Type of the account, e.g. service
Type string `json:"type"`
// ID of the account e.g. email
ID string `json:"id"`
// Type of the account, e.g. service
Type string `json:"type"`
// Provider who issued the account
Provider string `json:"provider"`
// RefreshToken used to renew the account
RefreshToken string `json:"refresh_token"`
// Roles associated with the Account

View File

@ -34,7 +34,7 @@ func (n *noop) Options() Options {
}
// Generate a new account
func (n *noop) Generate(id, secret string, opts ...GenerateOption) (*Account, error) {
func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) {
options := NewGenerateOptions(opts...)
return &Account{
@ -46,7 +46,7 @@ func (n *noop) Generate(id, secret string, opts ...GenerateOption) (*Account, er
}
// Login to an existing account
func (n *noop) Login(id, secret string) (*Account, error) {
func (n *noop) Login(id string, opts ...LoginOption) (*Account, error) {
return &Account{ID: id}, nil
}

View File

@ -78,10 +78,23 @@ type GenerateOptions struct {
Roles []string
// Namespace the account belongs too
Namespace string
// Secret to use with the account
Secret string
// Provider of the account, e.g. oauth
Provider string
// Type of the account, e.g. user
Type string
}
type GenerateOption func(o *GenerateOptions)
// WithType for the generated account
func WithType(t string) GenerateOption {
return func(o *GenerateOptions) {
o.Type = t
}
}
// WithMetadata for the generated account
func WithMetadata(md map[string]string) GenerateOption {
return func(o *GenerateOptions) {
@ -103,6 +116,20 @@ func WithNamespace(n string) GenerateOption {
}
}
// WithSecret for the generated account
func WithSecret(s string) GenerateOption {
return func(o *GenerateOptions) {
o.Secret = s
}
}
// WithProvider for the generated account
func WithProvider(p string) GenerateOption {
return func(o *GenerateOptions) {
o.Provider = p
}
}
// NewGenerateOptions from a slice of options
func NewGenerateOptions(opts ...GenerateOption) GenerateOptions {
var options GenerateOptions
@ -112,6 +139,29 @@ func NewGenerateOptions(opts ...GenerateOption) GenerateOptions {
return options
}
type LoginOptions struct {
// Secret to use for rlogin
Secret string
}
type LoginOption func(o *LoginOptions)
// WithLoginSecret for the generated account
func WithLoginSecret(s string) LoginOption {
return func(o *LoginOptions) {
o.Secret = s
}
}
// NewLoginOptions from a slice of options
func NewLoginOptions(opts ...LoginOption) LoginOptions {
var options LoginOptions
for _, o := range opts {
o(&options)
}
return options
}
type TokenOptions struct {
// TokenExpiry is the time the token should live for
TokenExpiry time.Duration

View File

@ -215,12 +215,12 @@ func (m *Token) GetNamespace() string {
type Account struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
// string secret = 2;
Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
Roles []string `protobuf:"bytes,3,rep,name=roles,proto3" json:"roles,omitempty"`
Metadata map[string]string `protobuf:"bytes,4,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
Namespace string `protobuf:"bytes,5,opt,name=namespace,proto3" json:"namespace,omitempty"`
Type string `protobuf:"bytes,6,opt,name=type,proto3" json:"type,omitempty"`
RefreshToken string `protobuf:"bytes,7,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token,omitempty"`
RefreshToken string `protobuf:"bytes,6,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token,omitempty"`
Provider string `protobuf:"bytes,7,opt,name=provider,proto3" json:"provider,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -258,6 +258,13 @@ func (m *Account) GetId() string {
return ""
}
func (m *Account) GetType() string {
if m != nil {
return m.Type
}
return ""
}
func (m *Account) GetRoles() []string {
if m != nil {
return m.Roles
@ -279,16 +286,16 @@ func (m *Account) GetNamespace() string {
return ""
}
func (m *Account) GetType() string {
func (m *Account) GetRefreshToken() string {
if m != nil {
return m.Type
return m.RefreshToken
}
return ""
}
func (m *Account) GetRefreshToken() string {
func (m *Account) GetProvider() string {
if m != nil {
return m.RefreshToken
return m.Provider
}
return ""
}
@ -441,6 +448,7 @@ type GenerateRequest struct {
Namespace string `protobuf:"bytes,4,opt,name=namespace,proto3" json:"namespace,omitempty"`
Secret string `protobuf:"bytes,5,opt,name=secret,proto3" json:"secret,omitempty"`
Type string `protobuf:"bytes,6,opt,name=type,proto3" json:"type,omitempty"`
Provider string `protobuf:"bytes,7,opt,name=provider,proto3" json:"provider,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -513,6 +521,13 @@ func (m *GenerateRequest) GetType() string {
return ""
}
func (m *GenerateRequest) GetProvider() string {
if m != nil {
return m.Provider
}
return ""
}
type GenerateResponse struct {
Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
@ -1221,64 +1236,65 @@ func init() {
}
var fileDescriptor_11312eec02fd5712 = []byte{
// 931 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0x6d, 0x6f, 0xdb, 0x36,
0x10, 0x8e, 0x24, 0x5b, 0x56, 0xce, 0x96, 0x63, 0xb0, 0x69, 0x26, 0xb8, 0x2f, 0xcb, 0xd4, 0x61,
0xc8, 0x8a, 0x55, 0x19, 0x5c, 0x60, 0x6f, 0x05, 0x86, 0x19, 0xb5, 0xe1, 0xb5, 0x6b, 0x3d, 0x4c,
0xe8, 0x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x26, 0xe3, 0x9e, 0x41, 0x00, 0xec, 0xf1, 0x64, 0xf6, 0x64, 0x32,
0xee, 0x99, 0xc3, 0x3f, 0x4d, 0x68, 0x8c, 0x32, 0x7e, 0x42, 0x9e, 0x83, 0xa3, 0x27, 0x0f, 0xb9,
0xfb, 0xe6, 0x01, 0xdb, 0x7f, 0x77, 0xe3, 0xb9, 0xe2, 0xb3, 0x45, 0x9e, 0x42, 0x4b, 0x35, 0x21,
0xb9, 0x53, 0xd1, 0x5e, 0x6d, 0xe2, 0xfe, 0xdd, 0x4d, 0xc7, 0x05, 0xd6, 0x58, 0x7f, 0xad, 0x6e,
0xd5, 0x36, 0x83, 0xc2, 0xb9, 0x5d, 0x7f, 0x58, 0x46, 0x91, 0x8f, 0xd8, 0x1a, 0x4a, 0xf9, 0x49,
0x5c, 0x43, 0x59, 0x79, 0xf7, 0xfc, 0xad, 0xe1, 0x8f, 0xe0, 0xe8, 0xff, 0x22, 0xf9, 0x0e, 0x1a,
0x22, 0x4d, 0xa4, 0xfa, 0xa7, 0xaa, 0xf9, 0x6b, 0xf6, 0xef, 0xbd, 0x51, 0xa7, 0x80, 0xff, 0xdb,
0x80, 0xa6, 0x48, 0x27, 0x23, 0x53, 0xb0, 0xf3, 0x02, 0x26, 0x55, 0x97, 0x56, 0x1a, 0xac, 0x7f,
0x67, 0xc3, 0x69, 0xc1, 0x7b, 0x0a, 0x76, 0x5e, 0x6d, 0x6b, 0x40, 0x2b, 0xdd, 0xb0, 0x06, 0x54,
0x29, 0xd1, 0x2d, 0x32, 0x52, 0x74, 0xfb, 0x35, 0x54, 0x34, 0xc8, 0xad, 0xda, 0x33, 0x0d, 0x71,
0x64, 0xcb, 0xef, 0xf9, 0xc3, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x8f, 0xd3, 0xdd, 0x57, 0xd9,
0x0b, 0x00, 0x00,
}

View File

@ -39,11 +39,12 @@ message Token {
message Account {
string id = 1;
string type = 2;
repeated string roles = 3;
map<string, string> metadata = 4;
string namespace = 5;
string type = 6;
string refresh_token = 7;
string refresh_token = 6;
string provider = 7;
}
message Resource{
@ -68,6 +69,7 @@ message GenerateRequest {
string namespace = 4;
string secret = 5;
string type = 6;
string provider = 7;
}
message GenerateResponse {

View File

@ -107,14 +107,16 @@ func (s *svc) Options() auth.Options {
}
// Generate a new account
func (s *svc) Generate(id, secret string, opts ...auth.GenerateOption) (*auth.Account, error) {
func (s *svc) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, error) {
options := auth.NewGenerateOptions(opts...)
rsp, err := s.auth.Generate(context.TODO(), &pb.GenerateRequest{
Id: id,
Secret: secret,
Type: options.Type,
Roles: options.Roles,
Secret: options.Secret,
Metadata: options.Metadata,
Provider: options.Provider,
Namespace: options.Namespace,
})
if err != nil {
@ -125,8 +127,9 @@ func (s *svc) Generate(id, secret string, opts ...auth.GenerateOption) (*auth.Ac
}
// Login to an account
func (s *svc) Login(id, secret string) (*auth.Account, error) {
rsp, err := s.auth.Login(context.TODO(), &pb.LoginRequest{Id: id, Secret: secret})
func (s *svc) Login(id string, opts ...auth.LoginOption) (*auth.Account, error) {
options := auth.NewLoginOptions(opts...)
rsp, err := s.auth.Login(context.TODO(), &pb.LoginRequest{Id: id, Secret: options.Secret})
if err != nil {
return nil, err
}
@ -331,6 +334,7 @@ func serializeAccount(a *pb.Account) *auth.Account {
ID: a.Id,
Roles: a.Roles,
Metadata: a.Metadata,
Provider: a.Provider,
Namespace: a.Namespace,
RefreshToken: a.RefreshToken,
}