Esempio n. 1
0
func (auth *Authenticator) CreateSession(username string, ttl time.Duration) (*LoginSession, error) {
	session := &LoginSession{
		ID:         base.GenerateRandomSecret(),
		Username:   username,
		Expiration: time.Now().Add(ttl),
	}
	if err := auth.bucket.Set(docIDForSession(session.ID), int(ttl.Seconds()), session); err != nil {
		return nil, err
	}
	return session, nil
}
Esempio n. 2
0
// Registers a new user account based on a BrowserID verified assertion.
// Username will be the same as the verified email address. Password will be random.
// The user will have access to no channels.
func (h *handler) registerBrowserIDUser(verifiedInfo *BrowserIDResponse) (*auth.User, error) {
	user, err := auth.NewUser(verifiedInfo.Email, base.GenerateRandomSecret(), []string{})
	if err != nil {
		return nil, err
	}
	user.Email = verifiedInfo.Email
	err = h.context.auth.SaveUser(user)
	if err != nil {
		return nil, err
	}
	return user, err
}
Esempio n. 3
0
// Registers a new user account based on the given verified email address.
// Username will be the same as the verified email address. Password will be random.
// The user will have access to no channels.
func (h *handler) registerNewUser(email string) (auth.User, error) {
	user, err := h.db.Authenticator().NewUser(email, base.GenerateRandomSecret(), base.Set{})
	if err != nil {
		return nil, err
	}
	user.SetEmail(email)
	err = h.db.Authenticator().Save(user)
	if err != nil {
		return nil, err
	}
	return user, err
}
Esempio n. 4
0
// Registers a new user account based on a Persona verified assertion.
// Username will be the same as the verified email address. Password will be random.
// The user will have access to no channels.
func (h *handler) registerPersonaUser(verifiedInfo *PersonaResponse) (auth.User, error) {
	user, err := h.context.auth.NewUser(verifiedInfo.Email, base.GenerateRandomSecret(), channels.Set{})
	if err != nil {
		return nil, err
	}
	user.SetEmail(verifiedInfo.Email)
	err = h.context.auth.Save(user)
	if err != nil {
		return nil, err
	}
	return user, err
}
Esempio n. 5
0
// Registers a new user account based on a Persona verified assertion.
// Username will be the same as the verified email address. Password will be random.
// The user will have access to no channels.
func (h *handler) registerPersonaUser(verifiedInfo *PersonaResponse) (auth.User, error) {
	user, err := h.db.Authenticator().NewUser(verifiedInfo.Email, base.GenerateRandomSecret(), base.Set{})
	if err != nil {
		return nil, err
	}
	user.SetEmail(verifiedInfo.Email)
	err = h.db.Authenticator().Save(user)
	if err != nil {
		return nil, err
	}
	return user, err
}
Esempio n. 6
0
func (auth *Authenticator) CreateSession(username string, ttl time.Duration) (*LoginSession, error) {
	ttlSec := int(ttl.Seconds())
	if ttlSec <= 0 {
		return nil, base.HTTPErrorf(400, "Invalid session time-to-live")
	}
	session := &LoginSession{
		ID:         base.GenerateRandomSecret(),
		Username:   username,
		Expiration: time.Now().Add(ttl),
	}
	if err := auth.bucket.Set(docIDForSession(session.ID), ttlSec, session); err != nil {
		return nil, err
	}
	return session, nil
}