authentify

package module
v0.0.0-...-9e16d20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPrefixChars = "ABC"
	DefaultCodeLength  = 6
	DefaultCodeChars   = "1234567890"
)

Variables

View Source
var File_api_Authentify_proto protoreflect.FileDescriptor

Functions

func GrpcProtoServiceDesc

func GrpcProtoServiceDesc() *grpc.ServiceDesc

func RandString

func RandString(chars []rune, length uint) string

Types

type Authenticator

type Authenticator interface {
	SendCode(ctx context.Context, sender Sender, to string) (_ Token, prefix string, _ error)
	RetrieveToken(ctx context.Context, receiver string) (Token, error)
}

func NewAuthenticator

func NewAuthenticator(opt Options) (Authenticator, error)

type Code

type Code interface {
	fmt.Stringer
	GetCode() string
	GetPrefix() string
	Hash() (HashedCode, error)
}

func NewCode

func NewCode(prefix, c string) (Code, error)

type GrpcProtoClient

type GrpcProtoClient interface {
	SendOTP(ctx context.Context, in *ProtoSendOTPRequest, opts ...grpc.CallOption) (*ProtoSendOTPResponse, error)
	CheckOTP(ctx context.Context, in *ProtoCheckOTPRequest, opts ...grpc.CallOption) (*ProtoCheckOTPResponse, error)
}

func NewGrpcProtoClient

func NewGrpcProtoClient(cc *grpc.ClientConn) GrpcProtoClient

type GrpcProtoServer

type GrpcProtoServer interface {
	SendOTP(context.Context, *ProtoSendOTPRequest) (*ProtoSendOTPResponse, error)
	CheckOTP(context.Context, *ProtoCheckOTPRequest) (*ProtoCheckOTPResponse, error)
	// contains filtered or unexported methods
}

func NewGrpcProtoServer

func NewGrpcProtoServer(a Authenticator, senders SendersMap) (GrpcProtoServer, error)

type HashedCode

type HashedCode interface {
	Bytes() []byte
	Check(a Code) error
}

func AsHashedCode

func AsHashedCode(hash []byte) (HashedCode, error)

type Options

type Options struct {
	PrefixChars, CodeChars []rune
	CodeLength, SaltLength uint
	Repo                   Repo
	TTL                    time.Duration
}

type ProtoCheckOTPRequest

type ProtoCheckOTPRequest struct {
	Code     string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"`
	Prefix   string `protobuf:"bytes,2,opt,name=prefix,proto3" json:"prefix,omitempty"`
	Salt     []byte `protobuf:"bytes,3,opt,name=salt,proto3" json:"salt,omitempty"`
	Receiver string `protobuf:"bytes,4,opt,name=receiver,proto3" json:"receiver,omitempty"`
	Type     string `protobuf:"bytes,5,opt,name=type,proto3" json:"type,omitempty"`
	// contains filtered or unexported fields
}

func (*ProtoCheckOTPRequest) Descriptor deprecated

func (*ProtoCheckOTPRequest) Descriptor() ([]byte, []int)

Deprecated: Use ProtoCheckOTPRequest.ProtoReflect.Descriptor instead.

func (*ProtoCheckOTPRequest) GetCode

func (x *ProtoCheckOTPRequest) GetCode() string

func (*ProtoCheckOTPRequest) GetPrefix

func (x *ProtoCheckOTPRequest) GetPrefix() string

func (*ProtoCheckOTPRequest) GetReceiver

func (x *ProtoCheckOTPRequest) GetReceiver() string

func (*ProtoCheckOTPRequest) GetSalt

func (x *ProtoCheckOTPRequest) GetSalt() []byte

func (*ProtoCheckOTPRequest) GetType

func (x *ProtoCheckOTPRequest) GetType() string

func (*ProtoCheckOTPRequest) ProtoMessage

func (*ProtoCheckOTPRequest) ProtoMessage()

func (*ProtoCheckOTPRequest) ProtoReflect

func (x *ProtoCheckOTPRequest) ProtoReflect() protoreflect.Message

func (*ProtoCheckOTPRequest) Reset

func (x *ProtoCheckOTPRequest) Reset()

func (*ProtoCheckOTPRequest) String

func (x *ProtoCheckOTPRequest) String() string

type ProtoCheckOTPResponse

type ProtoCheckOTPResponse struct {
	Deadline *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=deadline,proto3" json:"deadline,omitempty"`
	Valid    bool                   `protobuf:"varint,4,opt,name=valid,proto3" json:"valid,omitempty"`
	// contains filtered or unexported fields
}

func (*ProtoCheckOTPResponse) Descriptor deprecated

func (*ProtoCheckOTPResponse) Descriptor() ([]byte, []int)

Deprecated: Use ProtoCheckOTPResponse.ProtoReflect.Descriptor instead.

func (*ProtoCheckOTPResponse) GetDeadline

func (x *ProtoCheckOTPResponse) GetDeadline() *timestamppb.Timestamp

func (*ProtoCheckOTPResponse) GetValid

func (x *ProtoCheckOTPResponse) GetValid() bool

func (*ProtoCheckOTPResponse) ProtoMessage

func (*ProtoCheckOTPResponse) ProtoMessage()

func (*ProtoCheckOTPResponse) ProtoReflect

func (x *ProtoCheckOTPResponse) ProtoReflect() protoreflect.Message

func (*ProtoCheckOTPResponse) Reset

func (x *ProtoCheckOTPResponse) Reset()

func (*ProtoCheckOTPResponse) String

func (x *ProtoCheckOTPResponse) String() string

type ProtoSendOTPRequest

type ProtoSendOTPRequest struct {
	To   string `protobuf:"bytes,1,opt,name=to,proto3" json:"to,omitempty"`
	Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
	// contains filtered or unexported fields
}

func (*ProtoSendOTPRequest) Descriptor deprecated

func (*ProtoSendOTPRequest) Descriptor() ([]byte, []int)

Deprecated: Use ProtoSendOTPRequest.ProtoReflect.Descriptor instead.

func (*ProtoSendOTPRequest) GetTo

func (x *ProtoSendOTPRequest) GetTo() string

func (*ProtoSendOTPRequest) GetType

func (x *ProtoSendOTPRequest) GetType() string

func (*ProtoSendOTPRequest) ProtoMessage

func (*ProtoSendOTPRequest) ProtoMessage()

func (*ProtoSendOTPRequest) ProtoReflect

func (x *ProtoSendOTPRequest) ProtoReflect() protoreflect.Message

func (*ProtoSendOTPRequest) Reset

func (x *ProtoSendOTPRequest) Reset()

func (*ProtoSendOTPRequest) String

func (x *ProtoSendOTPRequest) String() string

type ProtoSendOTPResponse

type ProtoSendOTPResponse struct {
	Deadline *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=deadline,proto3" json:"deadline,omitempty"`
	Salt     []byte                 `protobuf:"bytes,2,opt,name=salt,proto3" json:"salt,omitempty"`
	Prefix   string                 `protobuf:"bytes,3,opt,name=prefix,proto3" json:"prefix,omitempty"`
	// contains filtered or unexported fields
}

func (*ProtoSendOTPResponse) Descriptor deprecated

func (*ProtoSendOTPResponse) Descriptor() ([]byte, []int)

Deprecated: Use ProtoSendOTPResponse.ProtoReflect.Descriptor instead.

func (*ProtoSendOTPResponse) GetDeadline

func (x *ProtoSendOTPResponse) GetDeadline() *timestamppb.Timestamp

func (*ProtoSendOTPResponse) GetPrefix

func (x *ProtoSendOTPResponse) GetPrefix() string

func (*ProtoSendOTPResponse) GetSalt

func (x *ProtoSendOTPResponse) GetSalt() []byte

func (*ProtoSendOTPResponse) ProtoMessage

func (*ProtoSendOTPResponse) ProtoMessage()

func (*ProtoSendOTPResponse) ProtoReflect

func (x *ProtoSendOTPResponse) ProtoReflect() protoreflect.Message

func (*ProtoSendOTPResponse) Reset

func (x *ProtoSendOTPResponse) Reset()

func (*ProtoSendOTPResponse) String

func (x *ProtoSendOTPResponse) String() string

type Repo

type Repo interface {
	Store(ctx context.Context, id string, val []byte, deadline time.Time) (err error)
	FindByID(ctx context.Context, id string) ([]byte, error)
	io.Closer
}

func BadgerAsRepo

func BadgerAsRepo(db *badger.DB) (Repo, error)

type Salt

type Salt interface {
	Bytes() []byte
	Equal([]byte) bool
	Hex() string
}

func AsSalt

func AsSalt(b []byte) (Salt, error)

func GenSalt

func GenSalt(len uint) (Salt, error)

type Sender

type Sender interface {
	Send(ctx context.Context, to string, code Code, expireAt time.Time) error
	Name() string
	io.Closer
}

type SendersMap

type SendersMap = map[string]Sender

func SendersToMap

func SendersToMap(senders ...Sender) (SendersMap, error)

type Token

type Token interface {
	Deadline() time.Time
	Validate(sender string, code Code, salt Salt) bool
	Receiver() string
	EncodeTo(dst io.Writer) error
	Encode() ([]byte, error)
	Sender() string
	Salt() Salt
}

func DecodeToken

func DecodeToken(b []byte) (Token, error)

func NewToken

func NewToken(senderName, to string, deadline time.Time, code HashedCode, salt Salt) (Token, error)

type TokenID

type TokenID = uuid.UUID

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL