identity

package
v0.0.0-...-dae10ae Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessToken sessionTokenType = iota
	RefreshToken
)
View Source
const (
	EventUserCreated = "UserCreated"
)
View Source
const OAuthStateLen = 10

Variables

View Source
var EventPublisher interface {
	Publish(event string, payload []byte)
	Subscribe(event string, cb func([]byte)) func()
}
View Source
var GithubAdapter interface {
	CreateOAuthURI(state string) (string, error)
	FetchOAuthToken(code string) (GithubOAuthToken, error)
	FetchUserPublicProfile(token string) (GithubUserPublicProfile, error)
}
View Source
var InvalidCredential = fmt.Errorf("invalid credential.")
View Source
var InvalidPassword = fmt.Errorf("invalid password.")
View Source
var ThirdPartyOAuthTokenRepository interface {
	Save(entity *ThirdPartyOAuthToken) error
	SaveByUserIDAndType(entity *ThirdPartyOAuthToken) error
	ExistActiveOne(userID int64, tokenType ThirdPartyTokenType) (bool, error)
}
View Source
var UserInvalidRefreshTokenRepository interface {
	Save(entity *UserInvalidRefreshToken) error
	Exist(userID int64, tokenID string) (bool, error)
}
View Source
var UserNameDuplicate = fmt.Errorf("user name has been used.")
View Source
var UserNameTooShort = fmt.Errorf("user name too short.")
View Source
var UserRepository interface {
	Save(entity *User) error
	Find(id int64) (User, error)
	FindByUserName(username string) (User, error)
	FindByGithubID(githubID int64) (User, error)
	FindByTodo(todoID int64) (User, error)
	ExistByUserName(username string) (bool, error)
	ExistByGithubID(githubID int64) (bool, error)
}

Functions

func NewGithubOAuthURI

func NewGithubOAuthURI() (string, error)

func NewPassword

func NewPassword(pwd string) (password, error)

func NewPasswordByBytes

func NewPasswordByBytes(bytes []byte) password

func PublishUserCreatedEvent

func PublishUserCreatedEvent(userID int64)

Types

type Config

type Config struct {
	AccessTokenExpiresIn         int // second
	AccessTokenRefreshThreshold  int // second
	RefreshTokenExpiresInDefault int // second
	RefreshTokenExpiresInMax     int // second
	RefreshTokenExpiresInOAuth   int // second
	OAuthStateExpiresIn          int // second
	TokenIssuer                  string

	// secret
	PasswordNonce   []byte
	TokenHmacSecret []byte
}
var Conf Config

*

  • Config

type Error

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

func (Error) Error

func (e Error) Error() string

func (Error) Unwrap

func (e Error) Unwrap() error

type Event

type Event string

type GithubOAuthToken

type GithubOAuthToken struct {
	AccessToken string
	Scope       string
	TokenType   string
}

type GithubUserPublicProfile

type GithubUserPublicProfile struct {
	ID        int64
	Name      string
	AvatarURL string
	Email     string
}

type ThirdPartyOAuthToken

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

aggregate

func NewThirdPartyOAuthToken

func NewThirdPartyOAuthToken(
	id int64,
	createdAt time.Time,
	updatedAt time.Time,
	userId int64,
	active bool,
	typee ThirdPartyTokenType,
	token string,
	scope string,
) ThirdPartyOAuthToken

func (ThirdPartyOAuthToken) Active

func (token ThirdPartyOAuthToken) Active() bool

func (ThirdPartyOAuthToken) CreatedAt

func (token ThirdPartyOAuthToken) CreatedAt() time.Time

func (ThirdPartyOAuthToken) ID

func (token ThirdPartyOAuthToken) ID() int64

func (*ThirdPartyOAuthToken) Save

func (token *ThirdPartyOAuthToken) Save() (err error)

func (ThirdPartyOAuthToken) Scope

func (token ThirdPartyOAuthToken) Scope() string

func (ThirdPartyOAuthToken) SetID

func (token ThirdPartyOAuthToken) SetID(id int64)

func (ThirdPartyOAuthToken) Token

func (token ThirdPartyOAuthToken) Token() string

func (ThirdPartyOAuthToken) Type

func (ThirdPartyOAuthToken) UpdatedAt

func (token ThirdPartyOAuthToken) UpdatedAt() time.Time

func (ThirdPartyOAuthToken) UserID

func (token ThirdPartyOAuthToken) UserID() int64

type ThirdPartyTokenType

type ThirdPartyTokenType int8

value object

const (
	ThirdPartyTokenTypeGithubAccessToken ThirdPartyTokenType = 10*iota + 11
)

type User

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

func GetUserByGithubOAuth

func GetUserByGithubOAuth(code, state string) (User, error)

func GetUserBySessionToken

func GetUserBySessionToken(tokenType sessionTokenType, token string) (User, error)

func GetUserByUserName

func GetUserByUserName(userName string) (User, error)

func NewUser

func NewUser(
	id int64,
	createdAt time.Time,
	updatedAt time.Time,
	name string,
	nickname string,
	pwd password,
	email string,
	telephone string,
	avatar string,
	githubId int64,
) User

func RegisterUser

func RegisterUser(userName, nickname, pwd string) (User, error)

func (User) Avatar

func (user User) Avatar() string

func (User) CreatedAt

func (user User) CreatedAt() time.Time

func (User) Email

func (user User) Email() string

func (User) GithubId

func (user User) GithubId() int64

func (User) Id

func (user User) Id() int64

func (User) Name

func (user User) Name() string

func (User) Nickname

func (user User) Nickname() string

func (User) Password

func (user User) Password() password

func (*User) Session

func (user *User) Session() session

func (*User) SetID

func (user *User) SetID(id int64)

func (User) Telephone

func (user User) Telephone() string

func (User) UpdatedAt

func (user User) UpdatedAt() time.Time

type UserInvalidRefreshToken

type UserInvalidRefreshToken struct {
	ID        int64
	CreatedAt time.Time
	UpdatedAt time.Time

	UserID  int64
	TokenID string
}

entity

Jump to

Keyboard shortcuts

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