// LoginURL returns the URL to redirect the user to login with.
17400
func (m *callback) LoginURL(s connector.Scopes, callbackURL, state string) (string, error) {
	u, err := url.Parse(callbackURL)
	if err != nil {
		return "", fmt.Errorf("failed to parse callbackURL %q: %v", callbackURL, err)
	}
	u.Path = u.Path + m.pathSuffix
	v := u.Query()
	v.Set("state", state)
	u.RawQuery = v.Encode()
	return u.String(), nil
}
1246605
func (c *client) URL(key string, fallback *url.URL) *url.URL {
	if v := c.Getenv(key); v != "" {
		u, err := url.Parse(v)
		if err != nil {
			return fallback
		}

		return u
	}

	return fallback
}
812053
func (api *API) Login(user, password string) (auth string, err error) {
	params := map[string]string{"user": user, "password": password}
	response, err := api.CallWithError("user.login", params)
	if err != nil {
		return
	}

	auth = response.Result.(string)
	api.Auth = auth
	return
}
552094
func (sc *SetupContext) AccountURL() string {
	return sc.Host.ImporterBaseURL() + sc.ia.im.name + "/" + sc.AccountNode.PermanodeRef().String()
}
1059316
func (r *usersResource) login(request *restful.Request, response *restful.Response, user schema.User) (error, interface{}) {
	var req loginReq
	if err := request.ReadEntity(&req); err != nil {
		return err, nil
	}

	if err := r.authenticate(req); err != nil {
		return err, nil
	}

	// Create the JWT Token
	token := jwt.New(jwt.GetSigningMethod("RS256"))
	token.Claims["ID"] = req.Username
	token.Claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
	tokenStr, err := token.SignedString(r.privateKey)
	if err != nil {
		return err, nil
	}

	auth := schema.Auth{
		Username: req.Username,
		Token:    tokenStr,
	}

	return nil, &auth
}
57198
func URL(uri string) p.Plugin {
	return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
		u, err := url.Parse(normalize(uri))
		if err != nil {
			h.Error(ctx, err)
			return
		}

		ctx.Request.URL = u
		h.Next(ctx)
	})
}
454070
func (reader *PluginConfigReader) GetURL(key string, defaultValue string) *url.URL {
	value, err := reader.WithError.GetURL(key, defaultValue)
	reader.Errors.Push(err)
	return value
}
1357227
func (a *admin) login(req params.LoginRequest, loginVersion int) (params.LoginResult, error) {
	var fail params.LoginResult

	a.mu.Lock()
	defer a.mu.Unlock()
	if a.loggedIn {
		// This can only happen if Login is called concurrently.
		return fail, errAlreadyLoggedIn
	}

	authResult, err := a.authenticate(req)
	if err, ok := errors.Cause(err).(*common.DischargeRequiredError); ok {
		loginResult := params.LoginResult{
			DischargeRequired:       err.Macaroon,
			DischargeRequiredReason: err.Error(),
		}
		logger.Infof("login failed with discharge-required error: %v", err)
		return loginResult, nil
	}
	if err != nil {
		return fail, errors.Trace(err)
	}

	// Fetch the API server addresses from state.
	// If the login comes from a client, return all available addresses.
	// Otherwise return the addresses suitable for agent use.
	getHostPorts := a.root.state.APIHostPortsForAgents
	if k, _ := names.TagKind(req.AuthTag); k == names.UserTagKind {
		getHostPorts = a.root.state.APIHostPortsForClients
	}
	hostPorts, err := getHostPorts()
	if err != nil {
		return fail, errors.Trace(err)
	}

	// apiRoot is the API root exposed to the client after login.
	var apiRoot rpc.Root = newAPIRoot(
		a.root.state,
		a.root.shared,
		a.srv.facades,
		a.root.resources,
		a.root,
	)
	apiRoot, err = restrictAPIRoot(
		a.srv,
		apiRoot,
		a.root.model,
		*authResult,
	)
	if err != nil {
		return fail, errors.Trace(err)
	}

	var facadeFilters []facadeFilterFunc
	var modelTag string
	if authResult.anonymousLogin {
		facadeFilters = append(facadeFilters, IsAnonymousFacade)
	}
	if authResult.controllerOnlyLogin {
		facadeFilters = append(facadeFilters, IsControllerFacade)
	} else {
		facadeFilters = append(facadeFilters, IsModelFacade)
		modelTag = a.root.model.Tag().String()
	}

	auditConfig := a.srv.GetAuditConfig()
	auditRecorder, err := a.getAuditRecorder(req, authResult, auditConfig)
	if err != nil {
		return fail, errors.Trace(err)
	}

	recorderFactory := observer.NewRecorderFactory(
		a.apiObserver, auditRecorder, auditConfig.CaptureAPIArgs,
	)
	a.root.rpcConn.ServeRoot(apiRoot, recorderFactory, serverError)
	return params.LoginResult{
		Servers:       params.FromNetworkHostsPorts(hostPorts),
		ControllerTag: a.root.model.ControllerTag().String(),
		UserInfo:      authResult.userInfo,
		ServerVersion: jujuversion.Current.String(),
		PublicDNSName: a.srv.publicDNSName(),
		ModelTag:      modelTag,
		Facades:       filterFacades(a.srv.facades, facadeFilters...),
	}, 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
}
957049
func login(ctx *cli.Context) {
	if len(ctx.Args()) != 0 {
		errExit(ctx, exitHelp, "More arguments than required", true)
	}

	// this check is redundant as ContivClient's Login() function also verifies
	// that the URL is https.  this is just for a better UX.  prompting for username
	// and password and then showing an error immediately is kind of lame.
	if !strings.HasPrefix(baseURL(ctx), "https://") {
		fmt.Println("login requires a https auth_proxy URL")
		errExit(ctx, exitInvalid, "", true)
	}

	username, password := readLoginCredentials(ctx)

	// perform the login
	resp, body, err := getClient(ctx).Login(username, password)
	if err != nil {
		errExit(ctx, exitIO, err.Error(), false)
	}

	// check the status code to see if the login succeeded
	if resp.StatusCode != http.StatusOK {
		fmt.Print("Login failed: ")

		if resp.StatusCode == http.StatusUnauthorized {
			fmt.Println("Bad username or password.")
		} else {
			fmt.Printf("unexpected response code (%d)\n\n", resp.StatusCode)
			os.Stderr.Write(body)
		}

		// exit without any additional output
		errExit(ctx, exitInvalid, "", false)
	}

	fmt.Println("Login succeeded.")

	// for now, we will just write out the raw JSON response as the netctl config file since it
	// contains nothing but the token.  we can extend the config file format in the future.
	writeConfig(ctx, body)
}
949966
func (m *AuthMethod) LogoutURL(c context.Context, dest string) (string, error) {
	if m.SessionStore == nil {
		return "", ErrNotConfigured
	}
	return makeRedirectURL(logoutURL, dest)
}
17686
func (c *Client) Login(ctx context.Context, user *url.Userinfo) error {
	req := internal.URL(c, internal.SessionPath).Request(http.MethodPost)

	if user != nil {
		if password, ok := user.Password(); ok {
			req.SetBasicAuth(user.Username(), password)
		}
	}

	return c.Do(ctx, req, 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
}
821485
func AuthURL(authURL string) Option {
	return func(c *CredHub) error {
		if authURL != "" {
			var err error
			c.authURL, err = url.Parse(authURL)
			return err
		}
		return nil
	}
}
10594
func (u *UserLDAPMapping) GetURL() string {
	if u == nil || u.URL == nil {
		return ""
	}
	return *u.URL
}
183737
func (r *Response) GetRedirectUrl() (string, error) {
	if r.Type != REDIRECT {
		return "", errors.New("Not a redirect response")
	}

	u, err := url.Parse(r.URL)
	if err != nil {
		return "", err
	}

	var q url.Values
	if r.RedirectInFragment {
		// start with empty set for fragment
		q = url.Values{}
	} else {
		// add parameters to existing query
		q = u.Query()
	}

	// add parameters
	for n, v := range r.Output {
		q.Set(n, fmt.Sprint(v))
	}

	// https://tools.ietf.org/html/rfc6749#section-4.2.2
	// Fragment should be encoded as application/x-www-form-urlencoded (%-escaped, spaces are represented as '+')
	// The stdlib URL#String() doesn't make that easy to accomplish, so build this ourselves
	if r.RedirectInFragment {
		u.Fragment = ""
		redirectURI := u.String() + "#" + q.Encode()
		return redirectURI, nil
	}

	// Otherwise, update the query and encode normally
	u.RawQuery = q.Encode()
	u.Fragment = ""
	return u.String(), nil
}
869049
func LogoutURL(c context.Context, dest string) (string, error) {
	if s := GetState(c); s != nil {
		return s.Authenticator().LogoutURL(c, dest)
	}
	return "", ErrNotConfigured
}