userapi

package module
v0.0.0-...-5f4f256 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2019 License: MIT Imports: 51 Imported by: 0

README

go-authentication

An Authentication Service Written In Go

Documentation

Index

Constants

View Source
const (
	SessionTime = 7 * 24 * time.Hour // 1 week
	TokenTime   = 10 * time.Minute   // 10 minutes
)

Variables

View Source
var (
	ErrNoKey error = errors.New("api key missing")

	// Key is the key used in JWT authentication
	Key = []byte("secret")
)
View Source
var ErrInvalidRecaptcha = errors.New("Invalid recaptcha response")

Functions

func CheckEmailExists

func CheckEmailExists(email string) bool

func CheckPhoneExists

func CheckPhoneExists(phone string) bool

func CheckUsernameExists

func CheckUsernameExists(username string) bool

func NewFacebookService

func NewFacebookService(log *logrus.Logger, jwt *auth.JWTSecurity, session *SessionService) facebook.Service

NewFacebookController creates a facebook controller.

func NewGoogleService

func NewGoogleService(log *logrus.Logger, jwt *auth.JWTSecurity, session *SessionService) google.Service

NewGoogleService creates a google controller.

func NewInstagramService

func NewInstagramService(log *logrus.Logger, jwt *auth.JWTSecurity, session *SessionService) instagram.Service

NewInstagramService creates a instagram controller.

func NewLinkedinService

func NewLinkedinService(log *logrus.Logger, jwt *auth.JWTSecurity, session *SessionService) linkedin.Service

NewLinkedinService creates a linkedin controller.

func NewMonitoring

func NewMonitoring(logger *logrus.Logger) monitoring.Service

NewMonitoring returns the monitoring service implementation.

func NewPasswordAuthService

func NewPasswordAuthService(log *logrus.Logger, jwt *auth.JWTSecurity, session *SessionService) passwordauth.Service

NewPasswordAuthService creates a password-auth controller.

func NewTwitterService

func NewTwitterService(log *logrus.Logger, jwt *auth.JWTSecurity, session *SessionService) twitter.Service

NewTwitterService creates a twitter controller.

func NewUsersService

func NewUsersService(log *logrus.Logger, jwt *auth.JWTSecurity, session *SessionService) user.Service

NewUsersService creates a user controller.

Types

type FacebookRegisterMedia

type FacebookRegisterMedia struct {
	OauthKey, FirstName, LastName, Email string
	TimeCreated                          time.Time
}

type FacebookService

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

FacebookController implements the facebook resource.

func (*FacebookService) APIKeyAuth

func (s *FacebookService) APIKeyAuth(ctx context.Context, key string, scheme *security.APIKeyScheme) (context.Context, error)

APIKeyAuth implements the authorization logic for service "facebook" for the "api_key" security scheme.

func (*FacebookService) AttachToAccount

func (s *FacebookService) AttachToAccount(ctx context.Context, p *facebook.AttachToAccountPayload) (res string, err error)

Attaches a Facebook account to an existing user account, returns the URL the browser should be redirected to

func (*FacebookService) DetachFromAccount

func (s *FacebookService) DetachFromAccount(ctx context.Context, p *facebook.DetachFromAccountPayload) (err error)

Detaches a Facebook account from an existing user account.

func (*FacebookService) FacebookRegister

func (s *FacebookService) FacebookRegister(ctx context.Context, grm *FacebookRegisterMedia, OauthKey string) (*facebook.UserMedia, error)

func (*FacebookService) JWTAuth

func (s *FacebookService) JWTAuth(ctx context.Context, token string, scheme *security.JWTScheme) (context.Context, error)

JWTAuth implements the authorization logic for service "facebook" for the "jwt" security scheme.

func (*FacebookService) Receive

The endpoint that Facebook redirects the browser to after the user has authenticated

func (*FacebookService) RegisterURL

func (s *FacebookService) RegisterURL(ctx context.Context, p *facebook.RegisterURLPayload) (res string, err error)

Gets the URL the front-end should redirect the browser to in order to be authenticated with Facebook, and then register

type FacebookUser

type FacebookUser struct {
	ID        string `json:"id"`
	Email     string `json:"email"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
}

func (*FacebookUser) GetID

func (g *FacebookUser) GetID() string

type GeoIP

type GeoIP struct {
	// The right side is the name of the JSON variable
	Ip          string  `json:"ip"`
	CountryCode string  `json:"country_code"`
	CountryName string  `json:"country_name"`
	RegionCode  string  `json:"region_code"`
	RegionName  string  `json:"region_name"`
	City        string  `json:"city"`
	Zipcode     string  `json:"zipcode"`
	Lat         float32 `json:"latitude"`
	Lon         float32 `json:"longitude"`
	MetroCode   int     `json:"metro_code"`
	AreaCode    int     `json:"area_code"`
}

type GoogleRegisterMedia

type GoogleRegisterMedia struct {
	OauthKey, FirstName, LastName, Email string
	TimeCreated                          time.Time
}

type GoogleService

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

GoogleService implements the google resource.

func (*GoogleService) APIKeyAuth

func (s *GoogleService) APIKeyAuth(ctx context.Context, key string, scheme *security.APIKeyScheme) (context.Context, error)

APIKeyAuth implements the authorization logic for service "google" for the "api_key" security scheme.

func (*GoogleService) AttachToAccount

func (s *GoogleService) AttachToAccount(ctx context.Context, p *google.AttachToAccountPayload) (res string, err error)

Attaches a Google account to an existing user account, returns the URL the browser should be redirected to

func (*GoogleService) DetachFromAccount

func (s *GoogleService) DetachFromAccount(ctx context.Context, p *google.DetachFromAccountPayload) (err error)

Detaches a Google account from an existing user account.

func (*GoogleService) GoogleRegister

func (s *GoogleService) GoogleRegister(ctx context.Context, gr *GoogleRegisterMedia, OauthKey string) (*google.UserMedia, error)

func (*GoogleService) JWTAuth

func (s *GoogleService) JWTAuth(ctx context.Context, token string, scheme *security.JWTScheme) (context.Context, error)

JWTAuth implements the authorization logic for service "google" for the "jwt" security scheme.

func (*GoogleService) Receive

func (s *GoogleService) Receive(ctx context.Context, p *google.ReceivePayload) (res *google.UserMedia, err error)

The endpoint that Google redirects the browser to after the user has authenticated

func (*GoogleService) RegisterURL

func (s *GoogleService) RegisterURL(ctx context.Context, p *google.RegisterURLPayload) (res string, err error)

Gets the URL the front-end should redirect the browser to in order to be authenticated with Google, and then register

type GoogleUser

type GoogleUser struct {
	ID        *string `json:"id"`
	FirstName string  `json:"given_name"`
	LastName  string  `json:"family_name"`
	Email     *string `json:"email"`
}

func (*GoogleUser) GetEmail

func (g *GoogleUser) GetEmail() string

type InstagramRegisterMedia

type InstagramRegisterMedia struct {
	AccessToken *string `json:"access_token"`
	// Instagram user
	User *InstagramUserMedia `json:"user"`
	// A merge token for merging into an account
	OauthKey      *string `json:"oauth_key"`
	Authorization *string `json:"authorization"`
	XSession      *string `json:"x_session"`
}

type InstagramService

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

InstagramService implements the instagram resource.

func (*InstagramService) APIKeyAuth

func (s *InstagramService) APIKeyAuth(ctx context.Context, key string, scheme *security.APIKeyScheme) (context.Context, error)

APIKeyAuth implements the authorization logic for service "instagram" for the "api_key" security scheme.

func (*InstagramService) AttachToAccount

func (s *InstagramService) AttachToAccount(ctx context.Context, p *instagram.AttachToAccountPayload) (res string, err error)

Attaches a Instagram account to an existing user account, returns the URL the browser should be redirected to

func (*InstagramService) DetachFromAccount

func (s *InstagramService) DetachFromAccount(ctx context.Context, p *instagram.DetachFromAccountPayload) (err error)

Detaches a Instagram account from an existing user account.

func (*InstagramService) InstagramRegister

func (*InstagramService) JWTAuth

func (s *InstagramService) JWTAuth(ctx context.Context, token string, scheme *security.JWTScheme) (context.Context, error)

JWTAuth implements the authorization logic for service "instagram" for the "jwt" security scheme.

func (*InstagramService) Receive

The endpoint that Instagram redirects the browser to after the user has authenticated

func (*InstagramService) RegisterURL

func (s *InstagramService) RegisterURL(ctx context.Context, p *instagram.RegisterURLPayload) (res string, err error)

Gets the URL the front-end should redirect the browser to in order to be authenticated with Instagram, and then register

type InstagramUser

type InstagramUser struct {
	AccessToken string `json:"access_token"`
	User        struct {
		ID             string `json:"id"`
		Username       string `json:"username"`
		FullName       string `json:"full_name"`
		ProfilePicture string `json:"profile_picture"`
	} `json:"user"`
}

func (*InstagramUser) GetID

func (g *InstagramUser) GetID() string

type InstagramUserMedia

type InstagramUserMedia struct {
	// Instagram id of connected account
	ID *string `json:"id"`
	// Instagram username of connected account
	Username *string `json:"username"`
	// Full name of the user
	FullName *string `json:"full_name"`
	// Instagram DP of the user
	ProfilePicture *string `json:"profile_picture"`
}

type LinkedinRegisterMedia

type LinkedinRegisterMedia struct {
	OauthKey    string `json:"id" bson:"id"`
	FirstName   string `json:"firstName" bson:"firstName"`
	LastName    string `json:"lastName" bson:"lastName"`
	Email       string `json:"emailAddress" bson:"emailAddress"`
	TimeCreated time.Time
}

type LinkedinService

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

LinkedinService implements the linkedin resource.

func (*LinkedinService) APIKeyAuth

func (s *LinkedinService) APIKeyAuth(ctx context.Context, key string, scheme *security.APIKeyScheme) (context.Context, error)

APIKeyAuth implements the authorization logic for service "linkedin" for the "api_key" security scheme.

func (*LinkedinService) AttachToAccount

func (s *LinkedinService) AttachToAccount(ctx context.Context, p *linkedin.AttachToAccountPayload) (res string, err error)

Attaches a Linkedin account to an existing user account, returns the URL the browser should be redirected to

func (*LinkedinService) DetachFromAccount

func (s *LinkedinService) DetachFromAccount(ctx context.Context, p *linkedin.DetachFromAccountPayload) (err error)

Detaches a Linkedin account from an existing user account.

func (*LinkedinService) JWTAuth

func (s *LinkedinService) JWTAuth(ctx context.Context, token string, scheme *security.JWTScheme) (context.Context, error)

JWTAuth implements the authorization logic for service "linkedin" for the "jwt" security scheme.

func (*LinkedinService) LinkedinRegister

func (s *LinkedinService) LinkedinRegister(ctx context.Context, grm *LinkedinRegisterMedia, OauthKey string) (*linkedin.UserMedia, error)

func (*LinkedinService) Receive

The endpoint that Linkedin redirects the browser to after the user has authenticated

func (*LinkedinService) RegisterURL

func (s *LinkedinService) RegisterURL(ctx context.Context, p *linkedin.RegisterURLPayload) (res string, err error)

Gets the URL the front-end should redirect the browser to in order to be authenticated with Linkedin, and then register

type LinkedinUser

type LinkedinUser struct {
	ID        string `json:"id" bson:"id"`
	FirstName string `json:"firstName" bson:"firstName"`
	LastName  string `json:"lastName" bson:"lastName"`
	Email     string `json:"emailAddress" bson:"emailAddress"`
}

type PasswordAuthService

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

PasswordAuthService implements the password-auth resource.

func (*PasswordAuthService) APIKeyAuth

func (s *PasswordAuthService) APIKeyAuth(ctx context.Context, key string, scheme *security.APIKeyScheme) (context.Context, error)

APIKeyAuth implements the authorization logic for service "password-auth" for the "api_key" security scheme.

func (*PasswordAuthService) ChangePassword

func (s *PasswordAuthService) ChangePassword(ctx context.Context, p *passwordauth.ChangePasswordParams) (err error)

Changes the user's current password to a new one, also adds a password to the account if there is none

func (*PasswordAuthService) CheckEmailAvailable

func (s *PasswordAuthService) CheckEmailAvailable(ctx context.Context, p *passwordauth.CheckEmailAvailablePayload) (res bool, err error)

func (*PasswordAuthService) CheckPhoneAvailable

func (s *PasswordAuthService) CheckPhoneAvailable(ctx context.Context, p *passwordauth.CheckPhoneAvailablePayload) (res bool, err error)

func (*PasswordAuthService) CheckUsernameAvailable

func (s *PasswordAuthService) CheckUsernameAvailable(ctx context.Context, p *passwordauth.CheckUsernameAvailablePayload) (res bool, err error)

func (*PasswordAuthService) ConfirmReset

Confirms that a reset has been completed and changes the password to the new one passed in

func (*PasswordAuthService) JWTAuth

func (s *PasswordAuthService) JWTAuth(ctx context.Context, token string, scheme *security.JWTScheme) (context.Context, error)

JWTAuth implements the authorization logic for service "password-auth" for the "jwt" security scheme.

func (*PasswordAuthService) Login

Login a user using an email and password

func (*PasswordAuthService) Register

Register a new user with an email and password

func (*PasswordAuthService) Remove

Removes using a password as a login method

func (*PasswordAuthService) Reset

Send an email to user to get a password reset, responds with no content even if the email is not on any user account

type SessionService

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

SessionService implements the session resource.

func NewSessionService

func NewSessionService(log *logrus.Logger, jwt *auth.JWTSecurity) *SessionService

NewSessionService creates a session controller.

func (*SessionService) APIKeyAuth

func (s *SessionService) APIKeyAuth(ctx context.Context, key string, scheme *security.APIKeyScheme) (context.Context, error)

APIKeyAuth implements the authorization logic for service "session" for the "api_key" security scheme.

func (*SessionService) CleanLoginToken

func (s *SessionService) CleanLoginToken(ctx context.Context, p *session.CleanLoginTokenPayload) (err error)

Cleans old login tokens from the database

func (*SessionService) CleanMergeToken

func (s *SessionService) CleanMergeToken(ctx context.Context, p *session.CleanMergeTokenPayload) (err error)

Cleans old account merge tokens from the database

func (*SessionService) CleanSessions

func (s *SessionService) CleanSessions(ctx context.Context, p *session.CleanSessionsPayload) (err error)

Deletes all the sessions that have expired

func (*SessionService) GetSessions

func (s *SessionService) GetSessions(ctx context.Context, p *session.GetSessionsPayload) (res *session.AllSessions, err error)

Gets all of the sessions that are associated with the currently logged in user

func (*SessionService) JWTAuth

func (s *SessionService) JWTAuth(ctx context.Context, token string, scheme *security.JWTScheme) (context.Context, error)

JWTAuth implements the authorization logic for service "session" for the "jwt" security scheme.

func (*SessionService) Logout

func (s *SessionService) Logout(ctx context.Context, p *session.LogoutPayload) (err error)

Takes a user's auth token, and logs-out the session associated with it

func (*SessionService) LogoutOther

func (s *SessionService) LogoutOther(ctx context.Context, p *session.LogoutOtherPayload) (err error)

Logout all sessions for the current user except their current session

func (*SessionService) LogoutSpecific

func (s *SessionService) LogoutSpecific(ctx context.Context, p *session.LogoutSpecificPayload) (err error)

Logout of a specific session

func (*SessionService) RedeemToken

Redeems a login token for credentials

func (*SessionService) Refresh

Take a user's session token and refresh it, also returns a new authentication token

type TwitterRegisterMedia

type TwitterRegisterMedia struct {
	OauthKey, FirstName, LastName, Email string
	TimeCreated                          time.Time
}

type TwitterService

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

TwitterService implements the twitter resource.

func (*TwitterService) APIKeyAuth

func (s *TwitterService) APIKeyAuth(ctx context.Context, key string, scheme *security.APIKeyScheme) (context.Context, error)

APIKeyAuth implements the authorization logic for service "twitter" for the "api_key" security scheme.

func (*TwitterService) AttachToAccount

func (s *TwitterService) AttachToAccount(ctx context.Context, p *twitter.AttachToAccountPayload) (res string, err error)

Attaches a Twitter account to an existing user account, returns the URL the browser should be redirected to

func (*TwitterService) DetachFromAccount

func (s *TwitterService) DetachFromAccount(ctx context.Context, p *twitter.DetachFromAccountPayload) (err error)

Detaches a Twitter account from an existing user account.

func (*TwitterService) JWTAuth

func (s *TwitterService) JWTAuth(ctx context.Context, token string, scheme *security.JWTScheme) (context.Context, error)

JWTAuth implements the authorization logic for service "twitter" for the "jwt" security scheme.

func (*TwitterService) Receive

func (s *TwitterService) Receive(ctx context.Context, p *twitter.ReceivePayload) (res *twitter.UserMedia, err error)

The endpoint that Twitter redirects the browser to after the user has authenticated

func (*TwitterService) RegisterURL

func (s *TwitterService) RegisterURL(ctx context.Context, p *twitter.RegisterURLPayload) (res string, err error)

Gets the URL the front-end should redirect the browser to in order to be authenticated with Twitter, and then register

func (*TwitterService) TwitterRegister

func (s *TwitterService) TwitterRegister(ctx context.Context, grm *TwitterRegisterMedia, OauthKey string) (*twitter.UserMedia, error)

type UsersService

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

UsersService implements the user resource.

func (*UsersService) APIKeyAuth

func (s *UsersService) APIKeyAuth(ctx context.Context, key string, scheme *security.APIKeyScheme) (context.Context, error)

APIKeyAuth implements the authorization logic for service "user" for the "api_key" security scheme.

func (*UsersService) Deactivate

func (s *UsersService) Deactivate(ctx context.Context, p *user.DeactivatePayload) (retErr error)

Disable a user's account

func (*UsersService) GetAuths

func (s *UsersService) GetAuths(ctx context.Context, p *user.GetAuthsPayload) (res *user.AuthStatusMedia, retErr error)

Returns whether Oauth is attached or not

func (*UsersService) GetUser

func (s *UsersService) GetUser(ctx context.Context, p *user.GetUserPayload) (res *user.UserMedia, retErr error)

func (*UsersService) JWTAuth

func (s *UsersService) JWTAuth(ctx context.Context, token string, scheme *security.JWTScheme) (context.Context, error)

JWTAuth implements the authorization logic for service "user" for the "jwt" security scheme.

func (*UsersService) ResendVerifyEmail

func (s *UsersService) ResendVerifyEmail(ctx context.Context, p *user.ResendVerifyEmailPayload) (err error)

Resends a verify email for the current user, also invalidates the link on the previously send email verification

func (*UsersService) UpdateUser

func (s *UsersService) UpdateUser(ctx context.Context, p *user.UserUpdateParams) (res *user.UserMedia, retErr error)

Update a user

func (*UsersService) ValidateEmail

func (s *UsersService) ValidateEmail(ctx context.Context, p *user.ValidateEmailPayload) (err error)

Validates an email address, designed to be called by users directly in their browser

Jump to

Keyboard shortcuts

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