auth

Paddy 2015-04-11 Parent:202e991accc2 Child:cf6c1f05eb21

158:3223a8e679db Browse Files

Remove concept of usernames. We really have no reason to use usernames, and they're complicating things more than they need to. We're going to keep logins the same, because we want to be able to support OAuth2/OpenID/whatever logins in the future, and keeping a type associated with those logins is probably for the best.

doc.go profile.go

     1.1 --- a/doc.go	Sat Apr 11 14:13:52 2015 -0400
     1.2 +++ b/doc.go	Sat Apr 11 14:39:51 2015 -0400
     1.3 @@ -3,9 +3,8 @@
     1.4  
     1.5  The service is an opinionated implementation of authentication using passphrases and the
     1.6  code.secondbit.org/pass package to implement user credentials and accounts. Additionally, users
     1.7 -are permitted to login using their email address on record or their username interchangeably.
     1.8 -Care is also taken to be able to mitigate attacks that have already happened and plan ahead for
     1.9 -the worst case scenarios.
    1.10 +are permitted to login using any email address they have on record. Care is also taken to be able
    1.11 +to mitigate attacks that have already happened and plan ahead for the worst case scenarios.
    1.12  
    1.13  An OAuth2 provider is also built-in and provided, complete with client registration and management,
    1.14  as well as a specification-based set of handlers for managing the issuing of grants and tokens. Token
     2.1 --- a/profile.go	Sat Apr 11 14:13:52 2015 -0400
     2.2 +++ b/profile.go	Sat Apr 11 14:39:51 2015 -0400
     2.3 @@ -10,7 +10,6 @@
     2.4  	"time"
     2.5  
     2.6  	"code.secondbit.org/uuid.hg"
     2.7 -	"github.com/extemporalgenome/slug"
     2.8  	"github.com/gorilla/mux"
     2.9  )
    2.10  
    2.11 @@ -23,8 +22,6 @@
    2.12  	CurPassphraseScheme = 1
    2.13  	// MaxNameLength is the maximum length, in bytes, of a name, exclusive.
    2.14  	MaxNameLength = 64
    2.15 -	// MaxUsernameLength is the maximum length, in bytes, of a username, exclusive.
    2.16 -	MaxUsernameLength = 16
    2.17  	// MaxEmailLength is the maximum length, in bytes, of an email address, exclusive.
    2.18  	MaxEmailLength = 64
    2.19  )
    2.20 @@ -68,8 +65,7 @@
    2.21  )
    2.22  
    2.23  // Profile represents a single user of the service,
    2.24 -// including their authentication information, but not
    2.25 -// including their username or email.
    2.26 +// including their authentication information.
    2.27  type Profile struct {
    2.28  	ID                     uuid.ID   `json:"id,omitempty"`
    2.29  	Name                   string    `json:"name,omitempty"`
    2.30 @@ -211,7 +207,6 @@
    2.31  }
    2.32  
    2.33  type newProfileRequest struct {
    2.34 -	Username   string `json:"username"`
    2.35  	Email      string `json:"email"`
    2.36  	Passphrase string `json:"passphrase"`
    2.37  	Name       string `json:"name"`
    2.38 @@ -221,7 +216,6 @@
    2.39  	errors := []requestError{}
    2.40  	req.Name = strings.TrimSpace(req.Name)
    2.41  	req.Email = strings.TrimSpace(req.Email)
    2.42 -	req.Username = slug.SlugAscii(strings.TrimSpace(req.Username))
    2.43  	if len(req.Passphrase) < MinPassphraseLength {
    2.44  		errors = append(errors, requestError{
    2.45  			Slug:  requestErrInsufficient,
    2.46 @@ -240,12 +234,6 @@
    2.47  			Field: "/name",
    2.48  		})
    2.49  	}
    2.50 -	if len(req.Username) > MaxUsernameLength {
    2.51 -		errors = append(errors, requestError{
    2.52 -			Slug:  requestErrOverflow,
    2.53 -			Field: "/username",
    2.54 -		})
    2.55 -	}
    2.56  	if req.Email == "" {
    2.57  		errors = append(errors, requestError{
    2.58  			Slug:  requestErrMissing,
    2.59 @@ -501,21 +489,6 @@
    2.60  		return
    2.61  	}
    2.62  	logins = append(logins, login)
    2.63 -	if req.Username != "" {
    2.64 -		login.Type = "username"
    2.65 -		login.Value = req.Username
    2.66 -		err = context.AddLogin(login)
    2.67 -		if err != nil {
    2.68 -			if err == ErrLoginAlreadyExists {
    2.69 -				encode(w, r, http.StatusBadRequest, response{Errors: []requestError{{Slug: requestErrConflict, Field: "/username"}}})
    2.70 -				return
    2.71 -			}
    2.72 -			log.Printf("Error adding login: %#+v\n", err)
    2.73 -			encode(w, r, http.StatusInternalServerError, actOfGodResponse)
    2.74 -			return
    2.75 -		}
    2.76 -		logins = append(logins, login)
    2.77 -	}
    2.78  	resp := response{
    2.79  		Logins:   logins,
    2.80  		Profiles: []Profile{profile},