Documentation ¶
Index ¶
- Variables
- func MigrateAll(db *gorm.DB) error
- type AccessToken
- type AuthorizationCode
- type Client
- type RefreshToken
- type Scope
- type Service
- func (s *Service) AuthClient(clientID, secret string) (*Client, error)
- func (s *Service) AuthUser(username, thePassword string) (*User, error)
- func (s *Service) Authenticate(token string) error
- func (s *Service) CreateClient(clientID, secret, redirectURI string) (*Client, error)
- func (s *Service) CreateUser(username, thePassword string) (*User, error)
- func (s *Service) FindClientByClientID(clientID string) (*Client, error)
- func (s *Service) FindUserByUsername(username string) (*User, error)
- func (s *Service) GetOrCreateRefreshToken(client *Client, user *User, 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, scope string) (*AccessToken, error)
- func (s *Service) GrantAuthorizationCode(client *Client, user *User, redirectURI, scope string) (*AuthorizationCode, error)
- func (s *Service) UserExists(username string) bool
- type User
Constants ¶
This section is empty.
Variables ¶
var Routes = []routes.Route{ routes.Route{ Name: "oauth_tokens", Methods: []string{"POST"}, Pattern: "/tokens", HandlerFunc: handleTokens, }, }
Routes for the oauth service
Functions ¶
Types ¶
type AccessToken ¶
type AccessToken struct { ID int64 `gorm:"primary_key"` Token string `sql:"type:varchar(40);unique;not null"` ExpiresAt time.Time `sql:"not null"` Scope string `sql:"type:varchar(200);not null"` ClientID sql.NullInt64 `sql:"index;not null"` UserID sql.NullInt64 `sql:"index"` Client *Client User *User }
AccessToken ...
type AuthorizationCode ¶
type AuthorizationCode struct { ID int64 `gorm:"primary_key"` Code string `sql:"type:varchar(40);unique;not null"` RedirectURI sql.NullString `sql:"type:varchar(200)"` ExpiresAt time.Time `sql:"not null"` Scope string `sql:"type:varchar(200);not null"` ClientID sql.NullInt64 `sql:"index;not null"` UserID sql.NullInt64 `sql:"index;not null"` Client *Client User *User }
AuthorizationCode ...
type Client ¶
type Client struct { ID int64 `gorm:"primary_key"` ClientID string `sql:"type:varchar(254);unique;not null"` Secret string `sql:"type:varchar(60);not null"` RedirectURI sql.NullString `sql:"type:varchar(200)"` }
Client ...
type RefreshToken ¶
type RefreshToken struct { ID int64 `gorm:"primary_key"` Token string `sql:"type:varchar(40);unique;not null"` ExpiresAt time.Time `sql:"not null"` Scope string `sql:"type:varchar(200);not null"` ClientID sql.NullInt64 `sql:"index;not null"` UserID sql.NullInt64 `sql:"index"` Client *Client User *User }
RefreshToken ...
type Scope ¶
type Scope struct { ID int64 `gorm:"primary_key"` Scope string `sql:"type:varchar(200);unique;not null"` Description sql.NullString IsDefault bool `sql:"default:false"` }
Scope ...
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service struct keeps config and db objects to avoid passing them around
func NewService ¶
NewService starts a new Service instance
func (*Service) AuthClient ¶
AuthClient authenticates client
func (*Service) Authenticate ¶
Authenticate checks the access token is valid
func (*Service) CreateClient ¶
CreateClient saves a new client to database
func (*Service) CreateUser ¶
CreateUser saves a new user to database
func (*Service) FindClientByClientID ¶
FindClientByClientID looks up a client by client ID
func (*Service) FindUserByUsername ¶
FindUserByUsername looks up a user by username
func (*Service) GetOrCreateRefreshToken ¶
func (s *Service) GetOrCreateRefreshToken(client *Client, user *User, scope string) (*RefreshToken, error)
GetOrCreateRefreshToken retrieves an existing refresh token, if expired, the token gets deleted and new refresh token is created
func (*Service) GetScope ¶
GetScope takes a requested scope and, if it's empty, returns the default scope, if not empty, it validates the requested scope
func (*Service) GetValidRefreshToken ¶
func (s *Service) GetValidRefreshToken(token string, client *Client) (*RefreshToken, error)
GetValidRefreshToken returns a valid non expired refresh token
func (*Service) GrantAccessToken ¶
GrantAccessToken deletes old tokens and grants a new access token
func (*Service) GrantAuthorizationCode ¶
func (s *Service) GrantAuthorizationCode(client *Client, user *User, redirectURI, scope string) (*AuthorizationCode, error)
GrantAuthorizationCode grants a new authorization code
func (*Service) UserExists ¶
UserExists returns true if user exists