Documentation ¶
Overview ¶
Package tastypie contains a Django Tastypie (https://django-tastypie.readthedocs.io/) models and functions, that helps to integrate Go project with existing Django Tastypie project.
Index ¶
Examples ¶
Constants ¶
const APIKeyAuthorizationHeader = "Authorization"
APIKeyAuthorizationHeader is a key in HTTP header where is stored authorization key
const (
TypeAPIKey = 1 << iota // APIKey Authentication
)
Authentication types
Variables ¶
var ( ErrorInvalidAuthenticationType = errors.New("Invalid authentication type") ErrorInvalidAuthorizationHeader = errors.New("Invalid Authorization header") ErrorInvalidCredentials = errors.New("Invalid credentials") ErrorUserIsInactive = errors.New("User is inactive") )
Predefined errors
Functions ¶
This section is empty.
Types ¶
type APIAccess ¶
type APIAccess struct { TableName string `sql:"tastypie_apiaccess"` ID uint16 Identifier string `sql:"type:varchar(255),notnull"` URL string `sql:"type:varchar(255),notnull,default:''"` RequestMethod string `sql:"type:varchar(10),notnull,default:''"` Accessed int64 `sql:",notnull"` }
APIAccess represents tastypie_apiaccess table
func (*APIAccess) BeforeInsert ¶
BeforeInsert hook update "Accessed" field
func (*APIAccess) BeforeUpdate ¶
BeforeUpdate hook update "Accessed" field
type APIKey ¶
type APIKey struct { TableName string `sql:"tastypie_apikey"` ID uint16 UserID uint16 `sql:",notnull" pg:",fk:auth.User"` User *auth.User Key string `sql:"type:varchar(128),notnull,default:''"` Created time.Time `sql:",notnull"` }
APIKey represents tastypie_apikey table
type APIKeyAuthentication ¶
APIKeyAuthentication represents authentication based on API Key
func (APIKeyAuthentication) ExtractCredentials ¶
ExtractCredentials returns username and tastypie apikey extracted from request
Example ¶
r, _ := http.NewRequest(http.MethodGet, "http://www.example.com/", nil) r.Header.Set("Authorization", "ApiKey admin:qaz123") authentication := APIKeyAuthentication{} username, key, _ := authentication.ExtractCredentials(r) fmt.Println(username, key)
Output: admin qaz123
func (APIKeyAuthentication) IsAuthenticated ¶
IsAuthenticated checks if user is authenticated and return it
type Authentication ¶
type Authentication interface { // Extract credentials from request ExtractCredentials(r *http.Request) (string, string, error) // Checks if user is authenticated and return it IsAuthenticated(r *http.Request) (*auth.User, error) }
Authentication is a interface to various authentication backends
func GetAuthentication ¶
func GetAuthentication(authenticationType int, db *pg.DB) (Authentication, error)
GetAuthentication gets Authentication object based on type and initiates it