Documentation
¶
Index ¶
- Variables
- type Config
- type Manager
- func (m *Manager) IsOrgExists(ctx context.Context, org string) (exists bool, err error)
- func (m *Manager) IsUserExists(ctx context.Context, email string) (exists bool, err error)
- func (m *Manager) Login(ctx context.Context, email string, password string) (token *Token, err error)
- func (m *Manager) Logout(ctx context.Context, token string) (err error)
- func (m *Manager) RegisterOrg(ctx context.Context, org Organization) (err error)
- func (m *Manager) RegisterOrgWithAdmin(ctx context.Context, org Organization, admin User) (err error)
- func (m *Manager) RegisterUser(ctx context.Context, user User) (err error)
- func (m *Manager) SetUserOrg(ctx context.Context, email, org string) error
- func (m *Manager) Verify(ctx context.Context, tokenStr string) (claims *TokenClaims, err error)
- type Organization
- type Provider
- type Token
- type TokenClaims
- type User
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadParams = errors.New("bad parameters") ErrInternalError = errors.New("internal error") ErrNotFound = errors.New("not found") ErrStoreError = errors.New("internal store error") ErrOrgExists = errors.New("org already exists") ErrUserExists = errors.New("user already token") ErrInvalidToken = errors.New("invalid token") ErrTokenExpired = errors.New("token expired") )
Exported errors.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
Manager manages the authentication.
func (*Manager) IsOrgExists ¶
IsOrgExists returns if the org exists.
func (*Manager) IsUserExists ¶
IsUserExists returns if the user exists.
func (*Manager) Login ¶
func (m *Manager) Login(ctx context.Context, email string, password string) ( token *Token, err error)
Login verify the user's email, password and returns the access token.
func (*Manager) RegisterOrg ¶
func (m *Manager) RegisterOrg(ctx context.Context, org Organization) ( err error)
RegisterOrg creates the org if org doesn't exist and admin holds no other org.
func (*Manager) RegisterOrgWithAdmin ¶
func (m *Manager) RegisterOrgWithAdmin( ctx context.Context, org Organization, admin User) (err error)
RegisterOrgWithAdmin creates the org and the admin user.
func (*Manager) RegisterUser ¶
RegisterUser creates the user, ensuring the user does not exist and the org does exist if user.Organization is not empty.
func (*Manager) SetUserOrg ¶
SetUserOrg sets the org of user with email.
type Organization ¶
Organization defines the org model.
type Provider ¶
type Provider interface { fmt.Stringer // users GetUser(ctx context.Context, email string) (User, error) GetUsers(ctx context.Context) ([]string, error) SetUser(ctx context.Context, user User) error DeleteUser(ctx context.Context, email string) error // organization GetOrg(ctx context.Context, name string) (Organization, error) GetOrgUsers(ctx context.Context, name string) ([]string, error) SetOrg(ctx context.Context, org Organization) error DeleteOrg(ctx context.Context, name string) error // tokens GetToken(ctx context.Context, token string) (Token, error) SetToken(ctx context.Context, token Token) error DeleteToken(ctx context.Context, token string) error }
Provider defines the auth provider interface.
type TokenClaims ¶
type TokenClaims struct { Email string `json:"email"` Org string `json:"org"` IssuedAt int64 `json:"issued_at"` ExpiredAt int64 `json:"expired_at"` }
TokenClaims defines the token claims struct.
type User ¶
User defines the user model.
func (*User) SetPassword ¶
SetPassword sets password hash with bcrypt.
func (*User) VerifyPassword ¶
VerifyPassword verifies password with bcrypt.