iam

package
v0.0.0-...-f41e87c Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const ChallengeCollectionName = "challenges"
View Source
const CtxClaimsKey = "claims"
View Source
const UserCollectionName = "users"

Variables

This section is empty.

Functions

func Router

func Router(svc Svc) *chi.Mux

Types

type Challenge

type Challenge struct {
	Id                      primitive.Id `bson:"_id,omitempty" json:"id"`
	CreatedAt               time.Time    `bson:"createdAt" json:"-"`
	UpdatedAt               time.Time    `bson:"updatedAt" json:"-"`
	IdentityType            IdentityType `bson:"identityType" json:"identityType"`
	OTP                     string       `bson:"otp" json:"-"`
	FailedVerificationCount int          `bson:"failedVerificationCount" json:"-"`

	// Phone
	Phone Phone `bson:"phone,omitempty" json:"phone"`

	// Email
	EmailId string `bson:"emailId,omitempty" json:"emailId"`
}

func (Challenge) Validate

func (c Challenge) Validate() error

type Claims

type Claims struct {
	UserId      primitive.Id `json:"userId"`
	UserVersion int          `json:"userVersion"`
	Verified    bool         `json:"verified,omitempty"`
	Role        Role         `json:"role"`
	jwt.StandardClaims
}

func VerifyActionToken

func VerifyActionToken(ctx context.Context) (Claims, error)

func VerifySession

func VerifySession(ctx context.Context, hasAnyRole []Role) (Claims, error)

type Identity

type Identity struct {
	Id       primitive.Id `bson:"_id,omitempty" json:"id"`
	Type     IdentityType `bson:"type" json:"type"`
	Verified bool         `bson:"verified" json:"verified"`
	EmailId  string       `bson:"emailId,omitempty" json:"emailId"`
	Phone    *Phone       `bson:"phone,omitempty" json:"phone"`
}

type IdentityList

type IdentityList []Identity

type IdentityType

type IdentityType string
const (
	EMAIL IdentityType = "EMAIL"
	PHONE IdentityType = "PHONE"
)

type InviteReq

type InviteReq struct {
	Name    string `json:"name"`
	Phone   Phone  `json:"phone"`
	EmailId string `json:"emailId"`
	Role    Role   `json:"role"`
}

type LoginReq

type LoginReq struct {
	IdentityType IdentityType `json:"identityType"`

	EmailId string `json:"emailId"`
	Phone   Phone  `json:"phone"`

	Password string `json:"password"`
}

type Phone

type Phone struct {
	Number string `bson:"number,omitempty" json:"number"`
}

type Role

type Role string
const (
	PlatformAdmin Role = "PLATFORM_ADMIN"
	MerchantAdmin Role = "MERCHANT_ADMIN"
)

type Session

type Session struct {
	User  User   `json:"user"`
	Token string `json:"token"`
}

type Svc

type Svc interface {
	VerifySeedUser(ctx context.Context) error
	Invite(ctx context.Context, req InviteReq) (User, error)
	Challenge(ctx context.Context, challenge Challenge) (Challenge, error)
	Verify(ctx context.Context, req VerifyReq) (Session, error)
	UpdatePassword(ctx context.Context, userId primitive.Id, req UpdatePasswordReq) (bool, error)
	Login(ctx context.Context, req LoginReq) (Session, error)
	FindMe(ctx context.Context) (User, error)
	FindUser(ctx context.Context, id primitive.Id) (User, error)
}

func NewService

func NewService(userRepo UserRepo, challengeRepo ChallengeRepo, notificationService notification.Svc) Svc

type UpdatePasswordReq

type UpdatePasswordReq struct {
	IdentityType IdentityType `json:"identityType"`
	Password     string       `json:"password"`
}

type User

type User struct {
	Id                 primitive.Id `bson:"_id,omitempty" json:"id"`
	Role               Role         `bson:"role" json:"role"`
	Name               string       `bson:"name" json:"name"`
	Version            int          `bson:"version" json:"version"`
	FailedAuthAttempts int          `bson:"failedAuthAttempts" json:"-"`
	Identities         IdentityList `bson:"identities" json:"identities"`
	Password           string       `bson:"password" json:"-"`
}

type UserList

type UserList struct {
	Users []User          `json:"users"`
	Page  repository.Page `json:"page"`
}

type VerifyReq

type VerifyReq struct {
	IdentityType IdentityType `json:"identityType"`

	EmailId string `json:"emailId"`
	Phone   Phone  `json:"phone"`

	OTP string `json:"otp"`
}

Jump to

Keyboard shortcuts

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