Versions in this module Expand all Collapse all v1 v1.0.1 Nov 1, 2017 v1.0.0 Nov 1, 2017 Changes in this version + const AccessTokenHint + const RefreshTokenHint + var ErrAccessTokenExpired = errors.New("Access token expired") + var ErrAccessTokenNotFound = errors.New("Access token not found") + var ErrAuthorizationCodeExpired = errors.New("Authorization code expired") + var ErrAuthorizationCodeNotFound = errors.New("Authorization code not found") + var ErrCannotSetEmptyUsername = errors.New("Cannot set empty username") + var ErrClientIDTaken = errors.New("Client ID taken") + var ErrClientNotFound = errors.New("Client not found") + var ErrInvalidClientIDOrSecret = errors.New("Invalid client ID or secret") + var ErrInvalidClientSecret = errors.New("Invalid client secret") + var ErrInvalidGrantType = errors.New("Invalid grant type") + var ErrInvalidRedirectURI = errors.New("Invalid redirect URI") + var ErrInvalidScope = errors.New("Invalid scope") + var ErrInvalidUserPassword = errors.New("Invalid user password") + var ErrInvalidUsernameOrPassword = errors.New("Invalid username or password") + var ErrPasswordTooShort = fmt.Errorf("Password must be at least %d characters long", MinPasswordLength) + var ErrRefreshTokenExpired = errors.New("Refresh token expired") + var ErrRefreshTokenNotFound = errors.New("Refresh token not found") + var ErrRequestedScopeCannotBeGreater = errors.New("Requested scope cannot be greater") + var ErrRoleNotFound = errors.New("Role not found") + var ErrTokenHintInvalid = errors.New("Invalid token hint") + var ErrTokenMissing = errors.New("Token missing") + var ErrUserNotFound = errors.New("User not found") + var ErrUserPasswordNotSet = errors.New("User password not set") + var ErrUsernameTaken = errors.New("Username taken") + var MinPasswordLength = 6 + type AccessTokenResponse struct + AccessToken string + ExpiresIn int + RefreshToken string + Scope string + TokenType string + UserID string + func NewAccessTokenResponse(accessToken *models.OauthAccessToken, refreshToken *models.OauthRefreshToken, ...) (*AccessTokenResponse, error) + type IntrospectResponse struct + Active bool + ClientID string + ExpiresAt int + Scope string + TokenType string + Username string + type Service struct + func NewService(cnf *config.Config, db *gorm.DB) *Service + func (s *Service) AuthClient(clientID, secret string) (*models.OauthClient, error) + func (s *Service) AuthUser(username, password string) (*models.OauthUser, error) + func (s *Service) Authenticate(token string) (*models.OauthAccessToken, error) + func (s *Service) ClearUserTokens(userSession *session.UserSession) + func (s *Service) ClientExists(clientID string) bool + func (s *Service) Close() + func (s *Service) CreateClient(clientID, secret, redirectURI string) (*models.OauthClient, error) + func (s *Service) CreateClientTx(tx *gorm.DB, clientID, secret, redirectURI string) (*models.OauthClient, error) + func (s *Service) CreateUser(roleID, username, password string) (*models.OauthUser, error) + func (s *Service) CreateUserTx(tx *gorm.DB, roleID, username, password string) (*models.OauthUser, error) + func (s *Service) FindClientByClientID(clientID string) (*models.OauthClient, error) + func (s *Service) FindRoleByID(id string) (*models.OauthRole, error) + func (s *Service) FindUserByUsername(username string) (*models.OauthUser, error) + func (s *Service) GetConfig() *config.Config + func (s *Service) GetDefaultScope() string + func (s *Service) GetOrCreateRefreshToken(client *models.OauthClient, user *models.OauthUser, expiresIn int, ...) (*models.OauthRefreshToken, error) + func (s *Service) GetRoutes() []routes.Route + func (s *Service) GetScope(requestedScope string) (string, error) + func (s *Service) GetValidRefreshToken(token string, client *models.OauthClient) (*models.OauthRefreshToken, error) + func (s *Service) GrantAccessToken(client *models.OauthClient, user *models.OauthUser, expiresIn int, ...) (*models.OauthAccessToken, error) + func (s *Service) GrantAuthorizationCode(client *models.OauthClient, user *models.OauthUser, expiresIn int, ...) (*models.OauthAuthorizationCode, error) + func (s *Service) IsRoleAllowed(role string) bool + func (s *Service) Login(client *models.OauthClient, user *models.OauthUser, scope string) (*models.OauthAccessToken, *models.OauthRefreshToken, error) + func (s *Service) NewIntrospectResponseFromAccessToken(accessToken *models.OauthAccessToken) (*IntrospectResponse, error) + func (s *Service) NewIntrospectResponseFromRefreshToken(refreshToken *models.OauthRefreshToken) (*IntrospectResponse, error) + func (s *Service) RegisterRoutes(router *mux.Router, prefix string) + func (s *Service) RestrictToRoles(allowedRoles ...string) + func (s *Service) ScopeExists(requestedScope string) bool + func (s *Service) SetPassword(user *models.OauthUser, password string) error + func (s *Service) SetPasswordTx(tx *gorm.DB, user *models.OauthUser, password string) error + func (s *Service) UpdateUsername(user *models.OauthUser, username string) error + func (s *Service) UpdateUsernameTx(tx *gorm.DB, user *models.OauthUser, username string) error + func (s *Service) UserExists(username string) bool + type ServiceInterface interface + AuthClient func(clientID, secret string) (*models.OauthClient, error) + AuthUser func(username, thePassword string) (*models.OauthUser, error) + Authenticate func(token string) (*models.OauthAccessToken, error) + ClearUserTokens func(userSession *session.UserSession) + ClientExists func(clientID string) bool + Close func() + CreateClient func(clientID, secret, redirectURI string) (*models.OauthClient, error) + CreateClientTx func(tx *gorm.DB, clientID, secret, redirectURI string) (*models.OauthClient, error) + CreateUser func(roleID, username, password string) (*models.OauthUser, error) + CreateUserTx func(tx *gorm.DB, roleID, username, password string) (*models.OauthUser, error) + FindClientByClientID func(clientID string) (*models.OauthClient, error) + FindRoleByID func(id string) (*models.OauthRole, error) + FindUserByUsername func(username string) (*models.OauthUser, error) + GetConfig func() *config.Config + GetDefaultScope func() string + GetOrCreateRefreshToken func(client *models.OauthClient, user *models.OauthUser, expiresIn int, ...) (*models.OauthRefreshToken, error) + GetRoutes func() []routes.Route + GetScope func(requestedScope string) (string, error) + GetValidRefreshToken func(token string, client *models.OauthClient) (*models.OauthRefreshToken, error) + GrantAccessToken func(client *models.OauthClient, user *models.OauthUser, expiresIn int, ...) (*models.OauthAccessToken, error) + GrantAuthorizationCode func(client *models.OauthClient, user *models.OauthUser, expiresIn int, ...) (*models.OauthAuthorizationCode, error) + IsRoleAllowed func(role string) bool + Login func(client *models.OauthClient, user *models.OauthUser, scope string) (*models.OauthAccessToken, *models.OauthRefreshToken, error) + NewIntrospectResponseFromAccessToken func(accessToken *models.OauthAccessToken) (*IntrospectResponse, error) + NewIntrospectResponseFromRefreshToken func(refreshToken *models.OauthRefreshToken) (*IntrospectResponse, error) + RegisterRoutes func(router *mux.Router, prefix string) + RestrictToRoles func(allowedRoles ...string) + ScopeExists func(requestedScope string) bool + SetPassword func(user *models.OauthUser, password string) error + SetPasswordTx func(tx *gorm.DB, user *models.OauthUser, password string) error + UpdateUsername func(user *models.OauthUser, username string) error + UpdateUsernameTx func(db *gorm.DB, user *models.OauthUser, username string) error + UserExists func(username string) bool