Versions in this module Expand all Collapse all v0 v0.0.0 Aug 29, 2016 Changes in this version + const AccessTokenHint + const RefreshTokenHint + const TokenType + 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 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 + func AccessTokenPreload(db *gorm.DB) *gorm.DB + func AccessTokenPreloadWithPrefix(db *gorm.DB, prefix string) *gorm.DB + func AuthorizationCodePreload(db *gorm.DB) *gorm.DB + func AuthorizationCodePreloadWithPrefix(db *gorm.DB, prefix string) *gorm.DB + func MigrateAll(db *gorm.DB) error + func RefreshTokenPreload(db *gorm.DB) *gorm.DB + func RefreshTokenPreloadWithPrefix(db *gorm.DB, prefix string) *gorm.DB + func RegisterRoutes(router *mux.Router, service ServiceInterface) + type AccessToken struct + Client *Client + ClientID sql.NullInt64 + ExpiresAt time.Time + Scope string + Token string + User *User + UserID sql.NullInt64 + func NewAccessToken(client *Client, user *User, expiresIn int, scope string) *AccessToken + func (at *AccessToken) TableName() string + type AccessTokenResponse struct + AccessToken string + ExpiresIn int + RefreshToken string + Scope string + TokenType string + UserID uint + type AuthorizationCode struct + Client *Client + ClientID sql.NullInt64 + Code string + ExpiresAt time.Time + RedirectURI sql.NullString + Scope string + User *User + UserID sql.NullInt64 + func NewAuthorizationCode(client *Client, user *User, expiresIn int, redirectURI, scope string) *AuthorizationCode + func (ac *AuthorizationCode) TableName() string + type Client struct + Key string + RedirectURI sql.NullString + Secret string + func (c *Client) TableName() string + type IntrospectResponse struct + Active bool + ClientID string + ExpiresAt int + Scope string + TokenType string + Username string + type RefreshToken struct + Client *Client + ClientID sql.NullInt64 + ExpiresAt time.Time + Scope string + Token string + User *User + UserID sql.NullInt64 + func NewRefreshToken(client *Client, user *User, expiresIn int, scope string) *RefreshToken + func (rt *RefreshToken) TableName() string + type Scope struct + Description sql.NullString + IsDefault bool + Scope string + func (s *Scope) TableName() string + type Service struct + func NewService(cnf *config.Config, db *gorm.DB) *Service + func (s *Service) AuthClient(clientID, secret string) (*Client, error) + func (s *Service) AuthUser(username, password string) (*User, error) + func (s *Service) Authenticate(token string) (*AccessToken, error) + func (s *Service) ClientExists(clientID string) bool + func (s *Service) CreateClient(clientID, secret, redirectURI string) (*Client, error) + func (s *Service) CreateClientTx(tx *gorm.DB, clientID, secret, redirectURI string) (*Client, error) + func (s *Service) CreateUser(username, password string) (*User, error) + func (s *Service) CreateUserTx(tx *gorm.DB, username, password string) (*User, error) + func (s *Service) FindClientByClientID(clientID string) (*Client, error) + func (s *Service) FindUserByUsername(username string) (*User, error) + func (s *Service) GetDefaultScope() string + func (s *Service) GetOrCreateRefreshToken(client *Client, user *User, expiresIn int, scope string) (*RefreshToken, error) + func (s *Service) GetScope(requestedScope string) (string, error) + func (s *Service) GetValidRefreshToken(token string, client *Client) (*RefreshToken, error) + func (s *Service) GrantAccessToken(client *Client, user *User, expiresIn int, scope string) (*AccessToken, error) + func (s *Service) GrantAuthorizationCode(client *Client, user *User, expiresIn int, redirectURI, scope string) (*AuthorizationCode, error) + func (s *Service) IntrospectHandler(w http.ResponseWriter, r *http.Request) + func (s *Service) IntrospectResponseAccessToken(at *AccessToken) *IntrospectResponse + func (s *Service) IntrospectResponseRefreshToken(rt *RefreshToken) *IntrospectResponse + func (s *Service) Login(client *Client, user *User, scope string) (*AccessToken, *RefreshToken, error) + func (s *Service) ScopeExists(requestedScope string) bool + func (s *Service) SetPassword(user *User, password string) error + func (s *Service) SetPasswordTx(tx *gorm.DB, user *User, password string) error + func (s *Service) TokensHandler(w http.ResponseWriter, r *http.Request) + func (s *Service) UpdateUsername(user *User, username string) error + func (s *Service) UpdateUsernameTx(tx *gorm.DB, user *User, username string) error + func (s *Service) UserExists(username string) bool + type ServiceInterface interface + AuthClient func(clientID, secret string) (*Client, error) + AuthUser func(username, thePassword string) (*User, error) + Authenticate func(token string) (*AccessToken, error) + ClientExists func(clientID string) bool + CreateClient func(clientID, secret, redirectURI string) (*Client, error) + CreateClientTx func(tx *gorm.DB, clientID, secret, redirectURI string) (*Client, error) + CreateUser func(username, password string) (*User, error) + CreateUserTx func(tx *gorm.DB, username, password string) (*User, error) + FindClientByClientID func(clientID string) (*Client, error) + FindUserByUsername func(username string) (*User, error) + GetOrCreateRefreshToken func(client *Client, user *User, expiresIn int, scope string) (*RefreshToken, error) + GetScope func(requestedScope string) (string, error) + GetValidRefreshToken func(token string, client *Client) (*RefreshToken, error) + GrantAccessToken func(client *Client, user *User, expiresIn int, scope string) (*AccessToken, error) + GrantAuthorizationCode func(client *Client, user *User, expiresIn int, redirectURI, scope string) (*AuthorizationCode, error) + IntrospectHandler func(w http.ResponseWriter, r *http.Request) + Login func(client *Client, user *User, scope string) (*AccessToken, *RefreshToken, error) + SetPassword func(user *User, password string) error + SetPasswordTx func(tx *gorm.DB, user *User, password string) error + TokensHandler func(w http.ResponseWriter, r *http.Request) + UpdateUsername func(user *User, username string) error + UpdateUsernameTx func(db *gorm.DB, user *User, username string) error + UserExists func(username string) bool + type User struct + MetaUserID uint + Password sql.NullString + Username string + func (u *User) TableName() string