users

package
v0.0.0-...-eec4b17 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthenticatedUserRole = "user"
	UnauthorizedUserRole  = "anonymous"
)

Variables

View Source
var (
	ErrInvalidLengthService        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowService          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupService = fmt.Errorf("proto: unexpected end of group")
)

Functions

func RegisterUsersServiceServer

func RegisterUsersServiceServer(s grpc1.Server, srv UsersServiceServer)

Types

type AuthorizedSessionResponse

type AuthorizedSessionResponse struct {
	*UnauthorizedSessionResponse
	// contains filtered or unexported fields
}

func NewAuthorizedHasuraSessionResponse

func NewAuthorizedHasuraSessionResponse(unauthorizedResponse *UnauthorizedSessionResponse, userAddress string) *AuthorizedSessionResponse

func (*AuthorizedSessionResponse) MarshalJSON

func (r *AuthorizedSessionResponse) MarshalJSON() ([]byte, error)

type Database

type Database interface {
	authentication.Database

	GetNonce(desmosAddress string, value string) (*types.EncryptedNonce, error)
	SaveNonce(nonce *types.Nonce) error
	DeleteNonce(nonce *types.EncryptedNonce) error

	SaveUser(desmosAddress string) error
	UpdateLoginInfo(desmosAddress string) error
	DeleteAllSessions(desmosAddress string) error

	SaveUserNotificationDeviceToken(token *types.UserNotificationDeviceToken) error
}

type DeleteAccountRequest

type DeleteAccountRequest struct {
	UserAddress string
}

func NewDeleteAccountRequest

func NewDeleteAccountRequest(userAddress string) *DeleteAccountRequest

type GetNonceRequest

type GetNonceRequest struct {
	// UserDesmosAddress represents the Desmos address of the user for which to
	// get the nonce
	UserDesmosAddress string `protobuf:"bytes,1,opt,name=user_desmos_address,json=userDesmosAddress,proto3" json:"user_desmos_address,omitempty"`
}

func (*GetNonceRequest) Descriptor

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

func (*GetNonceRequest) GetUserDesmosAddress

func (m *GetNonceRequest) GetUserDesmosAddress() string

func (*GetNonceRequest) Marshal

func (m *GetNonceRequest) Marshal() (dAtA []byte, err error)

func (*GetNonceRequest) MarshalTo

func (m *GetNonceRequest) MarshalTo(dAtA []byte) (int, error)

func (*GetNonceRequest) MarshalToSizedBuffer

func (m *GetNonceRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*GetNonceRequest) ProtoMessage

func (*GetNonceRequest) ProtoMessage()

func (*GetNonceRequest) Reset

func (m *GetNonceRequest) Reset()

func (*GetNonceRequest) Size

func (m *GetNonceRequest) Size() (n int)

func (*GetNonceRequest) String

func (m *GetNonceRequest) String() string

func (*GetNonceRequest) Unmarshal

func (m *GetNonceRequest) Unmarshal(dAtA []byte) error

func (*GetNonceRequest) XXX_DiscardUnknown

func (m *GetNonceRequest) XXX_DiscardUnknown()

func (*GetNonceRequest) XXX_Marshal

func (m *GetNonceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GetNonceRequest) XXX_Merge

func (m *GetNonceRequest) XXX_Merge(src proto.Message)

func (*GetNonceRequest) XXX_Size

func (m *GetNonceRequest) XXX_Size() int

func (*GetNonceRequest) XXX_Unmarshal

func (m *GetNonceRequest) XXX_Unmarshal(b []byte) error

type GetNonceResponse

type GetNonceResponse struct {
	// Nonce represents the nonce value that should be signed in order to login
	// the user
	Nonce string `protobuf:"bytes,1,opt,name=nonce,proto3" json:"nonce,omitempty"`
}

func NewGetNonceResponse

func NewGetNonceResponse(nonce string) *GetNonceResponse

NewGetNonceResponse builds a new GetNonceRequest instance

func (*GetNonceResponse) Descriptor

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

func (*GetNonceResponse) GetNonce

func (m *GetNonceResponse) GetNonce() string

func (*GetNonceResponse) Marshal

func (m *GetNonceResponse) Marshal() (dAtA []byte, err error)

func (*GetNonceResponse) MarshalTo

func (m *GetNonceResponse) MarshalTo(dAtA []byte) (int, error)

func (*GetNonceResponse) MarshalToSizedBuffer

func (m *GetNonceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*GetNonceResponse) ProtoMessage

func (*GetNonceResponse) ProtoMessage()

func (*GetNonceResponse) Reset

func (m *GetNonceResponse) Reset()

func (*GetNonceResponse) Size

func (m *GetNonceResponse) Size() (n int)

func (*GetNonceResponse) String

func (m *GetNonceResponse) String() string

func (*GetNonceResponse) Unmarshal

func (m *GetNonceResponse) Unmarshal(dAtA []byte) error

func (*GetNonceResponse) XXX_DiscardUnknown

func (m *GetNonceResponse) XXX_DiscardUnknown()

func (*GetNonceResponse) XXX_Marshal

func (m *GetNonceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GetNonceResponse) XXX_Merge

func (m *GetNonceResponse) XXX_Merge(src proto.Message)

func (*GetNonceResponse) XXX_Size

func (m *GetNonceResponse) XXX_Size() int

func (*GetNonceResponse) XXX_Unmarshal

func (m *GetNonceResponse) XXX_Unmarshal(b []byte) error

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(cdc codec.Codec, amino *codec.LegacyAmino, db Database) *Handler

NewHandler returns a new Handler instance

func (*Handler) GetUnauthorizedHasuraSession

func (h *Handler) GetUnauthorizedHasuraSession() HasuraSessionResponse

GetUnauthorizedHasuraSession returns the session used to authenticate an unauthorized Hasura user

func (*Handler) HandleAuthenticationRequest

func (h *Handler) HandleAuthenticationRequest(request *types.SignedRequest) (*LoginResponse, error)

HandleAuthenticationRequest checks the given request to make sure the user has authenticated correctly

func (*Handler) HandleDeleteAccountRequest

func (h *Handler) HandleDeleteAccountRequest(req *DeleteAccountRequest) error

HandleDeleteAccountRequest allows to handle the request of deleting a user account

func (*Handler) HandleHasuraSessionRequest

func (h *Handler) HandleHasuraSessionRequest(token string) (HasuraSessionResponse, error)

HandleHasuraSessionRequest returns the session used to authenticate a Hasura user

func (*Handler) HandleLogoutRequest

func (h *Handler) HandleLogoutRequest(req *LogoutUserRequest) error

HandleLogoutRequest allows to handle the request of logging out a user that is connected using the given session

func (*Handler) HandleNonceRequest

func (h *Handler) HandleNonceRequest(request *GetNonceRequest) (*GetNonceResponse, error)

HandleNonceRequest returns the proper nonce for the given request

func (*Handler) HandleRefreshSessionRequest

func (h *Handler) HandleRefreshSessionRequest(token string) (*RefreshSessionResponse, error)

HandleRefreshSessionRequest refreshes the session associated with the given request

func (*Handler) HandleRegisterUserDeviceTokenRequest

func (h *Handler) HandleRegisterUserDeviceTokenRequest(req *RegisterUserDeviceTokenRequest) error

HandleRegisterUserDeviceTokenRequest handles the request to register a new device token

type HasuraSessionResponse

type HasuraSessionResponse interface {
	MarshalJSON() ([]byte, error)
}

type HasuraSessionResponseJSON

type HasuraSessionResponseJSON struct {
	UserRole    string `json:"X-Hasura-Role"`
	UserAddress string `json:"X-Hasura-User-Address,omitempty"`
}

type LoginResponse

type LoginResponse struct {
	// Token represents the bearer token that can be used to authenticate requests
	// from the user without having to continuously perform the whole login
	// procedure
	Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"`
	// ExpirationTime represents the time at which the token will expire
	ExpirationTime *time.Time `protobuf:"bytes,2,opt,name=expiration_time,json=expirationTime,proto3,stdtime" json:"expiration_time,omitempty"`
}

func NewLoginResponse

func NewLoginResponse(token string, expirationTime *time.Time) *LoginResponse

NewLoginResponse builds a new LoginResponse instance

func (*LoginResponse) Descriptor

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

func (*LoginResponse) GetExpirationTime

func (m *LoginResponse) GetExpirationTime() *time.Time

func (*LoginResponse) GetToken

func (m *LoginResponse) GetToken() string

func (*LoginResponse) Marshal

func (m *LoginResponse) Marshal() (dAtA []byte, err error)

func (*LoginResponse) MarshalTo

func (m *LoginResponse) MarshalTo(dAtA []byte) (int, error)

func (*LoginResponse) MarshalToSizedBuffer

func (m *LoginResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*LoginResponse) ProtoMessage

func (*LoginResponse) ProtoMessage()

func (*LoginResponse) Reset

func (m *LoginResponse) Reset()

func (*LoginResponse) Size

func (m *LoginResponse) Size() (n int)

func (*LoginResponse) String

func (m *LoginResponse) String() string

func (*LoginResponse) Unmarshal

func (m *LoginResponse) Unmarshal(dAtA []byte) error

func (*LoginResponse) XXX_DiscardUnknown

func (m *LoginResponse) XXX_DiscardUnknown()

func (*LoginResponse) XXX_Marshal

func (m *LoginResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*LoginResponse) XXX_Merge

func (m *LoginResponse) XXX_Merge(src proto.Message)

func (*LoginResponse) XXX_Size

func (m *LoginResponse) XXX_Size() int

func (*LoginResponse) XXX_Unmarshal

func (m *LoginResponse) XXX_Unmarshal(b []byte) error

type LogoutRequest

type LogoutRequest struct {
	// LogoutFromAll tells whether the user should be logout from all sessions.
	// If false, the user will be logout only from the current session.
	LogoutFromAll bool `protobuf:"varint,1,opt,name=logout_from_all,json=logoutFromAll,proto3" json:"logout_from_all,omitempty"`
}

func (*LogoutRequest) Descriptor

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

func (*LogoutRequest) GetLogoutFromAll

func (m *LogoutRequest) GetLogoutFromAll() bool

func (*LogoutRequest) Marshal

func (m *LogoutRequest) Marshal() (dAtA []byte, err error)

func (*LogoutRequest) MarshalTo

func (m *LogoutRequest) MarshalTo(dAtA []byte) (int, error)

func (*LogoutRequest) MarshalToSizedBuffer

func (m *LogoutRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*LogoutRequest) ProtoMessage

func (*LogoutRequest) ProtoMessage()

func (*LogoutRequest) Reset

func (m *LogoutRequest) Reset()

func (*LogoutRequest) Size

func (m *LogoutRequest) Size() (n int)

func (*LogoutRequest) String

func (m *LogoutRequest) String() string

func (*LogoutRequest) Unmarshal

func (m *LogoutRequest) Unmarshal(dAtA []byte) error

func (*LogoutRequest) XXX_DiscardUnknown

func (m *LogoutRequest) XXX_DiscardUnknown()

func (*LogoutRequest) XXX_Marshal

func (m *LogoutRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*LogoutRequest) XXX_Merge

func (m *LogoutRequest) XXX_Merge(src proto.Message)

func (*LogoutRequest) XXX_Size

func (m *LogoutRequest) XXX_Size() int

func (*LogoutRequest) XXX_Unmarshal

func (m *LogoutRequest) XXX_Unmarshal(b []byte) error

type LogoutUserRequest

type LogoutUserRequest struct {
	Token            string
	LogoutAllDevices bool `json:"logout_all_devices"`
}

func NewLogoutUserRequest

func NewLogoutUserRequest(token string, logoutAll bool) *LogoutUserRequest

type RefreshSessionResponse

type RefreshSessionResponse struct {
	// Token represents the new token that should be used to authenticate future
	// requests after the refresh of the session.
	Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"`
	// ExpirationTime represents the time at which the token will expire
	ExpirationTime *time.Time `protobuf:"bytes,2,opt,name=expiration_time,json=expirationTime,proto3,stdtime" json:"expiration_time,omitempty"`
}

func NewSessionRefreshResponse

func NewSessionRefreshResponse(token string, expirationTime *time.Time) *RefreshSessionResponse

NewSessionRefreshResponse builds a new SessionRefreshResponse instance

func (*RefreshSessionResponse) Descriptor

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

func (*RefreshSessionResponse) GetExpirationTime

func (m *RefreshSessionResponse) GetExpirationTime() *time.Time

func (*RefreshSessionResponse) GetToken

func (m *RefreshSessionResponse) GetToken() string

func (*RefreshSessionResponse) Marshal

func (m *RefreshSessionResponse) Marshal() (dAtA []byte, err error)

func (*RefreshSessionResponse) MarshalTo

func (m *RefreshSessionResponse) MarshalTo(dAtA []byte) (int, error)

func (*RefreshSessionResponse) MarshalToSizedBuffer

func (m *RefreshSessionResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*RefreshSessionResponse) ProtoMessage

func (*RefreshSessionResponse) ProtoMessage()

func (*RefreshSessionResponse) Reset

func (m *RefreshSessionResponse) Reset()

func (*RefreshSessionResponse) Size

func (m *RefreshSessionResponse) Size() (n int)

func (*RefreshSessionResponse) String

func (m *RefreshSessionResponse) String() string

func (*RefreshSessionResponse) Unmarshal

func (m *RefreshSessionResponse) Unmarshal(dAtA []byte) error

func (*RefreshSessionResponse) XXX_DiscardUnknown

func (m *RefreshSessionResponse) XXX_DiscardUnknown()

func (*RefreshSessionResponse) XXX_Marshal

func (m *RefreshSessionResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RefreshSessionResponse) XXX_Merge

func (m *RefreshSessionResponse) XXX_Merge(src proto.Message)

func (*RefreshSessionResponse) XXX_Size

func (m *RefreshSessionResponse) XXX_Size() int

func (*RefreshSessionResponse) XXX_Unmarshal

func (m *RefreshSessionResponse) XXX_Unmarshal(b []byte) error

type RegisterNotificationDeviceTokenRequest

type RegisterNotificationDeviceTokenRequest struct {
	// DeviceToken represents the device token that should be registered as a
	// notification device token for the user
	DeviceToken string `protobuf:"bytes,1,opt,name=device_token,json=deviceToken,proto3" json:"device_token,omitempty"`
}

func (*RegisterNotificationDeviceTokenRequest) Descriptor

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

func (*RegisterNotificationDeviceTokenRequest) GetDeviceToken

func (m *RegisterNotificationDeviceTokenRequest) GetDeviceToken() string

func (*RegisterNotificationDeviceTokenRequest) Marshal

func (m *RegisterNotificationDeviceTokenRequest) Marshal() (dAtA []byte, err error)

func (*RegisterNotificationDeviceTokenRequest) MarshalTo

func (m *RegisterNotificationDeviceTokenRequest) MarshalTo(dAtA []byte) (int, error)

func (*RegisterNotificationDeviceTokenRequest) MarshalToSizedBuffer

func (m *RegisterNotificationDeviceTokenRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*RegisterNotificationDeviceTokenRequest) ProtoMessage

func (*RegisterNotificationDeviceTokenRequest) Reset

func (*RegisterNotificationDeviceTokenRequest) Size

func (*RegisterNotificationDeviceTokenRequest) String

func (*RegisterNotificationDeviceTokenRequest) Unmarshal

func (m *RegisterNotificationDeviceTokenRequest) Unmarshal(dAtA []byte) error

func (*RegisterNotificationDeviceTokenRequest) XXX_DiscardUnknown

func (m *RegisterNotificationDeviceTokenRequest) XXX_DiscardUnknown()

func (*RegisterNotificationDeviceTokenRequest) XXX_Marshal

func (m *RegisterNotificationDeviceTokenRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RegisterNotificationDeviceTokenRequest) XXX_Merge

func (*RegisterNotificationDeviceTokenRequest) XXX_Size

func (*RegisterNotificationDeviceTokenRequest) XXX_Unmarshal

func (m *RegisterNotificationDeviceTokenRequest) XXX_Unmarshal(b []byte) error

type RegisterUserDeviceTokenRequest

type RegisterUserDeviceTokenRequest struct {
	UserAddress string
	DeviceToken string
}

RegisterUserDeviceTokenRequest represents the request sent when a user wants to register a new device token to receive notifications

func NewRegisterUserDeviceTokenRequest

func NewRegisterUserDeviceTokenRequest(userAddress string, token string) *RegisterUserDeviceTokenRequest

func (RegisterUserDeviceTokenRequest) Validate

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(handler *Handler) *Server

func NewServerFromEnvVariables

func NewServerFromEnvVariables(cdc codec.Codec, amino *codec.LegacyAmino, db Database) *Server

func (*Server) DeleteAccount

func (s *Server) DeleteAccount(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error)

func (*Server) GetNonce

func (s *Server) GetNonce(ctx context.Context, request *GetNonceRequest) (*GetNonceResponse, error)

func (*Server) Login

func (s *Server) Login(ctx context.Context, request *types.SignedRequest) (*LoginResponse, error)

func (*Server) Logout

func (s *Server) Logout(ctx context.Context, request *LogoutRequest) (*emptypb.Empty, error)

func (*Server) RefreshSession

func (s *Server) RefreshSession(ctx context.Context, _ *emptypb.Empty) (*RefreshSessionResponse, error)

func (*Server) RegisterDeviceNotificationToken

func (s *Server) RegisterDeviceNotificationToken(ctx context.Context, request *RegisterNotificationDeviceTokenRequest) (*emptypb.Empty, error)

type UnauthorizedSessionResponse

type UnauthorizedSessionResponse struct {
}

func NewUnauthorizedHasuraSessionResponse

func NewUnauthorizedHasuraSessionResponse() *UnauthorizedSessionResponse

func (*UnauthorizedSessionResponse) MarshalJSON

func (r *UnauthorizedSessionResponse) MarshalJSON() ([]byte, error)

type UnimplementedUsersServiceServer

type UnimplementedUsersServiceServer struct {
}

UnimplementedUsersServiceServer can be embedded to have forward compatible implementations.

func (*UnimplementedUsersServiceServer) DeleteAccount

func (*UnimplementedUsersServiceServer) GetNonce

func (*UnimplementedUsersServiceServer) Login

func (*UnimplementedUsersServiceServer) Logout

func (*UnimplementedUsersServiceServer) RefreshSession

func (*UnimplementedUsersServiceServer) RegisterDeviceNotificationToken

type UsersServiceClient

type UsersServiceClient interface {
	// GetNonce allows to get a nonce that can later be signed to login the user
	// inside the APIs
	GetNonce(ctx context.Context, in *GetNonceRequest, opts ...grpc.CallOption) (*GetNonceResponse, error)
	// Login allows to finish the login procedure and get a bearer token to
	// authenticate future requests
	Login(ctx context.Context, in *types.SignedRequest, opts ...grpc.CallOption) (*LoginResponse, error)
	// RefreshSession allows the user to refresh their current session
	RefreshSession(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*RefreshSessionResponse, error)
	// RegisterDeviceNotificationToken allows to register a notification device
	// tokens for future notifications
	RegisterDeviceNotificationToken(ctx context.Context, in *RegisterNotificationDeviceTokenRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
	// Logout allows the user to logout from either the current or all sessions
	Logout(ctx context.Context, in *LogoutRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
	// DeleteAccount allows the user to delete their account
	// Note: Data will be deleted after 14 days of inactivity. During this time,
	// the user can login again in order to stop the deletion procedure.
	DeleteAccount(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error)
}

UsersServiceClient is the client API for UsersService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewUsersServiceClient

func NewUsersServiceClient(cc grpc1.ClientConn) UsersServiceClient

type UsersServiceServer

type UsersServiceServer interface {
	// GetNonce allows to get a nonce that can later be signed to login the user
	// inside the APIs
	GetNonce(context.Context, *GetNonceRequest) (*GetNonceResponse, error)
	// Login allows to finish the login procedure and get a bearer token to
	// authenticate future requests
	Login(context.Context, *types.SignedRequest) (*LoginResponse, error)
	// RefreshSession allows the user to refresh their current session
	RefreshSession(context.Context, *emptypb.Empty) (*RefreshSessionResponse, error)
	// RegisterDeviceNotificationToken allows to register a notification device
	// tokens for future notifications
	RegisterDeviceNotificationToken(context.Context, *RegisterNotificationDeviceTokenRequest) (*emptypb.Empty, error)
	// Logout allows the user to logout from either the current or all sessions
	Logout(context.Context, *LogoutRequest) (*emptypb.Empty, error)
	// DeleteAccount allows the user to delete their account
	// Note: Data will be deleted after 14 days of inactivity. During this time,
	// the user can login again in order to stop the deletion procedure.
	DeleteAccount(context.Context, *emptypb.Empty) (*emptypb.Empty, error)
}

UsersServiceServer is the server API for UsersService service.

Jump to

Keyboard shortcuts

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