Documentation ¶
Overview ¶
Package server provides a basic in-memory OAuth2 authentication server intended for testing purposes. The implementation may be used to as a reference or template to build a custom OAuth2 authentication server.
Index ¶
- func MustHash(clear string) []byte
- func SameHash(hash []byte, clear string) bool
- type Config
- type Credential
- type Entity
- type Server
- func (s *Server) AddAccessToken(token *Credential)
- func (s *Server) AddAuthorizationCode(code *Credential)
- func (s *Server) AddClient(client *Entity)
- func (s *Server) AddRefreshToken(token *Credential)
- func (s *Server) AddUser(user *Entity)
- func (s *Server) Authorize(w http.ResponseWriter, r *http.Request, required oauth2.Scope) bool
- func (s *Server) Config() Config
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { Secret []byte KeyLength int AllowedScope oauth2.Scope AccessTokenLifespan time.Duration RefreshTokenLifespan time.Duration AuthorizationCodeLifespan time.Duration }
Config is used to configure a server.
func (Config) MustGenerate ¶
MustGenerate will generate a new token.
type Credential ¶
type Credential struct { ClientID string Username string Signature string ExpiresAt time.Time Scope oauth2.Scope RedirectURI string Code string Used bool }
Credential represents an access token, refresh token or authorization code.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server implements a basic in-memory OAuth2 authentication server intended for testing purposes.
func (*Server) AddAccessToken ¶
func (s *Server) AddAccessToken(token *Credential)
AddAccessToken will add the provided access token.
func (*Server) AddAuthorizationCode ¶
func (s *Server) AddAuthorizationCode(code *Credential)
AddAuthorizationCode will add the provided authorization code.
func (*Server) AddRefreshToken ¶
func (s *Server) AddRefreshToken(token *Credential)
AddRefreshToken will add the provided refresh token.
Click to show internal directories.
Click to hide internal directories.