Example #1
0
// ParseRequestHeader check if need access token.
func (c RootController) ParseRequestHeader(p parameters.RequestParameter) error {
	req := c.GetContext().Request()

	// API
	apiToken := req.Header("Token")
	if len(apiToken) <= 0 {
		return fmt.Errorf("Not found the ApiToken.")
	}
	if apiToken != config.GetAPI().Token {
		return fmt.Errorf("Not matched the ApiToken.")
	}

	// AccessToken
	if !p.NeedAccessToken() {
		return nil
	}
	auth := req.Header("Authorization")
	if len(auth) <= 0 || !strings.HasPrefix(auth, "Bearer ") {
		return fmt.Errorf("Not found the Authorization.")
	}
	p.SetAccessToken(strings.TrimPrefix(auth, "Bearer "))
	return nil
}