// Auth implements QueryCtx Auth method.
326043
func (tc *TiDBContext) Auth(user *auth.UserIdentity, auth []byte, salt []byte) bool {
	return tc.session.Auth(user, auth, salt)
}
191387
func (s *S3Storage) Auth() (auth aws.Auth, err error) {
	return aws.GetAuth(s.AccessKeyId, s.SecretAccessKey)
}
984092
func (srv *server) authReq(req, ID []byte, provider auth.Provider, target string) ([]byte, error) {
	url := srv.getURL("auth" + target)

	token, err := provider.Token(req)
	if err != nil {
		return nil, errors.Wrap(errors.APIClientError, errors.AuthenticationFailure, err)
	}

	aReq := &auth.AuthenticatedRequest{
		Timestamp:     time.Now().Unix(),
		RemoteAddress: ID,
		Token:         token,
		Request:       req,
	}

	jsonData, err := json.Marshal(aReq)
	if err != nil {
		return nil, errors.Wrap(errors.APIClientError, errors.JSONError, err)
	}

	response, err := srv.post(url, jsonData)
	if err != nil {
		return nil, err
	}

	result, ok := response.Result.(map[string]interface{})
	if !ok {
		return nil, errors.New(errors.APIClientError, errors.JSONError)
	}

	cert, ok := result["certificate"].(string)
	if !ok {
		return nil, errors.New(errors.APIClientError, errors.JSONError)
	}

	return []byte(cert), nil
}
732648
func (ba *BasicAuth) Authenticate(r *http.Request) bool {
	user, pass, ok := r.BasicAuth()
	if !ok {
		return false
	}

	ba.RLock()
	defer ba.RUnlock()

	if passwords, exists := ba.creds[user]; exists {
		for _, password := range passwords {
			if password == pass {
				return true
			}
		}
	}

	return false
}
510758
func (auup *AuthUserUserPermission) AuthPermission(db XODB) (*AuthPermission, error) {
	return AuthPermissionByID(db, auup.PermissionID)
}
200569
func (asl *AuthServerLdap) AuthMethod(user string) (string, error) {
	return asl.Method, nil
}
752763
func (c *Client) authURL(path string) string {
	return authURL2 + c.appID + path
}
1322735
func (context *Context) Authentication(request *restful.Request) (interface{}, error) {
	return nil, errors.New("Auth is not implemented")
}
775017
func (c *RPCClient) auth(authKey string) error {
	header := requestHeader{
		Command: authCommand,
		Seq:     c.getSeq(),
	}
	req := authRequest{
		AuthKey: authKey,
	}
	return c.genericRPC(&header, &req, nil)
}
678165
func (ctxt *authContext) authenticator(serverHost string) authenticator {
	return authenticator{ctxt: ctxt, serverHost: serverHost}
}
362621
func (context *APIContext) Authentication(request *restful.Request) (interface{}, error) {
	//FIXME: implement this properly

	t := request.QueryParameter("accesstoken")
	if len(t) == 0 {
		t = request.HeaderParameter("authorization")
		if strings.Index(t, " ") > 0 {
			t = strings.TrimSpace(strings.Split(t, " ")[1])
		}
	}

	return nil, nil // context.GetUserByAccessToken(t)
}
818164
func (c *Client) SupportAuth(mech string) (bool, error) {
	return c.Support("AUTH=" + mech)
}
451168
func (ctx *Context) QueryAuthCode(authCode string) (*AuthBaseInfo, error) {
	cat, err := ctx.GetComponentAccessToken()
	if err != nil {
		return nil, err
	}

	req := map[string]string{
		"component_appid":    ctx.AppID,
		"authorization_code": authCode,
	}
	uri := fmt.Sprintf(queryAuthURL, cat)
	body, err := util.PostJSON(uri, req)
	if err != nil {
		return nil, err
	}

	var ret struct {
		Info *AuthBaseInfo `json:"authorization_info"`
	}

	if err := json.Unmarshal(body, &ret); err != nil {
		return nil, err
	}

	return ret.Info, nil
}
223432
func (aug *AuthUserGroup) AuthGroup(db XODB) (*AuthGroup, error) {
	return AuthGroupByID(db, aug.GroupID)
}
1042064
func (c *Clientset) Oauth() oauthinternalversion.OauthInterface {
	return &fakeoauthinternalversion.FakeOauth{Fake: &c.Fake}
}
543652
func (sc *serverConn) authPlain() error {
	m := &msg{
		header: header{
			Op: opAuthStart,
		},

		key: "PLAIN",
		val: fmt.Sprintf("\x00%s\x00%s", sc.username, sc.password),
	}

	return sc.sendRecv(m)
}
985115
func (m *AuthMethod) Authenticate(c context.Context, r *http.Request) (*auth.User, error) {
	if m.SessionStore == nil {
		return nil, ErrNotConfigured
	}

	// Grab session ID from the cookie.
	sid, err := decodeSessionCookie(c, r)
	if err != nil {
		return nil, err
	}
	if sid == "" {
		return nil, nil
	}

	// Grab session (with user information) from the store.
	session, err := m.SessionStore.GetSession(c, sid)
	if err != nil {
		return nil, err
	}
	if session == nil {
		(logging.Fields{"sid": sid}).Warningf(c, "The session cookie references unknown session")
		return nil, nil
	}
	(logging.Fields{
		"sid":   sid,
		"email": session.User.Email,
	}).Debugf(c, "Fetched the session")
	return &session.User, nil
}