service

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2018 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAccess = errors.New("access denied")

ErrNoAccess means user doesn't have necessary permissions for a resource

Functions

func GetUserID

func GetUserID(ctx context.Context) (int, error)

GetUserID gets the user ID set by the JWT middleware in the Context

func NewLogger

func NewLogger(env string) *logrus.Logger

NewLogger returns a logrus Logger

Types

type ACL

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

ACL allows to manage permissions for user role

func NewACL

func NewACL(usersRepo *repository.Users, role model.Role) *ACL

NewACL creates new ACL service

func (*ACL) Middleware

func (s *ACL) Middleware(next http.Handler) http.Handler

Middleware provides middleware which allows requests only for user only with selected role

type GithubUser added in v0.0.1

type GithubUser struct {
	ID        int        `json:"id"`
	Login     string     `json:"login"`
	Username  string     `json:"name"`
	AvatarURL string     `json:"avatar_url"`
	Role      model.Role `json:"-"`
}

GithubUser represents the user response returned by the GitHub auth.

type JWT

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

JWT service abstracts JWT implementation

func NewJWT

func NewJWT(signingKey string) *JWT

NewJWT return new JWT service

func (*JWT) MakeToken

func (j *JWT) MakeToken(user *model.User) (string, error)

MakeToken generates token string for a user

func (*JWT) Middleware

func (j *JWT) Middleware(next http.Handler) http.Handler

Middleware return http.Handler which validates token and set user id in context

type JWTConfig

type JWTConfig struct {
	SigningKey string `envconfig:"SIGNING_KEY" required:"true"`
}

JWTConfig defines enviroment variables for JWT

type OAuth

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

OAuth service abstracts OAuth implementation

func NewOAuth

func NewOAuth(clientID, clientSecret, restrictAccess, restrictRequesterAccess string) *OAuth

NewOAuth return new OAuth service

func (*OAuth) GetUser

func (o *OAuth) GetUser(ctx context.Context, code string) (*GithubUser, error)

GetUser gets user from provider and return user model

func (*OAuth) MakeAuthURL

func (o *OAuth) MakeAuthURL(w http.ResponseWriter, r *http.Request) string

MakeAuthURL returns string for redirect to provider

func (*OAuth) ValidateState

func (o *OAuth) ValidateState(r *http.Request, state string) error

ValidateState protects the user from CSRF attacks

type OAuthConfig

type OAuthConfig struct {
	ClientID                string `envconfig:"CLIENT_ID" required:"true"`
	ClientSecret            string `envconfig:"CLIENT_SECRET" required:"true"`
	RestrictAccess          string `envconfig:"RESTRICT_ACCESS"`
	RestrictRequesterAccess string `envconfig:"RESTRICT_REQUESTER_ACCESS"`
}

OAuthConfig defines enviroment variables for OAuth

Jump to

Keyboard shortcuts

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