code: func (r *Request) authenticate() *Error {
  	// Trust the Kite if we have initiated the connection.  Following casts
  	// means, session is opened by the client.
  	if _, ok := r.Client.session.(*sockjsclient.WebsocketSession); ok {
  		return nil
  	}
  
  	if _, ok := r.Client.session.(*sockjsclient.XHRSession); ok {
  		return nil
  	}
  
  	if r.Auth == nil {
  		return &Error{
  			Type:    "authenticationError",
  			Message: "No authentication information is provided",
  		}
  	}
  
  	// Select authenticator function.
  	f := r.LocalKite.Authenticators[r.Auth.Type]
  	if f == nil {
  		return &Error{
  			Type:    "authenticationError",
  			Message: fmt.Sprintf("Unknown authentication type: %s", r.Auth.Type),
  		}
  	}
  
  	// Call authenticator function. It sets the Request.Username field.
  	err := f(r)
  	if err != nil {
  		return &Error{
  			Type:    "authenticationError",
  			Message: fmt.Sprintf("%s: %s", r.Auth.Type, err),
  		}
  	}
  
  	// Replace username of the remote Kite with the username that client send
  	// us. This prevents a Kite to impersonate someone else's Kite.
  	r.Client.SetUsername(r.Username)
  	return nil
  }
docs: // authenticate tries to authenticate the user by selecting appropriate
  // authenticator function.