Documentation
¶
Index ¶
- type Config
- func (a *Config) AddAuth(r *http.Request) error
- func (a *Config) Authenticate(h http.Handler) http.HandlerFunc
- func (a *Config) CalcMD5(r *http.Request) (string, error)
- func (a *Config) CanonicalString(m string, u *url.URL, h http.Header) string
- func (a *Config) CheckDates(reqDate string) (bool, error)
- func (a *Config) CheckHash(r *http.Request, publicHash, privateKey string) (bool, error)
- func (a *Config) GetSignature(r *http.Request, apiKey string) (string, error)
- func (a *Config) ParseAuthHeader(h string) (string, string, error)
- func (a *Config) PrivateHash(id string) (string, string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
RootURL string
PrivateKey string
PublicID string
SignHeaders []string
AllowedPaths map[string]string
DB *sql.DB
}
Main object
func (*Config) AddAuth ¶
AddAuth calculates authorization information and adds it to Authorization-header
func (*Config) Authenticate ¶
func (a *Config) Authenticate(h http.Handler) http.HandlerFunc
Authenticate is a HTTP middleware that will check if request has proper authorization header
func (*Config) CanonicalString ¶
Constuct canonical string of the request
StringToSign = HTTP-Verb + "\n" +
Content-MD5 + "\n" + Content-Type + "\n" + Date + "\n" + CanonicalizedResource;
Example ¶
POST MDMyNjFlYWJkYTc4ZGEwNTc4NWZiZjYyZWI2YjUzYjU= application/json Wed, 21 Jan 2015 07:01:02 GMT /api/v1/groups/modes
func (*Config) CheckDates ¶
CheckDates will check if request's date is within 10 minutes of current datetime
func (*Config) CheckHash ¶
CheckHash will compare public hash against private hash and returns true if they are a match
func (*Config) GetSignature ¶
Construct request's signature
Signature = Base64( HMAC-SHA256( PrivateAPIKey, UTF-8-Encoding-Of( StringToSign ) ) );
func (*Config) ParseAuthHeader ¶
ParseAuthHeader will return public id and signature in base64 decoded format