Skip to content

Commit

Permalink
bug in authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Jan 7, 2018
1 parent cac6990 commit 08b51e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion server/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewErr(code int, err error) AuthErr {

// IsError checks if the venue represents an actual error.
func (a AuthErr) IsError() bool {
return a.Code <= InfoNotModified
return a.Code > InfoNotModified
}

// AuthHandler is the interface which auth providers must implement.
Expand Down
27 changes: 16 additions & 11 deletions server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func (s *Session) publish(msg *ClientComMessage) {
}
}

// Authenticate
// Client metadata
func (s *Session) hello(msg *ClientComMessage) {

if msg.Hi.Version == "" {
Expand Down Expand Up @@ -455,6 +455,8 @@ func (s *Session) login(msg *ClientComMessage) {
}

uid, authLvl, expires, authErr := handler.Authenticate(msg.Login.Secret)
log.Println("Login result:", authErr.Code, authErr.Err)

if authErr.IsError() {
log.Println(authErr.Err)
}
Expand All @@ -472,6 +474,7 @@ func (s *Session) login(msg *ClientComMessage) {

// All other errors are reported as invalid login or password
if uid.IsZero() {
log.Println("Zero UID")
s.queueOut(ErrAuthFailed(msg.Login.Id, "", msg.timestamp))
return
}
Expand All @@ -489,7 +492,7 @@ func (s *Session) login(msg *ClientComMessage) {
}
secret, expires, authErr := handler.GenSecret(uid, authLvl, tokenLifetime)
if authErr.IsError() {
log.Println(authErr.Err)
log.Println("auth basic: failed to generate token", authErr.Code, authErr.Err)
s.queueOut(ErrAuthFailed(msg.Login.Id, "", msg.timestamp))
return
}
Expand Down Expand Up @@ -519,6 +522,8 @@ func (s *Session) acc(msg *ClientComMessage) {

authhdl := store.GetAuthHandler(msg.Acc.Scheme)
if strings.HasPrefix(msg.Acc.User, "new") {
log.Println("Creating new account")

if authhdl == nil {
// New accounts must have an authentication scheme
s.queueOut(ErrMalformed(msg.Acc.Id, "", msg.timestamp))
Expand Down Expand Up @@ -607,17 +612,16 @@ func (s *Session) acc(msg *ClientComMessage) {
reply := NoErrCreated(msg.Acc.Id, "", msg.timestamp)
params := map[string]interface{}{
"user": user.Uid().UserId(),
"desc": &MsgTopicDesc{
CreatedAt: &user.CreatedAt,
UpdatedAt: &user.UpdatedAt,
DefaultAcs: &MsgDefaultAcsMode{
Auth: user.Access.Auth.String(),
Anon: user.Access.Anon.String()},
Public: user.Public,
Private: private},
}

params["desc"] = &MsgTopicDesc{
CreatedAt: &user.CreatedAt,
UpdatedAt: &user.UpdatedAt,
DefaultAcs: &MsgDefaultAcsMode{
Auth: user.Access.Auth.String(),
Anon: user.Access.Anon.String()},
Public: user.Public,
Private: private}

if msg.Acc.Login {
// User wants to use the new account for authentication. Generate token and resord session.

Expand All @@ -639,6 +643,7 @@ func (s *Session) acc(msg *ClientComMessage) {
}

reply.Ctrl.Params = params
log.Println("Account params", params)
s.queueOut(reply)

pluginAccount(&user, plgActCreate)
Expand Down

0 comments on commit 08b51e0

Please sign in to comment.