func (s *AuthServer) CreateSignupToken(user services.User) (string, error) {
	if err := user.Check(); err != nil {
		return "", trace.Wrap(err)
	}
	// make sure that connectors actually exist
	for _, id := range user.GetIdentities() {
		if err := id.Check(); err != nil {
			return "", trace.Wrap(err)
		}
		if _, err := s.GetOIDCConnector(id.ConnectorID, false); err != nil {
			return "", trace.Wrap(err)
		}
	}
	// check existing
	_, err := s.GetPasswordHash(user.GetName())
	if err == nil {
		return "", trace.BadParameter("user '%v' already exists", user)
	}

	token, err := utils.CryptoRandomHex(TokenLenBytes)
	if err != nil {
		return "", trace.Wrap(err)
	}

	otp, err := hotp.GenerateHOTP(defaults.HOTPTokenDigits, false)
	if err != nil {
		log.Errorf("[AUTH API] failed to generate HOTP: %v", err)
		return "", trace.Wrap(err)
	}
	otpQR, err := otp.QR("Teleport: " + user.GetName() + "@" + s.AuthServiceName)
	if err != nil {
		return "", trace.Wrap(err)
	}

	otpMarshalled, err := hotp.Marshal(otp)
	if err != nil {
		return "", trace.Wrap(err)
	}

	otpFirstValues := make([]string, defaults.HOTPFirstTokensRange)
	for i := 0; i < defaults.HOTPFirstTokensRange; i++ {
		otpFirstValues[i] = otp.OTP()
	}

	tokenData := services.SignupToken{
		Token: token,
		User: services.TeleportUser{
			Name:           user.GetName(),
			AllowedLogins:  user.GetAllowedLogins(),
			OIDCIdentities: user.GetIdentities()},
		Hotp:            otpMarshalled,
		HotpFirstValues: otpFirstValues,
		HotpQR:          otpQR,
	}

	err = s.UpsertSignupToken(token, tokenData, defaults.MaxSignupTokenTTL)
	if err != nil {
		return "", trace.Wrap(err)
	}

	log.Infof("[AUTH API] created the signup token for %v as %v", user)
	return token, nil
}
// CreateSignupToken creates one time token for creating account for the user
// For each token it creates username and hotp generator
//
// allowedLogins are linux user logins allowed for the new user to use
CreateSignupToken creates one time token for creating account for the user
For each token it creates username and hotp generator

allowedLogins are linux user logins allowed for the new user to use
// CreateSignupToken creates one time token for creating account for the user // For each token it creates username and hotp generator // // allowedLogins are linux user logins allowed for the new user to use
func (s *AuthServer) CreateSignupToken(user services.User) (string, error) {
	if err := user.Check(); err != nil {
		return "", trace.Wrap(err)
	}
	for _, id := range user.GetIdentities() {
		if err := id.Check(); err != nil {
			return "", trace.Wrap(err)
		}
		if _, err := s.GetOIDCConnector(id.ConnectorID, false); err != nil {
			return "", trace.Wrap(err)
		}
	}
	_, err := s.GetPasswordHash(user.GetName())
	if err == nil {
		return "", trace.BadParameter("user '%v' already exists", user)
	}
	token, err := utils.CryptoRandomHex(TokenLenBytes)
	if err != nil {
		return "", trace.Wrap(err)
	}
	otp, err := hotp.GenerateHOTP(defaults.HOTPTokenDigits, false)
	if err != nil {
		log.Errorf("[AUTH API] failed to generate HOTP: %v", err)
		return "", trace.Wrap(err)
	}
	otpQR, err := otp.QR("Teleport: " + user.GetName() + "@" + s.AuthServiceName)
	if err != nil {
		return "", trace.Wrap(err)
	}
	otpMarshalled, err := hotp.Marshal(otp)
	if err != nil {
		return "", trace.Wrap(err)
	}
	otpFirstValues := make([]string, defaults.HOTPFirstTokensRange)
	for i := 0; i < defaults.HOTPFirstTokensRange; i++ {
		otpFirstValues[i] = otp.OTP()
	}
	tokenData := services.SignupToken{
		Token: token,
		User: services.TeleportUser{
			Name:           user.GetName(),
			AllowedLogins:  user.GetAllowedLogins(),
			OIDCIdentities: user.GetIdentities()},
		Hotp:            otpMarshalled,
		HotpFirstValues: otpFirstValues,
		HotpQR:          otpQR,
	}
	err = s.UpsertSignupToken(token, tokenData, defaults.MaxSignupTokenTTL)
	if err != nil {
		return "", trace.Wrap(err)
	}
	log.Infof("[AUTH API] created the signup token for %v as %v", user)
	return token, nil
}
func ( s * AuthServer ) CreateSignupToken ( user services . User ) ( string , error ) { if err := user . Check ( ) ; err != nil { return " " , trace . Wrap ( err ) } for _ , id := range user . GetIdentities ( ) { if err := id . Check ( ) ; err != nil { return " " , trace . Wrap ( err ) } if _ , err := s . GetOIDCConnector ( id . ConnectorID , false ) ; err != nil { return " " , trace . Wrap ( err ) } } _ , err := s . GetPasswordHash ( user . GetName ( ) ) if err == nil { return " " , trace . BadParameter ( " " , user ) } token , err := utils . CryptoRandomHex ( TokenLenBytes ) if err != nil { return " " , trace . Wrap ( err ) } otp , err := hotp . GenerateHOTP ( defaults . HOTPTokenDigits , false ) if err != nil { log . Errorf ( " " , err ) return " " , trace . Wrap ( err ) } otpQR , err := otp . QR ( " " + user . GetName ( ) + " " + s . AuthServiceName ) if err != nil { return " " , trace . Wrap ( err ) } otpMarshalled , err := hotp . Marshal ( otp ) if err != nil { return " " , trace . Wrap ( err ) } otpFirstValues := make ( [ ] string , defaults . HOTPFirstTokensRange ) for i := 0 ; i < defaults . HOTPFirstTokensRange ; i ++ { otpFirstValues [ i ] = otp . OTP ( ) } tokenData := services . SignupToken { Token : token , User : services . TeleportUser { Name : user . GetName ( ) , AllowedLogins : user . GetAllowedLogins ( ) , OIDCIdentities : user . GetIdentities ( ) } , Hotp : otpMarshalled , HotpFirstValues : otpFirstValues , HotpQR : otpQR , } err = s . UpsertSignupToken ( token , tokenData , defaults . MaxSignupTokenTTL ) if err != nil { return " " , trace . Wrap ( err ) } log . Infof ( " " , user ) return token , nil }
CreateSignupToken creates one time token for creating account for the user
For each token it creates username and hotp generator
CreateSignupToken creates one time token for creating account for the user For each token it creates username and hotp generator
// make sure that connectors actually exist // check existing