code: func (a *authenticator) getTokenStringFromRequest(req *http.Request) (result string, errCode int, err error) {
  	// Try to read header, validate it if exists.
  	authHeader := req.Header.Get(AuthHeaderKey)
  	if authHeader != "" {
  		bearerToken := strings.Split(authHeader, " ")
  		if len(bearerToken) != 2 {
  			return "", http.StatusUnauthorized, fmt.Errorf("401 Unauthorized: invalid authorization token")
  		}
  		// Parse token header constant
  		if bearerToken[0] != "Bearer" {
  			return "", http.StatusUnauthorized, fmt.Errorf("401 Unauthorized: invalid authorization header")
  		}
  		return bearerToken[1], 0, nil
  	}
  	a.log.Debugf("Authentication header not found (err: %v)", err)
  
  	// Otherwise read cookie
  	cookie, err := req.Cookie(cookieName)
  	if err == nil && cookie != nil {
  		return cookie.Value, 0, nil
  	}
  	a.log.Debugf("Authentication cookie not found (err: %v)", err)
  
  	return "", http.StatusUnauthorized, fmt.Errorf("401 Unauthorized: authorization required")
  }
docs: // Read raw token from request.