onLogin performs steps after successful authentication.
(msgID string, timestamp time.Time, rec *auth.Rec, missing []string)
| 1051 | |
| 1052 | // onLogin performs steps after successful authentication. |
| 1053 | func (s *Session) onLogin(msgID string, timestamp time.Time, rec *auth.Rec, missing []string) *ServerComMessage { |
| 1054 | var reply *ServerComMessage |
| 1055 | var params map[string]any |
| 1056 | |
| 1057 | features := rec.Features |
| 1058 | |
| 1059 | params = map[string]any{ |
| 1060 | "user": rec.Uid.UserId(), |
| 1061 | "authlvl": rec.AuthLevel.String(), |
| 1062 | } |
| 1063 | if len(missing) > 0 { |
| 1064 | // Some credentials are not validated yet. Respond with request for validation. |
| 1065 | reply = InfoValidateCredentials(msgID, timestamp) |
| 1066 | |
| 1067 | params["cred"] = missing |
| 1068 | } else { |
| 1069 | // Everything is fine, authenticate the session. |
| 1070 | |
| 1071 | reply = NoErr(msgID, "", timestamp) |
| 1072 | |
| 1073 | // Check if the token is suitable for session authentication. |
| 1074 | if features&auth.FeatureNoLogin == 0 { |
| 1075 | // Authenticate the session. |
| 1076 | s.uid = rec.Uid |
| 1077 | s.authLvl = rec.AuthLevel |
| 1078 | // Reset expiration time. |
| 1079 | rec.Lifetime = 0 |
| 1080 | } |
| 1081 | features |= auth.FeatureValidated |
| 1082 | |
| 1083 | // Record deviceId used in this session |
| 1084 | if s.deviceID != "" { |
| 1085 | if err := store.Devices.Update(rec.Uid, "", &types.DeviceDef{ |
| 1086 | DeviceId: s.deviceID, |
| 1087 | Platform: s.platf, |
| 1088 | LastSeen: timestamp, |
| 1089 | Lang: s.lang, |
| 1090 | }); err != nil { |
| 1091 | logs.Warn.Println("failed to update device record", err) |
| 1092 | } |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | // GenSecret fails only if tokenLifetime is < 0. It can't be < 0 here, |
| 1097 | // otherwise login would have failed earlier. |
| 1098 | rec.Features = features |
| 1099 | params["token"], params["expires"], _ = store.Store.GetLogicalAuthHandler("token").GenSecret(rec) |
| 1100 | |
| 1101 | reply.Ctrl.Params = params |
| 1102 | return reply |
| 1103 | } |
| 1104 | |
| 1105 | func (s *Session) get(msg *ClientComMessage) { |
| 1106 | // Expand topic name. |
no test coverage detected