// onLogin logs in with remote proxy and gets signed certificates
423735
func onLogin(cf *CLIConf) {
	var (
		err error
		tc  *client.TeleportClient
		key *client.Key
	)

	if cf.IdentityFileIn != "" {
		utils.FatalError(trace.BadParameter("-i flag cannot be used here"))
	}

	if cf.IdentityFormat != client.IdentityFormatOpenSSH && cf.IdentityFormat != client.IdentityFormatFile {
		utils.FatalError(trace.BadParameter("invalid identity format: %s", cf.IdentityFormat))
	}

	// Get the status of the active profile ~/.tsh/profile as well as the status
	// of any other proxies the user is logged into.
	profile, profiles, err := client.Status("", cf.Proxy)
	if err != nil {
		if !trace.IsNotFound(err) {
			utils.FatalError(err)
		}
	}

	// make the teleport client and retrieve the certificate from the proxy:
	tc, err = makeClient(cf, true)
	if err != nil {
		utils.FatalError(err)
	}

	// client is already logged in and profile is not expired
	if profile != nil && !profile.IsExpired(clockwork.NewRealClock()) {
		switch {
		// in case if nothing is specified, print current status
		case cf.Proxy == "" && cf.SiteName == "":
			printProfiles(profile, profiles)
			return
		// in case if parameters match, print current status
		case host(cf.Proxy) == host(profile.ProxyURL.Host) && cf.SiteName == profile.Cluster:
			printProfiles(profile, profiles)
			return
		// proxy is unspecified or the same as the currently provided proxy,
		// but cluster is specified, treat this as selecting a new cluster
		// for the same proxy
		case (cf.Proxy == "" || host(cf.Proxy) == host(profile.ProxyURL.Host)) && cf.SiteName != "":
			tc.SaveProfile("", "")
			if err := kubeclient.UpdateKubeconfig(tc); err != nil {
				utils.FatalError(err)
			}
			onStatus(cf)
			return
		// otherwise just passthrough to standard login
		default:
		}
	}

	if cf.Username == "" {
		cf.Username = tc.Username
	}

	// -i flag specified? save the retreived cert into an identity file
	makeIdentityFile := (cf.IdentityFileOut != "")
	activateKey := !makeIdentityFile

	key, err = tc.Login(cf.Context, activateKey)
	if err != nil {
		utils.FatalError(err)
	}

	if makeIdentityFile {
		if err := setupNoninteractiveClient(tc, key); err != nil {
			utils.FatalError(err)
		}
		authorities, err := tc.GetTrustedCA(cf.Context, key.ClusterName)
		if err != nil {
			utils.FatalError(err)
		}
		client.MakeIdentityFile(cf.IdentityFileOut, key, cf.IdentityFormat, authorities)
		fmt.Printf("\nThe certificate has been written to %s\n", cf.IdentityFileOut)
		return
	}

	// If the proxy is advertising that it supports Kubernetes, update kubeconfig.
	if tc.KubeProxyAddr != "" {
		if err := kubeclient.UpdateKubeconfig(tc); err != nil {
			utils.FatalError(err)
		}
	}

	// Regular login without -i flag.
	tc.SaveProfile(key.ProxyHost, "")

	// Print status to show information of the logged in user. Update the
	// command line flag (used to print status) for the proxy to make sure any
	// advertised settings are picked up.
	webProxyHost, _ := tc.WebProxyHostPort()
	cf.Proxy = webProxyHost
	onStatus(cf)
}
1317135
func (d *DNSProvider) login() error {
	queryArgs := map[string]string{
		"username": d.config.UserName,
		"password": d.config.Password,
	}

	resp, err := d.sendRequest(http.MethodGet, "login", nil, queryArgs)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	authBytes, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return fmt.Errorf("bluecat: %v", err)
	}
	authResp := string(authBytes)

	if strings.Contains(authResp, "Authentication Error") {
		msg := strings.Trim(authResp, "\"")
		return fmt.Errorf("bluecat: request failed: %s", msg)
	}

	// Upon success, API responds with "Session Token-> BAMAuthToken: dQfuRMTUxNjc3MjcyNDg1ODppcGFybXM= <- for User : username"
	d.token = regexp.MustCompile("BAMAuthToken: [^ ]+").FindString(authResp)
	return nil
}
1133348
func (s *AuthenticationService) Login(p *LoginParams) (*LoginResponse, error) {
	resp, err := s.cs.newRequest("login", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r LoginResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
318114
func (o *Organization) GetLogin() string {
	if o == nil || o.Login == nil {
		return ""
	}
	return *o.Login
}
255924
func (c *ServerConn) Login(user, password string) error {
	code, message, err := c.cmd(-1, "USER %s", user)
	if err != nil {
		return err
	}

	switch code {
	case StatusLoggedIn:
	case StatusUserOK:
		_, _, err = c.cmd(StatusLoggedIn, "PASS %s", password)
		if err != nil {
			return err
		}
	default:
		return errors.New(message)
	}

	// Switch to binary mode
	if _, _, err = c.cmd(StatusCommandOK, "TYPE I"); err != nil {
		return err
	}

	// Switch to UTF-8
	err = c.setUTF8()

	return err
}
236418
func (client *AMIClient) Login(username, password string) error {
	response, err := client.Action("Login", Params{"Username": username, "Secret": password})
	if err != nil {
		return err
	}

	if (*response).Status == "Error" {
		return errors.New((*response).Params["Message"])
	}

	client.amiUser = username
	client.amiPass = password
	return nil
}
96129
func (t *TokensClient) PostLogin(ctx context.Context, creds apitypes.LoginCredential) (
	*base64.Value, *envelope.Token, error) {
	respBody := loginTokenResponse{}

	var body interface{}
	switch creds.Type() {
	case apitypes.UserSession:
		body = &loginTokenUserRequest{
			Type:  primitive.LoginToken,
			Email: creds.Identifier(),
		}
	case apitypes.MachineSession:
		body = &loginTokenMachineRequest{
			Type:    primitive.LoginToken,
			TokenID: creds.Identifier(),
		}
	}

	err := tokenRoundTrip(ctx, t.client, "", "POST", "/tokens", nil, body, &respBody)
	if err != nil {
		return nil, nil, err
	}

	return respBody.Salt, respBody.Token, nil
}
1033364
func (c *Client) Login(user, passwd string) error {
	_, err := c.ExecCmd(NewCmd("login").WithArgs(
		NewArg("client_login_name", user),
		NewArg("client_login_password", passwd)),
	)
	return err
}
40625
func (bridge *Bridge) Login(username string) error {
	uri := fmt.Sprintf("/api/%s", username)
	_, _, err := bridge.Get(uri)
	if err != nil {
		return err
	}
	bridge.Username = username
	return nil
}
57908
func (c *TokensClient) CreateLogin(ctx context.Context, loginTokenRequest *LoginTokenRequest) (*LoginTokenResponse, error) {
	p := "/tokens/login"

	req, err := c.backend.NewRequest(http.MethodPost, p, nil, loginTokenRequest)
	if err != nil {
		return nil, err
	}

	var resp LoginTokenResponse
	_, err = c.backend.Do(ctx, req, &resp, func(code int) error {
		return &Error{}
	})
	if err != nil {
		return nil, err
	}

	return &resp, nil
}
494826
func MultiLogin(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, loginPage)
}
474148
func (s *Server) onConn(conn *clientConn) {
	ctx := logutil.WithConnID(context.Background(), conn.connectionID)
	if err := conn.handshake(ctx); err != nil {
		// Some keep alive services will send request to TiDB and disconnect immediately.
		// So we only record metrics.
		metrics.HandShakeErrorCounter.Inc()
		err = conn.Close()
		terror.Log(errors.Trace(err))
		return
	}

	logutil.Logger(ctx).Info("new connection", zap.String("remoteAddr", conn.bufReadConn.RemoteAddr().String()))

	defer func() {
		logutil.Logger(ctx).Info("connection closed")
	}()
	s.rwlock.Lock()
	s.clients[conn.connectionID] = conn
	connections := len(s.clients)
	s.rwlock.Unlock()
	metrics.ConnGauge.Set(float64(connections))

	err := plugin.ForeachPlugin(plugin.Audit, func(p *plugin.Plugin) error {
		authPlugin := plugin.DeclareAuditManifest(p.Manifest)
		if authPlugin.OnConnectionEvent != nil {
			connInfo := conn.connectInfo()
			return authPlugin.OnConnectionEvent(context.Background(), conn.ctx.GetSessionVars().User, plugin.Connected, connInfo)
		}
		return nil
	})
	if err != nil {
		return
	}

	connectedTime := time.Now()
	conn.Run(ctx)

	err = plugin.ForeachPlugin(plugin.Audit, func(p *plugin.Plugin) error {
		authPlugin := plugin.DeclareAuditManifest(p.Manifest)
		if authPlugin.OnConnectionEvent != nil {
			connInfo := conn.connectInfo()
			connInfo.Duration = float64(time.Since(connectedTime)) / float64(time.Millisecond)
			err := authPlugin.OnConnectionEvent(context.Background(), conn.ctx.GetSessionVars().User, plugin.Disconnect, connInfo)
			if err != nil {
				logutil.Logger(context.Background()).Warn("do connection event failed", zap.String("plugin", authPlugin.Name), zap.Error(err))
			}
		}
		return nil
	})
	if err != nil {
		return
	}
}
564113
func (m *MockCommonAPIClient) RegistryLogin(ctx context.Context, auth types.AuthConfig) (registry.AuthenticateOKBody, error) {
	ret := m.ctrl.Call(m, "RegistryLogin", ctx, auth)
	ret0, _ := ret[0].(registry.AuthenticateOKBody)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
544658
func (api *Api) Login(username, password string) (err error) {
	defer func() { appendCaller(err, "lastfm.Login") }()

	var result AuthGetMobileSession
	args := P{"username": username, "password": password}
	if err = callPostWithoutSession("auth.getmobilesession", api.params, args, &result, P{
		"plain": []string{"username", "password"},
	}); err != nil {
		return
	}
	api.params.sk = result.Key
	//api.creds.username = result.Name
	return
}
1344726
func (c *Client) Login(username, password string) error {
	var req = LoginBlock{
		Username:     username,
		Password:     password,
		CustomerName: c.CustomerName}

	var resp LoginResponse

	err := c.Do("POST", "Session", req, &resp)
	if err != nil {
		return err
	}

	c.Token = resp.Data.Token
	return nil
}
981085
func Login(ctx ttnlog.Interface, code string) (*oauth2.Token, error) {
	config := getOAuth()
	token, err := config.Exchange(code)
	if err != nil {
		return nil, err
	}
	saveToken(ctx, token)
	return token, nil
}
1015092
func (h *Handler) hostCredentials(w http.ResponseWriter, r *http.Request, p httprouter.Params) (interface{}, error) {
	var req auth.RegisterUsingTokenRequest
	if err := httplib.ReadJSON(r, &req); err != nil {
		return nil, trace.Wrap(err)
	}

	authClient := h.cfg.ProxyClient
	packedKeys, err := authClient.RegisterUsingToken(req)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	return packedKeys, nil
}